diff --git a/core/modules/shortcut/src/Tests/ShortcutTestBase.php b/core/modules/shortcut/src/Tests/ShortcutTestBase.php index 1e3196ceb4d1fe113606082e5fb37e8b715d5d92..584a6154c309210df43ace42bbe65524fa52aa5a 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTestBase.php +++ b/core/modules/shortcut/src/Tests/ShortcutTestBase.php @@ -2,6 +2,8 @@ namespace Drupal\shortcut\Tests; +@trigger_error(__NAMESPACE__ . '\ShortcutTestBase is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\shortcut\Functional\ShortcutTestBase, see https://www.drupal.org/node/2906736.', E_USER_DEPRECATED); + use Drupal\shortcut\Entity\Shortcut; use Drupal\shortcut\Entity\ShortcutSet; use Drupal\shortcut\ShortcutSetInterface; @@ -9,6 +11,11 @@ /** * Defines base class for shortcut test cases. + * + * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. + * Use \Drupal\Tests\shortcut\Functional\ShortcutTestBase. + * + * @see https://www.drupal.org/node/2906736 */ abstract class ShortcutTestBase extends WebTestBase { diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php similarity index 97% rename from core/modules/shortcut/src/Tests/ShortcutLinksTest.php rename to core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php index cf4ae0fbe5b3ca006ae13cd4670d876151508dbd..e39f652e55e0d4ea3b28df9628067395c1bb0bbb 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php @@ -1,6 +1,6 @@ drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts', 'access content overview', 'administer content types'])); $this->drupalGet(Url::fromRoute('')); $shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a'); - $this->assertEqual((string) $shortcuts[0], 'Add content'); - $this->assertEqual((string) $shortcuts[1], 'All content'); + $this->assertEqual($shortcuts[0]->getText(), 'Add content'); + $this->assertEqual($shortcuts[1]->getText(), 'All content'); foreach ($this->set->getShortcuts() as $shortcut) { $shortcut->setWeight($shortcut->getWeight() * -1)->save(); } $this->drupalGet(Url::fromRoute('')); $shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a'); - $this->assertEqual((string) $shortcuts[0], 'All content'); - $this->assertEqual((string) $shortcuts[1], 'Add content'); + $this->assertEqual($shortcuts[0]->getText(), 'All content'); + $this->assertEqual($shortcuts[1]->getText(), 'Add content'); } /** diff --git a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php similarity index 98% rename from core/modules/shortcut/src/Tests/ShortcutSetsTest.php rename to core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php index e34518e0ae0100e693ff2b79b5de0f0c1c5a6440..b897df752db892d8d3d269b5ecea24594388b23a 100644 --- a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php @@ -1,6 +1,6 @@ $element) { - $this->assertEqual((string) $element[0], $expected_items[$key]); + $this->assertEqual($element->getText(), $expected_items[$key]); } // Look for test shortcuts in the table. diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php b/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php new file mode 100644 index 0000000000000000000000000000000000000000..3f9cc87be3840659957157088f43828cd53ee364 --- /dev/null +++ b/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php @@ -0,0 +1,133 @@ +profile != 'standard') { + // Create Basic page and Article node types. + $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); + $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); + + // Populate the default shortcut set. + $shortcut = Shortcut::create([ + 'shortcut_set' => 'default', + 'title' => t('Add content'), + 'weight' => -20, + 'link' => [ + 'uri' => 'internal:/node/add', + ], + ]); + $shortcut->save(); + + $shortcut = Shortcut::create([ + 'shortcut_set' => 'default', + 'title' => t('All content'), + 'weight' => -19, + 'link' => [ + 'uri' => 'internal:/admin/content', + ], + ]); + $shortcut->save(); + } + + // Create users. + $this->adminUser = $this->drupalCreateUser(['access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users', 'link to any page', 'edit any article content']); + $this->shortcutUser = $this->drupalCreateUser(['customize shortcut links', 'switch shortcut sets', 'access shortcuts', 'access content']); + + // Create a node. + $this->node = $this->drupalCreateNode(['type' => 'article']); + + // Log in as admin and grab the default shortcut set. + $this->drupalLogin($this->adminUser); + $this->set = ShortcutSet::load('default'); + \Drupal::entityManager()->getStorage('shortcut_set')->assignUser($this->set, $this->adminUser); + } + + /** + * Creates a generic shortcut set. + */ + public function generateShortcutSet($label = '', $id = NULL) { + $set = ShortcutSet::create([ + 'id' => isset($id) ? $id : strtolower($this->randomMachineName()), + 'label' => empty($label) ? $this->randomString() : $label, + ]); + $set->save(); + return $set; + } + + /** + * Extracts information from shortcut set links. + * + * @param \Drupal\shortcut\ShortcutSetInterface $set + * The shortcut set object to extract information from. + * @param string $key + * The array key indicating what information to extract from each link: + * - 'title': Extract shortcut titles. + * - 'link': Extract shortcut paths. + * - 'id': Extract the shortcut ID. + * + * @return array + * Array of the requested information from each link. + */ + public function getShortcutInformation(ShortcutSetInterface $set, $key) { + $info = []; + \Drupal::entityManager()->getStorage('shortcut')->resetCache(); + foreach ($set->getShortcuts() as $shortcut) { + if ($key == 'link') { + $info[] = $shortcut->link->uri; + } + else { + $info[] = $shortcut->{$key}->value; + } + } + return $info; + } + +} diff --git a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php similarity index 98% rename from core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php rename to core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php index 300ca3b7220872b525748df31b3598affd25f929..83bf47a49535cf296279028d65abd0267d72e847 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php @@ -1,6 +1,6 @@