3 namespace Drupal\tour\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Verifies help page display of tours.
12 class TourHelpPageTest extends WebTestBase {
15 * Modules to enable, including some providing tours.
19 public static $modules = ['help', 'tour', 'locale', 'language'];
22 * User that can access tours and help.
24 * @var \Drupal\user\UserInterface
29 * A user who can access help but not tours.
31 * @var \Drupal\user\UserInterface
33 protected $noTourUser;
38 protected function setUp() {
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']);
49 * Logs in users, tests help pages.
51 public function testHelp() {
52 $this->drupalLogin($this->tourUser);
55 $this->drupalLogin($this->noTourUser);
56 $this->verifyHelp(FALSE);
60 * Verifies the logged in user has access to the help properly.
62 * @param bool $tours_ok
63 * (optional) TRUE (default) if the user should see tours, FALSE if not.
65 protected function verifyHelp($tours_ok = TRUE) {
66 $this->drupalGet('admin/help');
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);
74 // Some users should be able to see the tour section.
76 $this->assertText('Tours guide you through workflows');
79 $this->assertNoText('Tours guide you through workflows');
82 $titles = $this->getTourList();
84 // Test the titles that should be links.
85 foreach ($titles[0] as $title) {
87 $this->assertLink($title);
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.
100 // Test the titles that should not be links.
101 foreach ($titles[1] as $title) {
103 $this->assertText($title);
104 $this->assertNoLink($title);
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.
119 * Gets a list of modules to test for hook_help() pages.
122 * A list of module names to test.
124 protected function getModuleList() {
125 return ['Help', 'Tour'];
129 * Gets a list of tours to test.
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'.
137 protected function getTourList() {
138 return [['Adding languages', 'Language'], ['Editing languages', 'Translation']];