help.test

Tests for help.module.

File

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