summaryrefslogtreecommitdiff
path: root/modules/help/help.test
blob: 73b4dedc86ac2d9e18cd1fe7597af85b2db1a0c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php

/**
 * @file
 * Tests for help.module.
 */

class HelpTestCase extends DrupalWebTestCase {
  protected $big_user;
  protected $any_user;

  public static function getInfo() {
    return array(
      'name' => 'Help functionality',
      'description' => 'Verify help display and user access to help based on permissions.',
      'group' => 'Help',
    );
  }

  /**
   * Enable modules and create users with specific permissions.
   */
  function setUp() {
    parent::setUp('blog', 'poll');

    $this->getModuleList();

    // Create users.
    $this->big_user = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer permissions'));
    $this->any_user = $this->drupalCreateUser(array());
  }

  /**
   * Login users, create dblog events, and test dblog functionality through the admin and user interfaces.
   */
  function testHelp() {
    // Login the admin user.
    $this->drupalLogin($this->big_user);
    $this->verifyHelp();

    // Login the regular user.
    $this->drupalLogin($this->any_user);
    $this->verifyHelp(403);

    // Check for css on admin/help.
    $this->drupalLogin($this->big_user);
    $this->drupalGet('admin/help');
    $this->assertRaw(drupal_get_path('module', 'help') . '/help.css', t('The help.css file is present in the HTML.'));

    // Verify that introductory help text exists, goes for 100% module coverage.
    $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/handbooks')), 'Help intro text correctly appears.');

    // Verify that help topics text appears.
    $this->assertRaw('<h2>' . t('Help topics') . '</h2><p>' . t('Help is available on the following items:') . '</p>', t('Help topics text correctly appears.'));

    // Make sure links are properly added for modules implementing hook_help().
    foreach ($this->modules as $module => $name) {
      $this->assertLink($name, 0, t('Link properly added to @name (admin/help/@module)', array('@module' => $module, '@name' => $name)));
    }
  }

  /**
   * Verify the logged in user has the desired access to the various help nodes and the nodes display help.
   *
   * @param integer $response HTTP response code.
   */
  protected function verifyHelp($response = 200) {
    foreach ($this->modules as $module => $name) {
      // View module help node.
      $this->drupalGet('admin/help/' . $module);
      $this->assertResponse($response);
      if ($response == 200) {
        $this->assertTitle($name . ' | Drupal', t('[' . $module . '] Title was displayed'));
        $this->assertRaw('<h1 class="page-title">' . t($name) . '</h1>', t('[' . $module . '] Heading was displayed'));
       }
    }
  }

  /**
   * Get list of enabled modules that implement hook_help().
   *
   * @return array Enabled modules.
   */
  protected function getModuleList() {
    $this->modules = array();
    $result = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
    foreach ($result as $module) {
      if (file_exists($module->filename) && function_exists($module->name . '_help')) {
        $fullname = unserialize($module->info);
        $this->modules[$module->name] = $fullname['name'];
      }
    }
  }
}

/**
 * Tests module without help to verify it is not listed in help page.
 */
class NoHelpTestCase extends DrupalWebTestCase {
  protected $big_user;

  public static function getInfo() {
    return array(
      'name' => 'No help',
      'description' => 'Verify no help is displayed for modules not providing any help.',
      'group' => 'Help',
    );
  }

  function setUp() {
    // Use one of the test modules that do not implement hook_help().
    parent::setUp('menu_test');
    $this->big_user = $this->drupalCreateUser(array('access administration pages'));
  }

  /**
   * Ensure modules not implementing help do not appear on admin/help.
   */
  function testMainPageNoHelp() {
    $this->drupalLogin($this->big_user);

    $this->drupalGet('admin/help');
    $this->assertNoText('Hook menu tests', t('Making sure the test module menu_test does not display a help link in admin/help'));
  }
}