Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\tour\Functional;
|
Chris@0
|
4
|
Chris@18
|
5 use Drupal\Core\Url;
|
Chris@0
|
6 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@0
|
7 use Drupal\tour\Entity\Tour;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Tests the functionality of tour tips.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @group tour
|
Chris@0
|
13 */
|
Chris@0
|
14 class TourTest extends TourTestBasic {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Modules to enable.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @var array
|
Chris@0
|
20 */
|
Chris@0
|
21 public static $modules = ['block', 'tour', 'locale', 'language', 'tour_test'];
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * The permissions required for a logged in user to test tour tips.
|
Chris@0
|
25 *
|
Chris@0
|
26 * @var array
|
Chris@0
|
27 * A list of permissions.
|
Chris@0
|
28 */
|
Chris@0
|
29 protected $permissions = ['access tour', 'administer languages'];
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * Tour tip attributes to be tested. Keyed by the path.
|
Chris@0
|
33 *
|
Chris@0
|
34 * @var array
|
Chris@0
|
35 * An array of tip attributes, keyed by path.
|
Chris@0
|
36 */
|
Chris@0
|
37 protected $tips = [
|
Chris@0
|
38 'tour-test-1' => [],
|
Chris@0
|
39 ];
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * {@inheritdoc}
|
Chris@0
|
43 */
|
Chris@0
|
44 protected function setUp() {
|
Chris@0
|
45 parent::setUp();
|
Chris@0
|
46
|
Chris@0
|
47 $this->drupalPlaceBlock('local_actions_block', [
|
Chris@0
|
48 'theme' => 'seven',
|
Chris@17
|
49 'region' => 'content',
|
Chris@0
|
50 ]);
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * Test tour functionality.
|
Chris@0
|
55 */
|
Chris@0
|
56 public function testTourFunctionality() {
|
Chris@0
|
57 // Navigate to tour-test-1 and verify the tour_test_1 tip is found with appropriate classes.
|
Chris@0
|
58 $this->drupalGet('tour-test-1');
|
Chris@0
|
59
|
Chris@0
|
60 // Test the TourTestBase class assertTourTips() method.
|
Chris@0
|
61 $tips = [];
|
Chris@0
|
62 $tips[] = ['data-id' => 'tour-test-1'];
|
Chris@0
|
63 $tips[] = ['data-class' => 'tour-test-5'];
|
Chris@0
|
64 $this->assertTourTips($tips);
|
Chris@0
|
65 $this->assertTourTips();
|
Chris@0
|
66
|
Chris@0
|
67 $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./p//a[@href=:href and contains(., :text)]]', [
|
Chris@0
|
68 ':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
|
Chris@0
|
69 ':data_id' => 'tour-test-1',
|
Chris@18
|
70 ':href' => Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(),
|
Chris@0
|
71 ':text' => 'Drupal',
|
Chris@0
|
72 ]);
|
Chris@0
|
73 $this->assertEqual(count($elements), 1, 'Found Token replacement.');
|
Chris@0
|
74
|
Chris@0
|
75 $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')");
|
Chris@0
|
76 $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.');
|
Chris@0
|
77
|
Chris@0
|
78 $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
|
Chris@0
|
79 $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 2.');
|
Chris@0
|
80
|
Chris@0
|
81 $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')");
|
Chris@0
|
82 $this->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.');
|
Chris@0
|
83
|
Chris@0
|
84 // Ensure that plugins work.
|
Chris@0
|
85 $elements = $this->xpath('//img[@src="http://local/image.png"]');
|
Chris@0
|
86 $this->assertEqual(count($elements), 1, 'Image plugin tip found.');
|
Chris@0
|
87
|
Chris@0
|
88 // Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found.
|
Chris@0
|
89 $this->drupalGet('tour-test-2/subpath');
|
Chris@0
|
90 $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
|
Chris@0
|
91 $this->assertEqual(count($elements), 1, 'Found English variant of tip 2.');
|
Chris@0
|
92
|
Chris@0
|
93 $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('The first tip')");
|
Chris@0
|
94 $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.');
|
Chris@0
|
95
|
Chris@0
|
96 // Enable Italian language and navigate to it/tour-test1 and verify italian
|
Chris@0
|
97 // version of tip is found.
|
Chris@0
|
98 ConfigurableLanguage::createFromLangcode('it')->save();
|
Chris@0
|
99 $this->drupalGet('it/tour-test-1');
|
Chris@0
|
100
|
Chris@0
|
101 $elements = $this->cssSelect("li[data-id=tour-test-1] h2:contains('La pioggia cade in spagna')");
|
Chris@0
|
102 $this->assertEqual(count($elements), 1, 'Found Italian variant of tip 1.');
|
Chris@0
|
103
|
Chris@0
|
104 $elements = $this->cssSelect("li[data-id=tour-test-2] h2:contains('The quick brown fox')");
|
Chris@0
|
105 $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.');
|
Chris@0
|
106
|
Chris@0
|
107 // Programmatically create a tour for use through the remainder of the test.
|
Chris@0
|
108 $tour = Tour::create([
|
Chris@0
|
109 'id' => 'tour-entity-create-test-en',
|
Chris@0
|
110 'label' => 'Tour test english',
|
Chris@0
|
111 'langcode' => 'en',
|
Chris@0
|
112 'module' => 'system',
|
Chris@0
|
113 'routes' => [
|
Chris@0
|
114 ['route_name' => 'tour_test.1'],
|
Chris@0
|
115 ],
|
Chris@0
|
116 'tips' => [
|
Chris@0
|
117 'tour-test-1' => [
|
Chris@0
|
118 'id' => 'tour-code-test-1',
|
Chris@0
|
119 'plugin' => 'text',
|
Chris@0
|
120 'label' => 'The rain in spain',
|
Chris@0
|
121 'body' => 'Falls mostly on the plain.',
|
Chris@0
|
122 'weight' => '100',
|
Chris@0
|
123 'attributes' => [
|
Chris@0
|
124 'data-id' => 'tour-code-test-1',
|
Chris@0
|
125 ],
|
Chris@0
|
126 ],
|
Chris@0
|
127 'tour-code-test-2' => [
|
Chris@0
|
128 'id' => 'tour-code-test-2',
|
Chris@0
|
129 'plugin' => 'image',
|
Chris@0
|
130 'label' => 'The awesome image',
|
Chris@0
|
131 'url' => 'http://local/image.png',
|
Chris@0
|
132 'weight' => 1,
|
Chris@0
|
133 'attributes' => [
|
Chris@17
|
134 'data-id' => 'tour-code-test-2',
|
Chris@0
|
135 ],
|
Chris@0
|
136 ],
|
Chris@0
|
137 ],
|
Chris@0
|
138 ]);
|
Chris@0
|
139 $tour->save();
|
Chris@0
|
140
|
Chris@0
|
141 // Ensure that a tour entity has the expected dependencies based on plugin
|
Chris@0
|
142 // providers and the module named in the configuration entity.
|
Chris@0
|
143 $dependencies = $tour->calculateDependencies()->getDependencies();
|
Chris@0
|
144 $this->assertEqual($dependencies['module'], ['system', 'tour_test']);
|
Chris@0
|
145
|
Chris@0
|
146 $this->drupalGet('tour-test-1');
|
Chris@0
|
147
|
Chris@0
|
148 // Load it back from the database and verify storage worked.
|
Chris@0
|
149 $entity_save_tip = Tour::load('tour-entity-create-test-en');
|
Chris@0
|
150 // Verify that hook_ENTITY_TYPE_load() integration worked.
|
Chris@0
|
151 $this->assertEqual($entity_save_tip->loaded, 'Load hooks work');
|
Chris@0
|
152 // Verify that hook_ENTITY_TYPE_presave() integration worked.
|
Chris@0
|
153 $this->assertEqual($entity_save_tip->label(), 'Tour test english alter');
|
Chris@0
|
154
|
Chris@0
|
155 // Navigate to tour-test-1 and verify the new tip is found.
|
Chris@0
|
156 $this->drupalGet('tour-test-1');
|
Chris@0
|
157 $elements = $this->cssSelect("li[data-id=tour-code-test-1] h2:contains('The rain in spain')");
|
Chris@0
|
158 $this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4');
|
Chris@0
|
159
|
Chris@0
|
160 // Verify that the weight sorting works by ensuring the lower weight item
|
Chris@0
|
161 // (tip 4) has the 'End tour' button.
|
Chris@0
|
162 $elements = $this->cssSelect("li[data-id=tour-code-test-1][data-text='End tour']");
|
Chris@0
|
163 $this->assertEqual(count($elements), 1, 'Found code tip was weighted last and had "End tour".');
|
Chris@0
|
164
|
Chris@0
|
165 // Test hook_tour_alter().
|
Chris@0
|
166 $this->assertText('Altered by hook_tour_tips_alter');
|
Chris@0
|
167
|
Chris@0
|
168 // Navigate to tour-test-3 and verify the tour_test_1 tip is found with
|
Chris@0
|
169 // appropriate classes.
|
Chris@0
|
170 $this->drupalGet('tour-test-3/foo');
|
Chris@0
|
171 $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [
|
Chris@0
|
172 ':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
|
Chris@0
|
173 ':data_id' => 'tour-test-1',
|
Chris@0
|
174 ':text' => 'The first tip',
|
Chris@0
|
175 ]);
|
Chris@0
|
176 $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.');
|
Chris@0
|
177
|
Chris@0
|
178 // Navigate to tour-test-3 and verify the tour_test_1 tip is not found with
|
Chris@0
|
179 // appropriate classes.
|
Chris@0
|
180 $this->drupalGet('tour-test-3/bar');
|
Chris@0
|
181 $elements = $this->xpath('//li[@data-id=:data_id and @class=:classes and ./h2[contains(., :text)]]', [
|
Chris@0
|
182 ':classes' => 'tip-module-tour-test tip-type-text tip-tour-test-1',
|
Chris@0
|
183 ':data_id' => 'tour-test-1',
|
Chris@0
|
184 ':text' => 'The first tip',
|
Chris@0
|
185 ]);
|
Chris@0
|
186 $this->assertEqual(count($elements), 0, 'Did not find English variant of tip 1.');
|
Chris@0
|
187 }
|
Chris@0
|
188
|
Chris@0
|
189 }
|