Chris@0: tourUser = $this->drupalCreateUser(['access administration pages', 'access tour', 'administer languages']); Chris@0: $this->noTourUser = $this->drupalCreateUser(['access administration pages']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Logs in users, tests help pages. Chris@0: */ Chris@0: public function testHelp() { Chris@0: $this->drupalLogin($this->tourUser); Chris@0: $this->verifyHelp(); Chris@0: Chris@0: $this->drupalLogin($this->noTourUser); Chris@0: $this->verifyHelp(FALSE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Verifies the logged in user has access to the help properly. Chris@0: * Chris@0: * @param bool $tours_ok Chris@0: * (optional) TRUE (default) if the user should see tours, FALSE if not. Chris@0: */ Chris@0: protected function verifyHelp($tours_ok = TRUE) { Chris@0: $this->drupalGet('admin/help'); Chris@0: Chris@0: // All users should be able to see the module section. Chris@0: $this->assertText('Module overviews are provided by modules'); Chris@0: foreach ($this->getModuleList() as $name) { Chris@0: $this->assertLink($name); Chris@0: } Chris@0: Chris@0: // Some users should be able to see the tour section. Chris@0: if ($tours_ok) { Chris@0: $this->assertText('Tours guide you through workflows'); Chris@0: } Chris@0: else { Chris@0: $this->assertNoText('Tours guide you through workflows'); Chris@0: } Chris@0: Chris@0: $titles = $this->getTourList(); Chris@0: Chris@0: // Test the titles that should be links. Chris@0: foreach ($titles[0] as $title) { Chris@0: if ($tours_ok) { Chris@0: $this->assertLink($title); Chris@0: } Chris@0: else { Chris@0: $this->assertNoLink($title); Chris@0: // Just test the first item in the list of links that should not Chris@0: // be there, because the second matches the name of a module that is Chris@0: // in the Module overviews section, so the link will be there and Chris@0: // this test will fail. Testing one should be sufficient to verify Chris@0: // the page is working correctly. Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: // Test the titles that should not be links. Chris@0: foreach ($titles[1] as $title) { Chris@0: if ($tours_ok) { Chris@0: $this->assertText($title); Chris@0: $this->assertSession()->linkNotExistsExact($title); Chris@0: } Chris@0: else { Chris@0: $this->assertNoText($title); Chris@0: // Just test the first item in the list of text that should not Chris@0: // be there, because the second matches part of the name of a module Chris@0: // that is in the Module overviews section, so the text will be there Chris@0: // and this test will fail. Testing one should be sufficient to verify Chris@0: // the page is working correctly. Chris@0: break; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets a list of modules to test for hook_help() pages. Chris@0: * Chris@0: * @return array Chris@0: * A list of module names to test. Chris@0: */ Chris@0: protected function getModuleList() { Chris@0: return ['Help', 'Tour']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets a list of tours to test. Chris@0: * Chris@0: * @return array Chris@0: * A list of tour titles to test. The first array element is a list of tours Chris@0: * with links, and the second is a list of tours without links. Assumes Chris@0: * that the user being tested has 'administer languages' permission but Chris@0: * not 'translate interface'. Chris@0: */ Chris@0: protected function getTourList() { Chris@0: return [['Adding languages', 'Language'], ['Editing languages', 'Translation']]; Chris@0: } Chris@0: Chris@0: }