1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
<?php
// $Id$
/**
* Implementation of hook_install().
*/
function simpletest_install() {
drupal_install_schema('simpletest');
// Check for files directory.
$path = file_directory_path() . '/simpletest';
if (file_check_directory($path, FILE_CREATE_DIRECTORY)) {
// Generate binary and text test files.
$generated = FALSE;
if (simpletest_get_file_count($path, 'binary') == 0) {
$lines = array(64, 1024);
foreach ($lines as $line) {
simpletest_generate_file('binary', 64, $line, 'binary');
}
$generated = TRUE;
}
if (simpletest_get_file_count($path, 'text') == 0) {
$lines = array(16, 256, 1024, 2048, 20480);
foreach ($lines as $line) {
simpletest_generate_file('text', 64, $line);
}
$generated = TRUE;
}
// Copy other test files for consistency.
$files = file_scan_directory($path, '(html|image|javascript|php|sql)-.*');
if (count($files) == 0) {
$original = drupal_get_path('module', 'simpletest') . '/files';
$files = file_scan_directory($original, '(html|image|javascript|php|sql)-.*');
foreach ($files as $file) {
file_copy($file->filename, $path . '/' . $file->basename);
}
$generated = TRUE;
}
if ($generated) {
drupal_set_message('Extra test files generated.');
}
}
}
/**
* Generate test file.
*/
function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
$size = $width * $lines - $lines;
// Generate random text
$text = '';
for ($i = 0; $i < $size; $i++) {
switch ($type) {
case 'text':
$text .= chr(rand(32, 126));
break;
case 'binary':
$text .= chr(rand(0, 31));
break;
case 'binary-text':
default:
$text .= rand(0, 1);
break;
}
}
$text = wordwrap($text, $width - 1, "\n", TRUE) ."\n"; // Add \n for symetrical file.
// Create filename.
$path = file_directory_path() . '/simpletest/';
$count = simpletest_get_file_count($path, $filename);
file_put_contents($path . $filename . '-' . ($count + 1) . '.txt', $text);
}
/**
* Get the number of files that have the specified filename base.
*/
function simpletest_get_file_count($directory, $filename) {
$files = scandir($directory);
$count = 0;
foreach ($files as $file) {
if (preg_match('/' . $filename . '.*?/', $file)) {
$count++;
}
}
return $count;
}
/**
* Implementation of hook_uninstall().
*/
function simpletest_uninstall() {
variable_del('simpletest_httpauth');
variable_del('simpletest_httpauth_username');
variable_del('simpletest_httpauth_pass');
variable_del('simpletest_devel');
drupal_uninstall_schema('simpletest');
}
/**
* Check that the cURL extension exists for PHP.
*/
function simpletest_requirements($phase) {
$requirements = array();
$t = get_t();
$has_curl = function_exists('curl_init');
switch ($phase) {
case 'runtime':
$requirements['simpletest'] = array(
'title' => $t('cURL'),
'value' => $has_curl ? $t('Enabled') : $t('Not found'),
'severity' => $has_curl ? REQUIREMENT_OK : REQUIREMENT_ERROR,
);
break;
case 'install':
if ($has_curl) {
$requirements['simpletest'] = array(
'title' => $t('cURL'),
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['simpletest'] = array(
'title' => $t('cURL'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('Simpletest 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')),
);
}
break;
}
return $requirements;
}
function simpletest_schema() {
$schema['simpletest'] = array(
'description' => t('Stores simpletest messages'),
'fields' => array(
'message_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => t('Primary Key: Unique simpletest message ID.'),
),
'test_id' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => t('Test id, messages belonging to the same id are reported together'),
),
'test_class' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => t('The name of the class that created this message.'),
),
'status' => array(
'type' => 'varchar',
'length' => 9,
'not null' => TRUE,
'default' => '',
'description' => t('Message status. Core understands pass, fail, exception.'),
),
'message' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => t('The message itself.'),
),
'message_group' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => t('The message group this message belongs to. For example: warning, browser, user.'),
),
'caller' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => t('Name of the caller function or method that created this message.'),
),
'line' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => t('Line number of the caller.'),
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => t('Name of the file where the caller is.'),
),
),
'primary key' => array('message_id'),
'indexes' => array(
'reporter' => array('test_class, message_id'),
),
);
$schema['simpletest_test_id'] = array(
'description' => t('Stores simpletest test IDs.'),
'fields' => array(
'message_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => t('Primary Key: Unique simpletest ID.'),
),
),
'primary key' => array('message_id'),
);
return $schema;
}
/**
* Create the simpletest tables.
*/
function simpletest_update_7000() {
$ret = array();
$schema = array();
$schema['simpletest'] = array(
'fields' => array(
'message_id' => array('type' => 'serial', 'not null' => TRUE),
'test_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'test_class' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'status' => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''),
'message' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'message_group' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'caller' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'line' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'file' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
),
'primary key' => array('message_id'),
'indexes' => array(
'reporter' => array('test_class, message_id'),
),
);
$schema['simpletest_test_id'] = array(
'fields' => array(
'message_id' => array('type' => 'serial', 'not null' => TRUE),
),
'primary key' => array('message_id'),
);
foreach ($schema as $name => $definition) {
db_create_table($ret, $name, $definition);
}
return $ret;
}
|