2
2
3
3
namespace Drupal \Tests \tour_example \Functional ;
4
4
5
+ use Drupal \Core \Url ;
6
+ use Drupal \Tests \tour \Functional \TourTestBasic ;
7
+
5
8
/**
6
9
* Regression tests for the tour_example module.
7
10
*
@@ -19,7 +22,7 @@ class TourExampleTest extends TourTestBasic {
19
22
*
20
23
* @var array
21
24
*/
22
- public static $ modules = ['tour ' , ' tour_example ' ];
25
+ public static $ modules = ['tour_example ' ];
23
26
24
27
/**
25
28
* The installation profile to use with this test.
@@ -31,23 +34,44 @@ class TourExampleTest extends TourTestBasic {
31
34
/**
32
35
* Main test.
33
36
*
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.
36
40
*/
37
41
public function testTourExample () {
38
-
39
42
$ assert = $ this ->assertSession ();
40
43
41
44
// Test for a link to the tour_example in the Tools menu.
42
- $ this ->drupalGet ('' );
45
+ $ this ->drupalGet (Url:: fromRoute ( ' <front> ' ) );
43
46
$ assert ->statusCodeEquals (200 );
44
47
$ assert ->linkByHrefExists ('examples/tour-example ' );
45
48
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 ' ) );
48
51
$ assert ->statusCodeEquals (200 );
49
52
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.
51
75
$ this ->assertTourTips ();
52
76
}
53
77
0 commit comments