diff --git a/core/modules/language/src/Tests/LanguageTourTest.php b/core/modules/language/tests/src/Functional/LanguageTourTest.php similarity index 93% rename from core/modules/language/src/Tests/LanguageTourTest.php rename to core/modules/language/tests/src/Functional/LanguageTourTest.php index b11006ec3e9f39a43ab88879ae22b295e0350df5..13b29f2ef56fcd03ae2b985e56c9536840d3c4c9 100644 --- a/core/modules/language/src/Tests/LanguageTourTest.php +++ b/core/modules/language/tests/src/Functional/LanguageTourTest.php @@ -1,8 +1,8 @@ assertText($title); - $this->assertNoLink($title); + $this->assertSession()->linkNotExistsExact($title); } else { $this->assertNoText($title); diff --git a/core/modules/tour/src/Tests/TourTest.php b/core/modules/tour/tests/src/Functional/TourTest.php similarity index 99% rename from core/modules/tour/src/Tests/TourTest.php rename to core/modules/tour/tests/src/Functional/TourTest.php index 749e7c5a3eeb702523bb96ea45277ef6be6929fd..55f3743f61365a2393b26625cac8883eedb13a83 100644 --- a/core/modules/tour/src/Tests/TourTest.php +++ b/core/modules/tour/tests/src/Functional/TourTest.php @@ -1,6 +1,6 @@ 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 1db8bc5c6aa20bb61bcbb610289f0d695252f3c4..ca188d7075cd8e30472730b379be40adaef03ae1 100644 --- a/core/modules/tour/src/Tests/TourTestBasic.php +++ b/core/modules/tour/tests/src/Functional/TourTestBasic.php @@ -1,6 +1,6 @@