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