From 27ab96bdb88cf6bf56bacb5a086b9009258e0bd7 Mon Sep 17 00:00:00 2001 From: GoZ Date: Mon, 13 Mar 2017 11:22:17 +0100 Subject: [PATCH] Issue #2767275 by Jo Fitzgerald, GoZ, claudiu.cristea, boaloysius, klausi: Convert web tests to browser tests for tour module --- core/modules/tour/src/Tests/TourTestBase.php | 4 ++ .../tests/src/Functional/TourCacheTagsTest.php | 2 +- .../src/Functional}/TourHelpPageTest.php | 8 +-- .../Tests => tests/src/Functional}/TourTest.php | 2 +- .../tour/tests/src/Functional/TourTestBase.php | 73 ++++++++++++++++++++++ .../src/Functional}/TourTestBasic.php | 2 +- 6 files changed, 84 insertions(+), 7 deletions(-) rename core/modules/tour/{src/Tests => tests/src/Functional}/TourHelpPageTest.php (96%) rename core/modules/tour/{src/Tests => tests/src/Functional}/TourTest.php (99%) create mode 100644 core/modules/tour/tests/src/Functional/TourTestBase.php rename core/modules/tour/{src/Tests => tests/src/Functional}/TourTestBasic.php (97%) diff --git a/core/modules/tour/src/Tests/TourTestBase.php b/core/modules/tour/src/Tests/TourTestBase.php index 198051d..798c4ea 100644 --- a/core/modules/tour/src/Tests/TourTestBase.php +++ b/core/modules/tour/src/Tests/TourTestBase.php @@ -6,6 +6,10 @@ /** * Base class for testing Tour functionality. + * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\Tests\tour\Functional\TourTestBase instead. + * + * @see https://www.drupal.org/node/2767275 */ abstract class TourTestBase extends WebTestBase { diff --git a/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php b/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php index ff2e9e5..daed6fa 100644 --- a/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php +++ b/core/modules/tour/tests/src/Functional/TourCacheTagsTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\tour\Functional; use Drupal\Core\Url; -use Drupal\system\Tests\Cache\PageCacheTagsTestBase; +use Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase; use Drupal\tour\Entity\Tour; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; diff --git a/core/modules/tour/src/Tests/TourHelpPageTest.php b/core/modules/tour/tests/src/Functional/TourHelpPageTest.php similarity index 96% rename from core/modules/tour/src/Tests/TourHelpPageTest.php rename to core/modules/tour/tests/src/Functional/TourHelpPageTest.php index 8a41eb9..e176005 100644 --- a/core/modules/tour/src/Tests/TourHelpPageTest.php +++ b/core/modules/tour/tests/src/Functional/TourHelpPageTest.php @@ -1,15 +1,15 @@ assertTourTips(); + * + * // Advanced example. The following would be used for multipage or + * // targeting a specific subset of tips. + * $tips = array(); + * $tips[] = array('data-id' => 'foo'); + * $tips[] = array('data-id' => 'bar'); + * $tips[] = array('data-class' => 'baz'); + * $this->assertTourTips($tips); + * @endcode + */ + public function assertTourTips($tips = []) { + // Get the rendered tips and their data-id and data-class attributes. + if (empty($tips)) { + // Tips are rendered as
  • elements inside
      . + $rendered_tips = $this->xpath('//ol[@id = "tour"]//li[starts-with(@class, "tip")]'); + foreach ($rendered_tips as $rendered_tip) { + $tips[] = [ + 'data-id' => $rendered_tip->getAttribute('data-id'), + 'data-class' => $rendered_tip->getAttribute('data-class'), + ]; + } + } + + // If the tips are still empty we need to fail. + if (empty($tips)) { + $this->fail('Could not find tour tips on the current page.'); + } + else { + // Check for corresponding page elements. + $total = 0; + $modals = 0; + $raw_content = $this->getSession()->getPage()->getContent(); + foreach ($tips as $tip) { + if (!empty($tip['data-id'])) { + $elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $raw_content, TRUE); + $this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); + } + elseif (!empty($tip['data-class'])) { + $elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $raw_content, TRUE); + $this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']])); + } + else { + // It's a modal. + $modals++; + } + $total++; + } + $this->pass(format_string('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals])); + } + } + +} diff --git a/core/modules/tour/src/Tests/TourTestBasic.php b/core/modules/tour/tests/src/Functional/TourTestBasic.php similarity index 97% rename from core/modules/tour/src/Tests/TourTestBasic.php rename to core/modules/tour/tests/src/Functional/TourTestBasic.php index 1db8bc5..ca188d7 100644 --- a/core/modules/tour/src/Tests/TourTestBasic.php +++ b/core/modules/tour/tests/src/Functional/TourTestBasic.php @@ -1,6 +1,6 @@