From e0b00598c14ff9fdc465ae90edae2d2ef250c045 Mon Sep 17 00:00:00 2001
From: GoZ <goz@226961.no-reply.drupal.org>
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 @@
 <?php
 
-namespace Drupal\shortcut\Tests;
+namespace Drupal\Tests\shortcut\Functional;
 
 use Drupal\block_content\Entity\BlockContentType;
 use Drupal\Component\Utility\SafeMarkup;
@@ -368,15 +368,15 @@ public function testShortcutLinkOrder() {
     $this->drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts', 'access content overview', 'administer content types']));
     $this->drupalGet(Url::fromRoute('<front>'));
     $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('<front>'));
     $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 @@
 <?php
 
-namespace Drupal\shortcut\Tests;
+namespace Drupal\Tests\shortcut\Functional;
 
 use Drupal\shortcut\Entity\ShortcutSet;
 
@@ -68,7 +68,7 @@ public function testShortcutSetEdit() {
     // Test the contents of each th cell.
     $expected_items = [t('Name'), t('Weight'), t('Operations')];
     foreach ($elements as $key => $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 @@
 <?php
 
-namespace Drupal\shortcut\Tests;
+namespace Drupal\Tests\shortcut\Functional;
 
 use Drupal\shortcut\Entity\Shortcut;
 use Drupal\shortcut\Entity\ShortcutSet;
 use Drupal\shortcut\ShortcutSetInterface;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
 
 /**
  * Defines base class for shortcut test cases.
  */
-abstract class ShortcutTestBase extends WebTestBase {
+abstract class ShortcutTestBase extends BrowserTestBase {
 
   /**
    * Modules to enable.
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 300ca3b..83bf47a 100644
--- a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Drupal\shortcut\Tests;
+namespace Drupal\Tests\shortcut\Functional;
 
 use Drupal\content_translation\Tests\ContentTranslationUITestBase;
 use Drupal\Core\Entity\EntityChangedInterface;
diff --git a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
index 79653da..8abfab4 100644
--- a/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
+++ b/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
@@ -3,6 +3,7 @@
 namespace Drupal\FunctionalTests;
 
 use Behat\Mink\Selector\Xpath\Escaper;
+use Drupal\block\Entity\Block;
 use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Component\Utility\Xss;
 use Drupal\KernelTests\AssertLegacyTrait as BaseAssertLegacyTrait;
@@ -744,4 +745,52 @@ protected function getRawContent() {
     return $this->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

