From e0b00598c14ff9fdc465ae90edae2d2ef250c045 Mon Sep 17 00:00:00 2001 From: GoZ Date: Sun, 26 Mar 2017 10:28:40 +0200 Subject: [PATCH] Issue #2864088: Convert web tests to browser tests for shortcut module --- .../src/Functional}/ShortcutLinksTest.php | 10 ++--- .../src/Functional}/ShortcutSetsTest.php | 4 +- .../src/Functional}/ShortcutTestBase.php | 6 +-- .../src/Functional}/ShortcutTranslationUITest.php | 2 +- .../Drupal/FunctionalTests/AssertLegacyTrait.php | 49 ++++++++++++++++++++++ 5 files changed, 60 insertions(+), 11 deletions(-) rename core/modules/shortcut/{src/Tests => tests/src/Functional}/ShortcutLinksTest.php (98%) rename core/modules/shortcut/{src/Tests => tests/src/Functional}/ShortcutSetsTest.php (98%) rename core/modules/shortcut/{src/Tests => tests/src/Functional}/ShortcutTestBase.php (96%) rename core/modules/shortcut/{src/Tests => tests/src/Functional}/ShortcutTranslationUITest.php (98%) diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php similarity index 98% rename from core/modules/shortcut/src/Tests/ShortcutLinksTest.php rename to core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php index cf4ae0f..d31eaf9 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 e34518e..b897df7 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/src/Tests/ShortcutTestBase.php b/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php similarity index 96% rename from core/modules/shortcut/src/Tests/ShortcutTestBase.php rename to core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php index 1e3196c..3f9cc87 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTestBase.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php @@ -1,16 +1,16 @@ getSession()->getPage()->getContent(); } + /** + * Checks to see whether a block appears on the page. + * + * @param \Drupal\block\Entity\Block $block + * The block entity to find on the page. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->xpath() instead and assert that the result is not empty. + */ + protected function assertBlockAppears(Block $block) { + @trigger_error('AssertLegacyTrait::assertBlockAppears() is scheduled for removal in Drupal 9.0.0. Use $this->xpath() instead and assert that the result is not empty.', E_USER_DEPRECATED); + $result = $this->findBlockInstance($block); + $this->assertTrue(!empty($result), format_string('Ensure the block @id appears on the page', ['@id' => $block->id()])); + } + + /** + * Checks to see whether a block does not appears on the page. + * + * @param \Drupal\block\Entity\Block $block + * The block entity to find on the page. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->xpath() instead and assert that the result is empty. + */ + protected function assertNoBlockAppears(Block $block) { + @trigger_error('AssertLegacyTrait::assertNoBlockAppears() is scheduled for removal in Drupal 9.0.0. Use $this->xpath() instead and assert that the result is empty.', E_USER_DEPRECATED); + $result = $this->findBlockInstance($block); + $this->assertFalse(!empty($result), format_string('Ensure the block @id does not appear on the page', ['@id' => $block->id()])); + } + + /** + * Find a block instance on the page. + * + * @param \Drupal\block\Entity\Block $block + * The block entity to find on the page. + * + * @return array + * The result from the xpath query. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]) + * instead. + */ + protected function findBlockInstance(Block $block) { + @trigger_error('AssertLegacyTrait::findBlockInstance() is scheduled for removal in Drupal 9.0.0. Use $this->xpath(\'//div[@id = :id]\', [\':id\' => \'block-\' . $block->id()]) instead.', E_USER_DEPRECATED); + return $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]); + } + } -- 2.8.1