diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index dcadd3f..7aaa71e 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -8,12 +8,12 @@ namespace Drupal\tour\Tests; use Drupal\Core\Language\Language; -use Drupal\simpletest\WebTestBase; +use Drupal\tour\Tests\TourTestBase; /** * Tests tour functionality. */ -class TourTest extends WebTestBase { +class TourTest extends TourTestBase { /** * Modules to enable. @@ -48,6 +48,7 @@ public function testTourFunctionality() { ':text' => 'The first tip', )); $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); + $this->assertTourTips(); $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./p//a[@href=:href and contains(., :text)]]', array( ':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1 even last', diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTestBase.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTestBase.php new file mode 100644 index 0000000..0a360d5 --- /dev/null +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTestBase.php @@ -0,0 +1,63 @@ +assertTourTips(); + * + * Advanced xample: + * $tips = array(); + * $tips[] = array('data-id' => 'foo'); + * $tips[] = array('data-id' => 'bar'); + * $tips[] = array('data-class' => 'baz'); + * $this->assertTourTips($tips); + */ + public function assertTourTips($tips = array()) { + // Using xpath, get the rendered tips and there data-id and data-class attributes. + if (empty($tips)) { + $rendered_tips = $this->xpath('//ol[@id = "tour"]//li'); + foreach ($rendered_tips as $rendered_tip) { + $attributes = (array) $rendered_tip->attributes(); + $tips[] = $attributes['@attributes']; + } + } + + // If the tips are still empty we need to fail. + if (empty($tips)) { + $this->assertTrue(FALSE, 'Could not find tour tips on the current page.'); + } + else { + // Check for corresponding page elements. + foreach ($tips as $tip) { + if (!empty($tip['data-id'])) { + $elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $this->content, TRUE); + $this->assertTrue(count($elements), format_string('Found corresponding page element for tour tip with id #%data-id', array('%data-id' => $tip['data-id']))); + } + else if (!empty($tip['data-class'])) { + $elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $this->content, TRUE); + $this->assertTrue(count($elements), format_string('Found corresponding page element for tour tip with class .%data-class', array('%data-class' => $tip['data-class']))); + } + } + } + } + +} diff --git a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Controller/TourTestController.php b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Controller/TourTestController.php index 73b7cde..62aa705 100644 --- a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Controller/TourTestController.php +++ b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Controller/TourTestController.php @@ -33,6 +33,13 @@ public function tourTest1() { ), '#children' => t('Where does the rain in Spain fail?'), ), + 'tip-3' => array( + '#type' => 'container', + '#attributes' => array( + 'id' => 'tour-test-3', + ), + '#children' => t('Tip created now?'), + ), 'tip-4' => array( '#type' => 'container', '#attributes' => array( @@ -40,6 +47,13 @@ public function tourTest1() { ), '#children' => t('Tip created later?'), ), + 'code-tip-1' => array( + '#type' => 'container', + '#attributes' => array( + 'id' => 'tour-code-test-1', + ), + '#children' => t('Tip created now?'), + ), ); } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewsUITourTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewsUITourTest.php index 739e98d..c15e2ca 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewsUITourTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewsUITourTest.php @@ -7,27 +7,26 @@ namespace Drupal\views_ui\Tests; -use Drupal\Core\Language\Language; -use Drupal\simpletest\WebTestBase; +use Drupal\tour\Tests\TourTestBase; /** * Tests tour functionality. */ -class ViewsUITourTest extends UITestBase { +class ViewsUITourTest extends TourTestBase { /** - * Modules to enable. + * An admin user with administrative permissions for views. * - * @var array + * @var \Drupal\user\UserInterface */ - public static $modules = array('tour'); + protected $adminUser; /** - * Views used by this test. + * Modules to enable. * * @var array */ - public static $testViews = array('test_view'); + public static $modules = array('views_ui', 'tour'); public static function getInfo() { return array( @@ -39,16 +38,23 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - $this->drupalLogin($this->drupalCreateUser(array('access tour', 'administer views'))); + $this->adminUser = $this->drupalCreateUser(array('administer views', 'access tour')); + $this->drupalLogin($this->adminUser); } /** - * Tests the Views UI tour. + * Tests views_ui tour tip availability. */ - public function testTourFunctionality() { - $this->drupalGet('admin/structure/views/view/test_view'); - $elements = $this->xpath('//ol[@id="tour"]'); - $this->assertEqual(count($elements), 1, 'Found a tour on the test view.'); + public function testViewsUiTourTips() { + // Create a basic view that shows all content, with a page and a block + // display. + $view['label'] = $this->randomName(16); + $view['id'] = strtolower($this->randomName(16)); + $view['page[create]'] = 1; + $view['page[path]'] = $this->randomName(16); + $view_path = $view['page[path]']; + $this->drupalPost('admin/structure/views/add', $view, t('Save and edit')); + $this->assertTourTips(); } }