Line # | Frequency | Source Line |
1 | | <?php
|
2 | | // $Id: help.test,v 1.1 2008/04/04 23:01:20 boombatower Exp $
|
3 | |
|
4 | | class HelpModuleTestCase extends DrupalTestCase {
|
5 | | protected $big_user;
|
6 | | protected $any_user;
|
7 | |
|
8 | | /**
|
9 | | * Implementation of getInfo().
|
10 | | */
|
11 | | function getInfo() {
|
12 | | return array(
|
13 | 1 | 'name' => t('Help functionality'),
|
14 | | 'description' => t('Verify help display and user access to help based on persmissions.'),
|
15 | | 'group' => t('Help Tests'),
|
16 | | );
|
17 | | }
|
18 | |
|
19 | | /**
|
20 | | * Enable modules and create users with specific permissions.
|
21 | | */
|
22 | | function setUp() {
|
23 | 1 | parent::setUp();
|
24 | |
|
25 | | // Loading these (and other?) modules will result in failures?
|
26 | | // $this->drupalModuleEnable('blog');
|
27 | | // $this->drupalModuleEnable('poll');
|
28 | 1 | $this->getModuleList();
|
29 | |
|
30 | | // Create users.
|
31 | 1 | $this->big_user = $this->drupalCreateUser(array('access administration pages')); // 'administer blocks', 'administer site configuration',
|
32 | 1 | $this->any_user = $this->drupalCreateUser(array());
|
33 | | }
|
34 | |
|
35 | | /**
|
36 | | * Login users, create dblog events, and test dblog functionality through the admin and user interfaces.
|
37 | | */
|
38 | | function testHelp() {
|
39 | | // Login the admin user.
|
40 | 1 | $this->drupalLogin($this->big_user);
|
41 | 1 | $this->verifyHelp();
|
42 | |
|
43 | | // Login the regular user.
|
44 | 1 | $user = $this->drupalLogin($this->any_user);
|
45 | 1 | $this->verifyHelp(403);
|
46 | | }
|
47 | |
|
48 | | /**
|
49 | | * Verify the logged in user has the desired access to the various help nodes and the nodes display help.
|
50 | | *
|
51 | | * @param integer $response HTTP response code.
|
52 | | */
|
53 | | private function verifyHelp($response = 200) {
|
54 | 1 | $crumb = '›';
|
55 | |
|
56 | 1 | foreach ($this->modules as $module => $name) {
|
57 | | // View module help node.
|
58 | 1 | $this->drupalGet('admin/help/'. $module);
|
59 | 1 | $this->assertResponse($response);
|
60 | 1 | if ($response == 200) {
|
61 | | // NOTE: The asserts fail on blog and poll because the get returns the 'admin/help' node instead of the indicated node???
|
62 | | // if ($module == 'blog' || $module == 'poll') {
|
63 | | // continue;
|
64 | | // }
|
65 | 1 | $this->assertTitle($name. ' | Drupal', t('['. $module .'] Title was displayed'));
|
66 | 1 | $this->assertRaw('<h2>'. t($name) .'</h2>', t('['. $module .'] Heading was displayed'));
|
67 | 1 | $this->assertText(t('Home '. $crumb .' Administer '. $crumb .' Help'), t('['. $module .'] Breadcrumbs were displayed'));
|
68 | | }
|
69 | | }
|
70 | | }
|
71 | |
|
72 | | /**
|
73 | | * Get list of enabled modules.
|
74 | | *
|
75 | | * @return array Enabled modules.
|
76 | | */
|
77 | | private function getModuleList() {
|
78 | 1 | $this->modules = array();
|
79 | 1 | $result = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
|
80 | 1 | while ($module = db_fetch_object($result)) {
|
81 | 1 | if (file_exists($module->filename)) {
|
82 | 1 | $fullname = unserialize($module->info);
|
83 | 1 | $this->modules[$module->name] = $fullname['name'];
|
84 | | }
|
85 | | }
|
86 | | }
|
87 | | }
|