Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\help\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Verify help display and user access to help based on permissions.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group help
|
Chris@0
|
11 */
|
Chris@0
|
12 class HelpTest extends BrowserTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Modules to enable.
|
Chris@0
|
16 *
|
Chris@0
|
17 * The help_test module implements hook_help() but does not provide a module
|
Chris@0
|
18 * overview page. The help_page_test module has a page section plugin that
|
Chris@0
|
19 * returns no links.
|
Chris@0
|
20 *
|
Chris@17
|
21 * @var array
|
Chris@0
|
22 */
|
Chris@0
|
23 public static $modules = ['help_test', 'help_page_test'];
|
Chris@0
|
24
|
Chris@0
|
25 /**
|
Chris@0
|
26 * Use the Standard profile to test help implementations of many core modules.
|
Chris@12
|
27 *
|
Chris@12
|
28 * @var string
|
Chris@0
|
29 */
|
Chris@0
|
30 protected $profile = 'standard';
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * The admin user that will be created.
|
Chris@0
|
34 */
|
Chris@0
|
35 protected $adminUser;
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * The anonymous user that will be created.
|
Chris@0
|
39 */
|
Chris@0
|
40 protected $anyUser;
|
Chris@0
|
41
|
Chris@0
|
42 protected function setUp() {
|
Chris@0
|
43 parent::setUp();
|
Chris@0
|
44
|
Chris@0
|
45 // Create users.
|
Chris@0
|
46 $this->adminUser = $this->drupalCreateUser(['access administration pages', 'view the administration theme', 'administer permissions']);
|
Chris@0
|
47 $this->anyUser = $this->drupalCreateUser([]);
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * Logs in users, tests help pages.
|
Chris@0
|
52 */
|
Chris@0
|
53 public function testHelp() {
|
Chris@0
|
54 // Log in the root user to ensure as many admin links appear as possible on
|
Chris@0
|
55 // the module overview pages.
|
Chris@0
|
56 $this->drupalLogin($this->rootUser);
|
Chris@0
|
57 $this->verifyHelp();
|
Chris@0
|
58
|
Chris@0
|
59 // Log in the regular user.
|
Chris@0
|
60 $this->drupalLogin($this->anyUser);
|
Chris@0
|
61 $this->verifyHelp(403);
|
Chris@0
|
62
|
Chris@0
|
63 // Verify that introductory help text exists, goes for 100% module coverage.
|
Chris@0
|
64 $this->drupalLogin($this->adminUser);
|
Chris@0
|
65 $this->drupalGet('admin/help');
|
Chris@0
|
66 $this->assertRaw(t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', [':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org']));
|
Chris@0
|
67
|
Chris@0
|
68 // Verify that hook_help() section title and description appear.
|
Chris@0
|
69 $this->assertRaw('<h2>' . t('Module overviews') . '</h2>');
|
Chris@0
|
70 $this->assertRaw('<p>' . t('Module overviews are provided by modules. Overviews available for your installed modules:'), '</p>');
|
Chris@0
|
71
|
Chris@0
|
72 // Verify that an empty section is handled correctly.
|
Chris@0
|
73 $this->assertRaw('<h2>' . t('Empty section') . '</h2>');
|
Chris@0
|
74 $this->assertRaw('<p>' . t('This description should appear.'), '</p>');
|
Chris@0
|
75 $this->assertText(t('There is currently nothing in this section.'));
|
Chris@0
|
76
|
Chris@0
|
77 // Make sure links are properly added for modules implementing hook_help().
|
Chris@0
|
78 foreach ($this->getModuleList() as $module => $name) {
|
Chris@0
|
79 $this->assertLink($name, 0, format_string('Link properly added to @name (admin/help/@module)', ['@module' => $module, '@name' => $name]));
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82 // Ensure that module which does not provide an module overview page is
|
Chris@0
|
83 // handled correctly.
|
Chris@0
|
84 $this->clickLink(\Drupal::moduleHandler()->getName('help_test'));
|
Chris@0
|
85 $this->assertRaw(t('No help is available for module %module.', ['%module' => \Drupal::moduleHandler()->getName('help_test')]));
|
Chris@0
|
86
|
Chris@0
|
87 // Verify that the order of topics is alphabetical by displayed module
|
Chris@0
|
88 // name, by checking the order of some modules, including some that would
|
Chris@0
|
89 // have a different order if it was done by machine name instead.
|
Chris@0
|
90 $this->drupalGet('admin/help');
|
Chris@0
|
91 $page_text = $this->getTextContent();
|
Chris@0
|
92 $start = strpos($page_text, 'Module overviews');
|
Chris@0
|
93 $pos = $start;
|
Chris@0
|
94 $list = ['Block', 'Color', 'Custom Block', 'History', 'Text Editor'];
|
Chris@0
|
95 foreach ($list as $name) {
|
Chris@0
|
96 $this->assertLink($name);
|
Chris@0
|
97 $new_pos = strpos($page_text, $name, $start);
|
Chris@0
|
98 $this->assertTrue($new_pos > $pos, 'Order of ' . $name . ' is correct on page');
|
Chris@0
|
99 $pos = $new_pos;
|
Chris@0
|
100 }
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@0
|
103 /**
|
Chris@0
|
104 * Verifies the logged in user has access to the various help pages.
|
Chris@0
|
105 *
|
Chris@0
|
106 * @param int $response
|
Chris@0
|
107 * (optional) An HTTP response code. Defaults to 200.
|
Chris@0
|
108 */
|
Chris@0
|
109 protected function verifyHelp($response = 200) {
|
Chris@0
|
110 $this->drupalGet('admin/index');
|
Chris@0
|
111 $this->assertResponse($response);
|
Chris@0
|
112 if ($response == 200) {
|
Chris@0
|
113 $this->assertText('This page shows you all available administration tasks for each module.');
|
Chris@0
|
114 }
|
Chris@0
|
115 else {
|
Chris@0
|
116 $this->assertNoText('This page shows you all available administration tasks for each module.');
|
Chris@0
|
117 }
|
Chris@0
|
118
|
Chris@0
|
119 foreach ($this->getModuleList() as $module => $name) {
|
Chris@0
|
120 // View module help page.
|
Chris@0
|
121 $this->drupalGet('admin/help/' . $module);
|
Chris@0
|
122 $this->assertResponse($response);
|
Chris@0
|
123 if ($response == 200) {
|
Chris@0
|
124 $this->assertTitle($name . ' | Drupal', format_string('%module title was displayed', ['%module' => $module]));
|
Chris@0
|
125 $this->assertEquals($name, $this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed");
|
Chris@0
|
126 $admin_tasks = system_get_module_admin_tasks($module, system_get_info('module', $module));
|
Chris@0
|
127 if (!empty($admin_tasks)) {
|
Chris@0
|
128 $this->assertText(t('@module administration pages', ['@module' => $name]));
|
Chris@0
|
129 }
|
Chris@0
|
130 foreach ($admin_tasks as $task) {
|
Chris@0
|
131 $this->assertLink($task['title']);
|
Chris@0
|
132 // Ensure there are no double escaped '&' or '<' characters.
|
Chris@0
|
133 $this->assertNoEscaped('&', 'The help text does not have double escaped &.');
|
Chris@0
|
134 $this->assertNoEscaped('<', 'The help text does not have double escaped <.');
|
Chris@0
|
135 // Ensure there are no escaped '<' characters.
|
Chris@0
|
136 $this->assertNoEscaped('<', 'The help text does not have single escaped <.');
|
Chris@0
|
137 }
|
Chris@0
|
138 // Ensure there are no double escaped '&' or '<' characters.
|
Chris@0
|
139 $this->assertNoEscaped('&');
|
Chris@0
|
140 $this->assertNoEscaped('<');
|
Chris@0
|
141 // Ensure there are no escaped '<' characters.
|
Chris@0
|
142 $this->assertNoEscaped('<');
|
Chris@0
|
143 }
|
Chris@0
|
144 }
|
Chris@0
|
145 }
|
Chris@0
|
146
|
Chris@0
|
147 /**
|
Chris@0
|
148 * Gets the list of enabled modules that implement hook_help().
|
Chris@0
|
149 *
|
Chris@0
|
150 * @return array
|
Chris@0
|
151 * A list of enabled modules.
|
Chris@0
|
152 */
|
Chris@0
|
153 protected function getModuleList() {
|
Chris@0
|
154 $modules = [];
|
Chris@0
|
155 $module_data = system_rebuild_module_data();
|
Chris@0
|
156 foreach (\Drupal::moduleHandler()->getImplementations('help') as $module) {
|
Chris@0
|
157 $modules[$module] = $module_data[$module]->info['name'];
|
Chris@0
|
158 }
|
Chris@0
|
159 return $modules;
|
Chris@0
|
160 }
|
Chris@0
|
161
|
Chris@0
|
162 }
|