simpletest.install 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. $requirements['curl'] = array(
  20. 'title' => $t('cURL'),
  21. 'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  22. );
  23. if (!$has_curl) {
  24. $requirements['curl']['severity'] = REQUIREMENT_ERROR;
  25. $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'));
  26. }
  27. $requirements['hash'] = array(
  28. 'title' => $t('hash'),
  29. 'value' => $has_hash ? $t('Enabled') : $t('Not found'),
  30. );
  31. if (!$has_hash) {
  32. $requirements['hash']['severity'] = REQUIREMENT_ERROR;
  33. $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'));
  34. }
  35. $requirements['php_domdocument'] = array(
  36. 'title' => $t('PHP DOMDocument class'),
  37. 'value' => $has_domdocument ? $t('Enabled') : $t('Not found'),
  38. );
  39. if (!$has_domdocument) {
  40. $requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;
  41. $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')));
  42. }
  43. // Check the current memory limit. If it is set too low, SimpleTest will fail
  44. // to load all tests and throw a fatal error.
  45. $memory_limit = ini_get('memory_limit');
  46. if (!drupal_check_memory_limit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
  47. $requirements['php_memory_limit']['severity'] = REQUIREMENT_ERROR;
  48. $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'));
  49. }
  50. return $requirements;
  51. }
  52. /**
  53. * Implements hook_schema().
  54. */
  55. function simpletest_schema() {
  56. $schema['simpletest'] = array(
  57. 'description' => 'Stores simpletest messages',
  58. 'fields' => array(
  59. 'message_id' => array(
  60. 'type' => 'serial',
  61. 'not null' => TRUE,
  62. 'description' => 'Primary Key: Unique simpletest message ID.',
  63. ),
  64. 'test_id' => array(
  65. 'type' => 'int',
  66. 'not null' => TRUE,
  67. 'default' => 0,
  68. 'description' => 'Test ID, messages belonging to the same ID are reported together',
  69. ),
  70. 'test_class' => array(
  71. 'type' => 'varchar',
  72. 'length' => 255,
  73. 'not null' => TRUE,
  74. 'default' => '',
  75. 'description' => 'The name of the class that created this message.',
  76. ),
  77. 'status' => array(
  78. 'type' => 'varchar',
  79. 'length' => 9,
  80. 'not null' => TRUE,
  81. 'default' => '',
  82. 'description' => 'Message status. Core understands pass, fail, exception.',
  83. ),
  84. 'message' => array(
  85. 'type' => 'text',
  86. 'not null' => TRUE,
  87. 'description' => 'The message itself.',
  88. ),
  89. 'message_group' => array(
  90. 'type' => 'varchar',
  91. 'length' => 255,
  92. 'not null' => TRUE,
  93. 'default' => '',
  94. 'description' => 'The message group this message belongs to. For example: warning, browser, user.',
  95. ),
  96. 'function' => array(
  97. 'type' => 'varchar',
  98. 'length' => 255,
  99. 'not null' => TRUE,
  100. 'default' => '',
  101. 'description' => 'Name of the assertion function or method that created this message.',
  102. ),
  103. 'line' => array(
  104. 'type' => 'int',
  105. 'not null' => TRUE,
  106. 'default' => 0,
  107. 'description' => 'Line number on which the function is called.',
  108. ),
  109. 'file' => array(
  110. 'type' => 'varchar',
  111. 'length' => 255,
  112. 'not null' => TRUE,
  113. 'default' => '',
  114. 'description' => 'Name of the file where the function is called.',
  115. ),
  116. ),
  117. 'primary key' => array('message_id'),
  118. 'indexes' => array(
  119. 'reporter' => array('test_class', 'message_id'),
  120. ),
  121. );
  122. $schema['simpletest_test_id'] = array(
  123. 'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',
  124. 'fields' => array(
  125. 'test_id' => array(
  126. 'type' => 'serial',
  127. 'not null' => TRUE,
  128. 'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
  129. are run a new test ID is used.',
  130. ),
  131. 'last_prefix' => array(
  132. 'type' => 'varchar',
  133. 'length' => 60,
  134. 'not null' => FALSE,
  135. 'default' => '',
  136. 'description' => 'The last database prefix used during testing.',
  137. ),
  138. ),
  139. 'primary key' => array('test_id'),
  140. );
  141. return $schema;
  142. }
  143. /**
  144. * Implements hook_uninstall().
  145. */
  146. function simpletest_uninstall() {
  147. drupal_load('module', 'simpletest');
  148. simpletest_clean_database();
  149. // Remove settings variables.
  150. variable_del('simpletest_httpauth_method');
  151. variable_del('simpletest_httpauth_username');
  152. variable_del('simpletest_httpauth_password');
  153. variable_del('simpletest_clear_results');
  154. variable_del('simpletest_verbose');
  155. // Remove generated files.
  156. file_unmanaged_delete_recursive('public://simpletest');
  157. }