1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for help.module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests help display and user access for all modules implementing help.
|
10
|
*/
|
11
|
class HelpTestCase extends DrupalWebTestCase {
|
12
|
/**
|
13
|
* The admin user that will be created.
|
14
|
*/
|
15
|
protected $big_user;
|
16
|
|
17
|
/**
|
18
|
* The anonymous user that will be created.
|
19
|
*/
|
20
|
protected $any_user;
|
21
|
|
22
|
public static function getInfo() {
|
23
|
return array(
|
24
|
'name' => 'Help functionality',
|
25
|
'description' => 'Verify help display and user access to help based on permissions.',
|
26
|
'group' => 'Help',
|
27
|
);
|
28
|
}
|
29
|
|
30
|
function setUp() {
|
31
|
parent::setUp('blog', 'poll');
|
32
|
|
33
|
$this->getModuleList();
|
34
|
|
35
|
// Create users.
|
36
|
$this->big_user = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer permissions'));
|
37
|
$this->any_user = $this->drupalCreateUser(array());
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Logs in users, creates dblog events, and tests dblog functionality.
|
42
|
*/
|
43
|
function testHelp() {
|
44
|
// Login the admin user.
|
45
|
$this->drupalLogin($this->big_user);
|
46
|
$this->verifyHelp();
|
47
|
|
48
|
// Login the regular user.
|
49
|
$this->drupalLogin($this->any_user);
|
50
|
$this->verifyHelp(403);
|
51
|
|
52
|
// Check for css on admin/help.
|
53
|
$this->drupalLogin($this->big_user);
|
54
|
$this->drupalGet('admin/help');
|
55
|
$this->assertRaw(drupal_get_path('module', 'help') . '/help.css', 'The help.css file is present in the HTML.');
|
56
|
|
57
|
// Verify that introductory help text exists, goes for 100% module coverage.
|
58
|
$this->assertRaw(t('For more information, refer to the specific topics listed in the next section or to the <a href="@drupal">online Drupal handbooks</a>.', array('@drupal' => 'http://drupal.org/documentation')), 'Help intro text correctly appears.');
|
59
|
|
60
|
// Verify that help topics text appears.
|
61
|
$this->assertRaw('<h2>' . t('Help topics') . '</h2><p>' . t('Help is available on the following items:') . '</p>', 'Help topics text correctly appears.');
|
62
|
|
63
|
// Make sure links are properly added for modules implementing hook_help().
|
64
|
foreach ($this->modules as $module => $name) {
|
65
|
$this->assertLink($name, 0, format_string('Link properly added to @name (admin/help/@module)', array('@module' => $module, '@name' => $name)));
|
66
|
}
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Verifies the logged in user has access to the various help nodes.
|
71
|
*
|
72
|
* @param integer $response
|
73
|
* An HTTP response code.
|
74
|
*/
|
75
|
protected function verifyHelp($response = 200) {
|
76
|
foreach ($this->modules as $module => $name) {
|
77
|
// View module help node.
|
78
|
$this->drupalGet('admin/help/' . $module);
|
79
|
$this->assertResponse($response);
|
80
|
if ($response == 200) {
|
81
|
$this->assertTitle($name . ' | Drupal', format_string('%module title was displayed', array('%module' => $module)));
|
82
|
$this->assertRaw('<h1 class="page-title">' . t($name) . '</h1>', format_string('%module heading was displayed', array('%module' => $module)));
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Gets the list of enabled modules that implement hook_help().
|
89
|
*
|
90
|
* @return array
|
91
|
* A list of enabled modules.
|
92
|
*/
|
93
|
protected function getModuleList() {
|
94
|
$this->modules = array();
|
95
|
$result = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
|
96
|
foreach ($result as $module) {
|
97
|
if (file_exists($module->filename) && function_exists($module->name . '_help')) {
|
98
|
$fullname = unserialize($module->info);
|
99
|
$this->modules[$module->name] = $fullname['name'];
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* Tests a module without help to verify it is not listed in the help page.
|
107
|
*/
|
108
|
class NoHelpTestCase extends DrupalWebTestCase {
|
109
|
/**
|
110
|
* The user who will be created.
|
111
|
*/
|
112
|
protected $big_user;
|
113
|
|
114
|
public static function getInfo() {
|
115
|
return array(
|
116
|
'name' => 'No help',
|
117
|
'description' => 'Verify no help is displayed for modules not providing any help.',
|
118
|
'group' => 'Help',
|
119
|
);
|
120
|
}
|
121
|
|
122
|
function setUp() {
|
123
|
// Use one of the test modules that do not implement hook_help().
|
124
|
parent::setUp('menu_test');
|
125
|
$this->big_user = $this->drupalCreateUser(array('access administration pages'));
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Ensures modules not implementing help do not appear on admin/help.
|
130
|
*/
|
131
|
function testMainPageNoHelp() {
|
132
|
$this->drupalLogin($this->big_user);
|
133
|
|
134
|
$this->drupalGet('admin/help');
|
135
|
$this->assertNoText('Hook menu tests', 'Making sure the test module menu_test does not display a help link in admin/help');
|
136
|
}
|
137
|
}
|