Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\tour\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Verifies help page display of tours.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group help
|
Chris@0
|
11 */
|
Chris@0
|
12 class TourHelpPageTest extends BrowserTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Modules to enable, including some providing tours.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 public static $modules = ['help', 'tour', 'locale', 'language'];
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * User that can access tours and help.
|
Chris@0
|
23 *
|
Chris@0
|
24 * @var \Drupal\user\UserInterface
|
Chris@0
|
25 */
|
Chris@0
|
26 protected $tourUser;
|
Chris@0
|
27
|
Chris@0
|
28 /**
|
Chris@0
|
29 * A user who can access help but not tours.
|
Chris@0
|
30 *
|
Chris@0
|
31 * @var \Drupal\user\UserInterface
|
Chris@0
|
32 */
|
Chris@0
|
33 protected $noTourUser;
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * {@inheritdoc}
|
Chris@0
|
37 */
|
Chris@0
|
38 protected function setUp() {
|
Chris@0
|
39 parent::setUp();
|
Chris@0
|
40
|
Chris@0
|
41 // Create users. For the Tour user, include permissions for the language
|
Chris@0
|
42 // tours' parent pages, but not the translation tour's parent page. See
|
Chris@0
|
43 // self:getTourList().
|
Chris@0
|
44 $this->tourUser = $this->drupalCreateUser(['access administration pages', 'access tour', 'administer languages']);
|
Chris@0
|
45 $this->noTourUser = $this->drupalCreateUser(['access administration pages']);
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 /**
|
Chris@0
|
49 * Logs in users, tests help pages.
|
Chris@0
|
50 */
|
Chris@0
|
51 public function testHelp() {
|
Chris@0
|
52 $this->drupalLogin($this->tourUser);
|
Chris@0
|
53 $this->verifyHelp();
|
Chris@0
|
54
|
Chris@0
|
55 $this->drupalLogin($this->noTourUser);
|
Chris@0
|
56 $this->verifyHelp(FALSE);
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 /**
|
Chris@0
|
60 * Verifies the logged in user has access to the help properly.
|
Chris@0
|
61 *
|
Chris@0
|
62 * @param bool $tours_ok
|
Chris@0
|
63 * (optional) TRUE (default) if the user should see tours, FALSE if not.
|
Chris@0
|
64 */
|
Chris@0
|
65 protected function verifyHelp($tours_ok = TRUE) {
|
Chris@0
|
66 $this->drupalGet('admin/help');
|
Chris@0
|
67
|
Chris@0
|
68 // All users should be able to see the module section.
|
Chris@0
|
69 $this->assertText('Module overviews are provided by modules');
|
Chris@0
|
70 foreach ($this->getModuleList() as $name) {
|
Chris@0
|
71 $this->assertLink($name);
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 // Some users should be able to see the tour section.
|
Chris@0
|
75 if ($tours_ok) {
|
Chris@0
|
76 $this->assertText('Tours guide you through workflows');
|
Chris@0
|
77 }
|
Chris@0
|
78 else {
|
Chris@0
|
79 $this->assertNoText('Tours guide you through workflows');
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82 $titles = $this->getTourList();
|
Chris@0
|
83
|
Chris@0
|
84 // Test the titles that should be links.
|
Chris@0
|
85 foreach ($titles[0] as $title) {
|
Chris@0
|
86 if ($tours_ok) {
|
Chris@0
|
87 $this->assertLink($title);
|
Chris@0
|
88 }
|
Chris@0
|
89 else {
|
Chris@0
|
90 $this->assertNoLink($title);
|
Chris@0
|
91 // Just test the first item in the list of links that should not
|
Chris@0
|
92 // be there, because the second matches the name of a module that is
|
Chris@0
|
93 // in the Module overviews section, so the link will be there and
|
Chris@0
|
94 // this test will fail. Testing one should be sufficient to verify
|
Chris@0
|
95 // the page is working correctly.
|
Chris@0
|
96 break;
|
Chris@0
|
97 }
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 // Test the titles that should not be links.
|
Chris@0
|
101 foreach ($titles[1] as $title) {
|
Chris@0
|
102 if ($tours_ok) {
|
Chris@0
|
103 $this->assertText($title);
|
Chris@0
|
104 $this->assertSession()->linkNotExistsExact($title);
|
Chris@0
|
105 }
|
Chris@0
|
106 else {
|
Chris@0
|
107 $this->assertNoText($title);
|
Chris@0
|
108 // Just test the first item in the list of text that should not
|
Chris@0
|
109 // be there, because the second matches part of the name of a module
|
Chris@0
|
110 // that is in the Module overviews section, so the text will be there
|
Chris@0
|
111 // and this test will fail. Testing one should be sufficient to verify
|
Chris@0
|
112 // the page is working correctly.
|
Chris@0
|
113 break;
|
Chris@0
|
114 }
|
Chris@0
|
115 }
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@0
|
118 /**
|
Chris@0
|
119 * Gets a list of modules to test for hook_help() pages.
|
Chris@0
|
120 *
|
Chris@0
|
121 * @return array
|
Chris@0
|
122 * A list of module names to test.
|
Chris@0
|
123 */
|
Chris@0
|
124 protected function getModuleList() {
|
Chris@0
|
125 return ['Help', 'Tour'];
|
Chris@0
|
126 }
|
Chris@0
|
127
|
Chris@0
|
128 /**
|
Chris@0
|
129 * Gets a list of tours to test.
|
Chris@0
|
130 *
|
Chris@0
|
131 * @return array
|
Chris@0
|
132 * A list of tour titles to test. The first array element is a list of tours
|
Chris@0
|
133 * with links, and the second is a list of tours without links. Assumes
|
Chris@0
|
134 * that the user being tested has 'administer languages' permission but
|
Chris@0
|
135 * not 'translate interface'.
|
Chris@0
|
136 */
|
Chris@0
|
137 protected function getTourList() {
|
Chris@0
|
138 return [['Adding languages', 'Language'], ['Editing languages', 'Translation']];
|
Chris@0
|
139 }
|
Chris@0
|
140
|
Chris@0
|
141 }
|