summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-08-14 15:48:00 +0900
committerNathaniel Catchpole2017-08-14 15:48:05 +0900
commit621aa0b5b84b959b5442fe51c726cf620204dd6e (patch)
tree1bedba7566c4c23b946ebeaa1b6c62e8d78ea30d
parent3c82d9029bfffc1ec8ae7802ad11c4c0bebe6129 (diff)
Issue #2767275 by GoZ, Jo Fitzgerald, claudiu.cristea, boaloysius, andypost, klausi, dawehner: Convert web tests to browser tests for tour module
(cherry picked from commit 455672e7640cb02478f05acf6f331f9d9de4c450)
-rw-r--r--core/modules/language/tests/src/Functional/LanguageTourTest.php (renamed from core/modules/language/src/Tests/LanguageTourTest.php)4
-rw-r--r--core/modules/locale/tests/src/Functional/LocaleTranslateStringTourTest.php2
-rw-r--r--core/modules/tour/src/Tests/TourTestBase.php5
-rw-r--r--core/modules/tour/tests/src/Functional/TourCacheTagsTest.php2
-rw-r--r--core/modules/tour/tests/src/Functional/TourHelpPageTest.php (renamed from core/modules/tour/src/Tests/TourHelpPageTest.php)8
-rw-r--r--core/modules/tour/tests/src/Functional/TourTest.php (renamed from core/modules/tour/src/Tests/TourTest.php)2
-rw-r--r--core/modules/tour/tests/src/Functional/TourTestBase.php73
-rw-r--r--core/modules/tour/tests/src/Functional/TourTestBasic.php (renamed from core/modules/tour/src/Tests/TourTestBasic.php)2
-rw-r--r--core/modules/views_ui/tests/src/Functional/ViewsUITourTest.php (renamed from core/modules/views_ui/src/Tests/ViewsUITourTest.php)4
9 files changed, 90 insertions, 12 deletions
diff --git a/core/modules/language/src/Tests/LanguageTourTest.php b/core/modules/language/tests/src/Functional/LanguageTourTest.php
index b11006e..13b29f2 100644
--- a/core/modules/language/src/Tests/LanguageTourTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageTourTest.php
@@ -1,8 +1,8 @@
<?php
-namespace Drupal\language\Tests;
+namespace Drupal\Tests\language\Functional;
-use Drupal\tour\Tests\TourTestBase;
+use Drupal\Tests\tour\Functional\TourTestBase;
/**
* Tests tour functionality.
diff --git a/core/modules/locale/tests/src/Functional/LocaleTranslateStringTourTest.php b/core/modules/locale/tests/src/Functional/LocaleTranslateStringTourTest.php
index 397c1c7..ffd5bc7 100644
--- a/core/modules/locale/tests/src/Functional/LocaleTranslateStringTourTest.php
+++ b/core/modules/locale/tests/src/Functional/LocaleTranslateStringTourTest.php
@@ -2,7 +2,7 @@
namespace Drupal\Tests\locale\Functional;
-use Drupal\tour\Tests\TourTestBase;
+use Drupal\Tests\tour\Functional\TourTestBase;
/**
* Tests the Translate Interface tour.
diff --git a/core/modules/tour/src/Tests/TourTestBase.php b/core/modules/tour/src/Tests/TourTestBase.php
index 198051d..e139650 100644
--- a/core/modules/tour/src/Tests/TourTestBase.php
+++ b/core/modules/tour/src/Tests/TourTestBase.php
@@ -4,8 +4,13 @@ namespace Drupal\tour\Tests;
use Drupal\simpletest\WebTestBase;
+@trigger_error('\Drupal\tour\Tests\TourTestBase is deprecated in 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\tour\Functional\TourTestBase.', E_USER_DEPRECATED);
+
/**
* 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.
*/
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
index 8a41eb9..ad60df1 100644
--- a/core/modules/tour/src/Tests/TourHelpPageTest.php
+++ b/core/modules/tour/tests/src/Functional/TourHelpPageTest.php
@@ -1,15 +1,15 @@
<?php
-namespace Drupal\tour\Tests;
+namespace Drupal\Tests\tour\Functional;
-use Drupal\simpletest\WebTestBase;
+use Drupal\Tests\BrowserTestBase;
/**
* Verifies help page display of tours.
*
* @group help
*/
-class TourHelpPageTest extends WebTestBase {
+class TourHelpPageTest extends BrowserTestBase {
/**
* Modules to enable, including some providing tours.
@@ -101,7 +101,7 @@ class TourHelpPageTest extends WebTestBase {
foreach ($titles[1] as $title) {
if ($tours_ok) {
$this->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
index 749e7c5..55f3743 100644
--- a/core/modules/tour/src/Tests/TourTest.php
+++ b/core/modules/tour/tests/src/Functional/TourTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Drupal\tour\Tests;
+namespace Drupal\Tests\tour\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\tour\Entity\Tour;
diff --git a/core/modules/tour/tests/src/Functional/TourTestBase.php b/core/modules/tour/tests/src/Functional/TourTestBase.php
new file mode 100644
index 0000000..522e8e6
--- /dev/null
+++ b/core/modules/tour/tests/src/Functional/TourTestBase.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Drupal\Tests\tour\Functional;
+
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Base class for testing Tour functionality.
+ */
+abstract class TourTestBase extends BrowserTestBase {
+
+ /**
+ * Assert function to determine if tips rendered to the page
+ * have a corresponding page element.
+ *
+ * @param array $tips
+ * A list of tips which provide either a "data-id" or "data-class".
+ *
+ * @code
+ * // Basic example.
+ * $this->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 <li> elements inside <ol id="tour">.
+ $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
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 @@
<?php
-namespace Drupal\tour\Tests;
+namespace Drupal\Tests\tour\Functional;
/**
* Simple tour tips test base.
diff --git a/core/modules/views_ui/src/Tests/ViewsUITourTest.php b/core/modules/views_ui/tests/src/Functional/ViewsUITourTest.php
index 31748e8..839fe3a 100644
--- a/core/modules/views_ui/src/Tests/ViewsUITourTest.php
+++ b/core/modules/views_ui/tests/src/Functional/ViewsUITourTest.php
@@ -1,8 +1,8 @@
<?php
-namespace Drupal\views_ui\Tests;
+namespace Drupal\Tests\views_ui\Functional;
-use Drupal\tour\Tests\TourTestBase;
+use Drupal\Tests\tour\Functional\TourTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
/**