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