annotate modules/simpletest/simpletest.install @ 0:ff03f76ab3fe

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