simpletest.install 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the simpletest module.
  5. */
  6. /**
  7. * Minimum value of PHP memory_limit for SimpleTest.
  8. */
  9. define('SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT', '64M');
  10. /**
  11. * Implements hook_requirements().
  12. */
  13. function simpletest_requirements($phase) {
  14. $requirements = array();
  15. $t = get_t();
  16. $has_curl = function_exists('curl_init');
  17. $has_hash = function_exists('hash_hmac');
  18. $has_domdocument = method_exists('DOMDocument', 'loadHTML');
  19. $open_basedir = ini_get('open_basedir');
  20. $requirements['curl'] = array(
  21. 'title' => $t('cURL'),
  22. 'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  23. );
  24. if (!$has_curl) {
  25. $requirements['curl']['severity'] = REQUIREMENT_ERROR;
  26. $requirements['curl']['description'] = $t('The testing framework could not be installed because the PHP <a href="@curl_url">cURL</a> library is not available.', array('@curl_url' => 'http://php.net/manual/en/curl.setup.php'));
  27. }
  28. $requirements['hash'] = array(
  29. 'title' => $t('hash'),
  30. 'value' => $has_hash ? $t('Enabled') : $t('Not found'),
  31. );
  32. if (!$has_hash) {
  33. $requirements['hash']['severity'] = REQUIREMENT_ERROR;
  34. $requirements['hash']['description'] = $t('The testing framework could not be installed because the PHP <a href="@hash_url">hash</a> extension is disabled.', array('@hash_url' => 'http://php.net/manual/en/book.hash.php'));
  35. }
  36. $requirements['php_domdocument'] = array(
  37. 'title' => $t('PHP DOMDocument class'),
  38. 'value' => $has_domdocument ? $t('Enabled') : $t('Not found'),
  39. );
  40. if (!$has_domdocument) {
  41. $requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;
  42. $requirements['php_domdocument']['description'] = $t('The testing framework requires the DOMDocument class to be available. Check the configure command at the <a href="@link-phpinfo">PHP info page</a>.', array('@link-phpinfo' => url('admin/reports/status/php')));
  43. }
  44. // SimpleTest currently needs 2 cURL options which are incompatible with
  45. // having PHP's open_basedir restriction set.
  46. // See http://drupal.org/node/674304.
  47. $requirements['php_open_basedir'] = array(
  48. 'title' => $t('PHP open_basedir restriction'),
  49. 'value' => $open_basedir ? $t('Enabled') : $t('Disabled'),
  50. );
  51. if ($open_basedir) {
  52. $requirements['php_open_basedir']['severity'] = REQUIREMENT_ERROR;
  53. $requirements['php_open_basedir']['description'] = $t('The testing framework requires the PHP <a href="@open_basedir-url">open_basedir</a> restriction to be disabled. Check your webserver configuration or contact your web host.', array('@open_basedir-url' => 'http://php.net/manual/en/ini.core.php#ini.open-basedir'));
  54. }
  55. // Check the current memory limit. If it is set too low, SimpleTest will fail
  56. // to load all tests and throw a fatal error.
  57. $memory_limit = ini_get('memory_limit');
  58. if (!drupal_check_memory_limit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
  59. $requirements['php_memory_limit']['severity'] = REQUIREMENT_ERROR;
  60. $requirements['php_memory_limit']['description'] = $t('The testing framework requires the PHP memory limit to be at least %memory_minimum_limit. The current value is %memory_limit. <a href="@url">Follow these steps to continue</a>.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, '@url' => 'http://drupal.org/node/207036'));
  61. }
  62. return $requirements;
  63. }
  64. /**
  65. * Implements hook_schema().
  66. */
  67. function simpletest_schema() {
  68. $schema['simpletest'] = array(
  69. 'description' => 'Stores simpletest messages',
  70. 'fields' => array(
  71. 'message_id' => array(
  72. 'type' => 'serial',
  73. 'not null' => TRUE,
  74. 'description' => 'Primary Key: Unique simpletest message ID.',
  75. ),
  76. 'test_id' => array(
  77. 'type' => 'int',
  78. 'not null' => TRUE,
  79. 'default' => 0,
  80. 'description' => 'Test ID, messages belonging to the same ID are reported together',
  81. ),
  82. 'test_class' => array(
  83. 'type' => 'varchar',
  84. 'length' => 255,
  85. 'not null' => TRUE,
  86. 'default' => '',
  87. 'description' => 'The name of the class that created this message.',
  88. ),
  89. 'status' => array(
  90. 'type' => 'varchar',
  91. 'length' => 9,
  92. 'not null' => TRUE,
  93. 'default' => '',
  94. 'description' => 'Message status. Core understands pass, fail, exception.',
  95. ),
  96. 'message' => array(
  97. 'type' => 'text',
  98. 'not null' => TRUE,
  99. 'description' => 'The message itself.',
  100. ),
  101. 'message_group' => array(
  102. 'type' => 'varchar',
  103. 'length' => 255,
  104. 'not null' => TRUE,
  105. 'default' => '',
  106. 'description' => 'The message group this message belongs to. For example: warning, browser, user.',
  107. ),
  108. 'function' => array(
  109. 'type' => 'varchar',
  110. 'length' => 255,
  111. 'not null' => TRUE,
  112. 'default' => '',
  113. 'description' => 'Name of the assertion function or method that created this message.',
  114. ),
  115. 'line' => array(
  116. 'type' => 'int',
  117. 'not null' => TRUE,
  118. 'default' => 0,
  119. 'description' => 'Line number on which the function is called.',
  120. ),
  121. 'file' => array(
  122. 'type' => 'varchar',
  123. 'length' => 255,
  124. 'not null' => TRUE,
  125. 'default' => '',
  126. 'description' => 'Name of the file where the function is called.',
  127. ),
  128. ),
  129. 'primary key' => array('message_id'),
  130. 'indexes' => array(
  131. 'reporter' => array('test_class', 'message_id'),
  132. ),
  133. );
  134. $schema['simpletest_test_id'] = array(
  135. 'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',
  136. 'fields' => array(
  137. 'test_id' => array(
  138. 'type' => 'serial',
  139. 'not null' => TRUE,
  140. 'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
  141. are run a new test ID is used.',
  142. ),
  143. 'last_prefix' => array(
  144. 'type' => 'varchar',
  145. 'length' => 60,
  146. 'not null' => FALSE,
  147. 'default' => '',
  148. 'description' => 'The last database prefix used during testing.',
  149. ),
  150. ),
  151. 'primary key' => array('test_id'),
  152. );
  153. return $schema;
  154. }
  155. /**
  156. * Implements hook_uninstall().
  157. */
  158. function simpletest_uninstall() {
  159. drupal_load('module', 'simpletest');
  160. simpletest_clean_database();
  161. // Remove settings variables.
  162. variable_del('simpletest_httpauth_method');
  163. variable_del('simpletest_httpauth_username');
  164. variable_del('simpletest_httpauth_password');
  165. variable_del('simpletest_clear_results');
  166. variable_del('simpletest_verbose');
  167. // Remove generated files.
  168. file_unmanaged_delete_recursive('public://simpletest');
  169. }