Skip to content

Commit 8e81405

Browse files
Mile23paul-m
Mile23
authored andcommitted
Issue #2940089 by Mile23: Clean up tour_example tests
1 parent fd9fb85 commit 8e81405

File tree

5 files changed

+46
-165
lines changed

5 files changed

+46
-165
lines changed

tour_example/config/install/tour.tour.tour-example.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ tips:
7373
weight: 2
7474
location: bottom
7575
attributes:
76-
data-id: tour-id-1
76+
data-id: tour-target-1
7777
second-item:
7878
id: second-item
7979
plugin: text
@@ -82,7 +82,7 @@ tips:
8282
weight: 3
8383
location: top
8484
attributes:
85-
data-id: tour-id-2
85+
data-id: tour-target-2
8686
third-item:
8787
id: third-item
8888
plugin: text
@@ -91,7 +91,7 @@ tips:
9191
weight: 4
9292
location: bottom
9393
attributes:
94-
data-id: tour-id-3
94+
data-id: tour-target-3
9595
fourth-item:
9696
id: fourth-item
9797
plugin: text
@@ -100,4 +100,4 @@ tips:
100100
weight: 5
101101
location: left
102102
attributes:
103-
data-id: tour-id-4
103+
data-id: tour-target-4

tour_example/templates/description.html.twig

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
33
Description text for the Tour Example.
44
5+
Note that we have defined some 'buttons.' These page elements are targets for
6+
the tour we're demonstrating.
7+
8+
The id of the target elements are used in the tour definition file as targets
9+
for the various tour steps.
10+
511
#}
612

713
{% trans %}
814

915

1016
<h2>The Tour:</h2>
1117
<p>Click the 'Tour' icon in the admin menu bar to start.</p>
12-
<div class="button" id="tour-id-1">First item.</div>
13-
<div class="button" id="tour-id-2">Second item.</div>
14-
<div class="button" id="tour-id-3">Third item.</div>
15-
<div class="button" id="tour-id-4">Fourth item.</div>
18+
<div class="button" id="tour-target-1">First item.</div>
19+
<div class="button" id="tour-target-2">Second item.</div>
20+
<div class="button" id="tour-target-3">Third item.</div>
21+
<div class="button" id="tour-target-4">Fourth item.</div>
1622

1723
<h2>About Tours</h2>
1824

tour_example/tests/src/Functional/TourExampleTest.php

+32-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Drupal\Tests\tour_example\Functional;
44

5+
use Drupal\Core\Url;
6+
use Drupal\Tests\tour\Functional\TourTestBasic;
7+
58
/**
69
* Regression tests for the tour_example module.
710
*
@@ -19,7 +22,7 @@ class TourExampleTest extends TourTestBasic {
1922
*
2023
* @var array
2124
*/
22-
public static $modules = ['tour', 'tour_example'];
25+
public static $modules = ['tour_example'];
2326

2427
/**
2528
* The installation profile to use with this test.
@@ -31,23 +34,44 @@ class TourExampleTest extends TourTestBasic {
3134
/**
3235
* Main test.
3336
*
34-
* Enable Tour Example and see if it can successfully return its main page
35-
* and if there is a link to the tour example in the Tools menu.
37+
* Make sure the Tour Example link is on the front page. Make sure all the
38+
* tour tips exist on the page. Make sure all the corresponding target
39+
* elements exist for tour tips that have targets.
3640
*/
3741
public function testTourExample() {
38-
3942
$assert = $this->assertSession();
4043

4144
// Test for a link to the tour_example in the Tools menu.
42-
$this->drupalGet('');
45+
$this->drupalGet(Url::fromRoute('<front>'));
4346
$assert->statusCodeEquals(200);
4447
$assert->linkByHrefExists('examples/tour-example');
4548

46-
// Verify if the can successfully access the tour_examples page.
47-
$this->drupalGet('examples/tour-example');
49+
// Verify anonymous user can successfully access the tour_examples page.
50+
$this->drupalGet(Url::fromRoute('tour_example_description'));
4851
$assert->statusCodeEquals(200);
4952

50-
// Verify that the tour tips exist on this page.
53+
// Get all the tour elements. These are the IDs of each tour tip. See them
54+
// in config/install/tour.tour.tour-example.yml.
55+
$tip_ids = [
56+
'introduction',
57+
'first-item',
58+
'second-item',
59+
'third-item',
60+
'fourth-item',
61+
];
62+
63+
// Ensure that we have the same number of tour tips that we expect.
64+
$this->assertCount(count($tip_ids), $this->xpath("//ol[@id = \"tour\"]//li"));
65+
66+
// Ensure each item exists.
67+
foreach ($tip_ids as $tip_id) {
68+
$this->assertNotEmpty(
69+
$this->xpath("//ol[@id = \"tour\"]//li[contains(@class, \"tip-$tip_id\")]"),
70+
"Tip id: $tip_id"
71+
);
72+
}
73+
74+
// Verify that existing tour tips have corresponding target page elements.
5175
$this->assertTourTips();
5276
}
5377

tour_example/tests/src/Functional/TourTestBase.php

-73
This file was deleted.

tour_example/tests/src/Functional/TourTestBasic.php

-76
This file was deleted.

0 commit comments

Comments
 (0)