00001 <?php
00002
00003
00014 function simpletest_install() {
00015 drupal_install_schema('simpletest');
00016
00017 $path = file_directory_path() . '/simpletest';
00018 if (file_check_directory($path, FILE_CREATE_DIRECTORY)) {
00019
00020 $generated = FALSE;
00021 if (simpletest_get_file_count($path, 'binary') == 0) {
00022 $lines = array(64, 1024);
00023 foreach ($lines as $line) {
00024 simpletest_generate_file('binary', 64, $line, 'binary');
00025 }
00026 $generated = TRUE;
00027 }
00028
00029 if (simpletest_get_file_count($path, 'text') == 0) {
00030 $lines = array(16, 256, 1024, 2048, 20480);
00031 foreach ($lines as $line) {
00032 simpletest_generate_file('text', 64, $line);
00033 }
00034 $generated = TRUE;
00035 }
00036
00037
00038 $files = file_scan_directory($path, '/(html|image|javascript|php|sql)-.*/');
00039 if (count($files) == 0) {
00040 $original = drupal_get_path('module', 'simpletest') . '/files';
00041 $files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/');
00042 foreach ($files as $file) {
00043
00044 file_unmanaged_copy($file->filename, $path . '/' . $file->basename);
00045 }
00046 $generated = TRUE;
00047 }
00048
00049 if ($generated) {
00050 drupal_set_message('Extra test files generated.');
00051 }
00052 }
00053 }
00054
00058 function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
00059 $size = $width * $lines - $lines;
00060
00061
00062 $text = '';
00063 for ($i = 0; $i < $size; $i++) {
00064 switch ($type) {
00065 case 'text':
00066 $text .= chr(rand(32, 126));
00067 break;
00068 case 'binary':
00069 $text .= chr(rand(0, 31));
00070 break;
00071 case 'binary-text':
00072 default:
00073 $text .= rand(0, 1);
00074 break;
00075 }
00076 }
00077 $text = wordwrap($text, $width - 1, "\n", TRUE) ."\n";
00078
00079
00080 $path = file_directory_path() . '/simpletest/';
00081 $count = simpletest_get_file_count($path, $filename);
00082 file_put_contents($path . $filename . '-' . ($count + 1) . '.txt', $text);
00083 }
00084
00088 function simpletest_get_file_count($directory, $filename) {
00089 $files = scandir($directory);
00090 $count = 0;
00091 foreach ($files as $file) {
00092 if (preg_match('/' . $filename . '.*?/', $file)) {
00093 $count++;
00094 }
00095 }
00096 return $count;
00097 }
00098
00102 function simpletest_uninstall() {
00103 simpletest_clean_environment();
00104
00105 variable_del('simpletest_httpauth');
00106 variable_del('simpletest_httpauth_username');
00107 variable_del('simpletest_httpauth_pass');
00108 variable_del('simpletest_devel');
00109 drupal_uninstall_schema('simpletest');
00110 }
00111
00115 function simpletest_requirements($phase) {
00116 $requirements = array();
00117 $t = get_t();
00118
00119 $has_curl = function_exists('curl_init');
00120 $has_domdocument = class_exists('DOMDocument');
00121
00122 $requirements['curl'] = array(
00123 'title' => $t('cURL'),
00124 'value' => $has_curl ? $t('Enabled') : $t('Not found'),
00125 );
00126 if (!$has_curl) {
00127 $requirements['curl']['severity'] = REQUIREMENT_ERROR;
00128 $requirements['curl']['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'));
00129 }
00130
00131 $requirements['php_domdocument'] = array(
00132 'title' => $t('PHP DOMDocument class'),
00133 'value' => $has_domdocument ? $t('Enabled') : $t('Not found'),
00134 );
00135 if (!$has_domdocument) {
00136 $requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;
00137 $requirements['php_domdocument']['description'] =t('SimpleTest requires the DOMDocument class to be available. Please check the configure command at the <a href="@link-phpinfo">PHP info page</a>.', array('@link-phpinfo' => url('admin/reports/status/php')));
00138 }
00139
00140
00141
00142 if (isset($GLOBALS['simpletest_installed'])) {
00143 $requirements['simpletest_settings'] = array(
00144 'title' => $t('SimpleTest code addition'),
00145 'value' => t('Found'),
00146 'severity' => REQUIREMENT_OK
00147 );
00148 }
00149 else {
00150 $requirements['simpletest_settings'] = array(
00151 'title' => $t('SimpleTest code addition'),
00152 'value' => t('Not-found'),
00153 'severity' => REQUIREMENT_ERROR,
00154 'description' => $t('SimpleTest could not be installed. Must add code to the %settings file please see
00155 <a href="@install">INSTALL.txt</a>.',
00156 array('%settings' => realpath(conf_path() . '/settings.php'),
00157 '@install' => url(drupal_get_path('module', 'simpletest') . '/INSTALL.txt')))
00158 );
00159 }
00160
00161 return $requirements;
00162 }
00163
00164 function simpletest_schema() {
00165 $schema['simpletest'] = array(
00166 'description' => 'Stores simpletest messages',
00167 'fields' => array(
00168 'message_id' => array(
00169 'type' => 'serial',
00170 'not null' => TRUE,
00171 'description' => 'Primary Key: Unique simpletest message ID.',
00172 ),
00173 'test_id' => array(
00174 'type' => 'int',
00175 'not null' => TRUE,
00176 'default' => 0,
00177 'description' => 'Test ID, messages belonging to the same ID are reported together',
00178 ),
00179 'test_class' => array(
00180 'type' => 'varchar',
00181 'length' => 255,
00182 'not null' => TRUE,
00183 'default' => '',
00184 'description' => 'The name of the class that created this message.',
00185 ),
00186 'status' => array(
00187 'type' => 'varchar',
00188 'length' => 9,
00189 'not null' => TRUE,
00190 'default' => '',
00191 'description' => 'Message status. Core understands pass, fail, exception.',
00192 ),
00193 'message' => array(
00194 'type' => 'text',
00195 'not null' => TRUE,
00196 'description' => 'The message itself.',
00197 ),
00198 'message_group' => array(
00199 'type' => 'varchar',
00200 'length' => 255,
00201 'not null' => TRUE,
00202 'default' => '',
00203 'description' => 'The message group this message belongs to. For example: warning, browser, user.',
00204 ),
00205 'function' => array(
00206 'type' => 'varchar',
00207 'length' => 255,
00208 'not null' => TRUE,
00209 'default' => '',
00210 'description' => 'Name of the assertion function or method that created this message.',
00211 ),
00212 'line' => array(
00213 'type' => 'int',
00214 'not null' => TRUE,
00215 'default' => 0,
00216 'description' => 'Line number on which the function is called.',
00217 ),
00218 'file' => array(
00219 'type' => 'varchar',
00220 'length' => 255,
00221 'not null' => TRUE,
00222 'default' => '',
00223 'description' => 'Name of the file where the function is called.',
00224 ),
00225 ),
00226 'primary key' => array('message_id'),
00227 'indexes' => array(
00228 'reporter' => array('test_class', 'message_id'),
00229 ),
00230 );
00231 $schema['simpletest_test_id'] = array(
00232 'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',
00233 'fields' => array(
00234 'test_id' => array(
00235 'type' => 'serial',
00236 'not null' => TRUE,
00237 'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
00238 are run a new test ID is used.',
00239 ),
00240 ),
00241 'primary key' => array('test_id'),
00242 );
00243 return $schema;
00244 }
00245
00251 function simpletest_update_6000() {
00252 $ret = array();
00253 $schema = array();
00254
00255
00256 $path = file_directory_path() . '/simpletest';
00257 if (file_check_directory($path, FILE_CREATE_DIRECTORY)) {
00258
00259 $generated = FALSE;
00260 if (simpletest_get_file_count($path, 'binary') == 0) {
00261 $lines = array(64, 1024);
00262 foreach ($lines as $line) {
00263 simpletest_generate_file('binary', 64, $line, 'binary');
00264 }
00265 $generated = TRUE;
00266 }
00267
00268 if (simpletest_get_file_count($path, 'text') == 0) {
00269 $lines = array(16, 256, 1024, 2048, 20480);
00270 foreach ($lines as $line) {
00271 simpletest_generate_file('text', 64, $line);
00272 }
00273 $generated = TRUE;
00274 }
00275
00276
00277 $files = file_scan_directory($path, '(html|image|javascript|php|sql)-.*');
00278 if (count($files) == 0) {
00279 $original = drupal_get_path('module', 'simpletest') . '/files';
00280 $files = file_scan_directory($original, '(html|image|javascript|php|sql)-.*');
00281 foreach ($files as $file) {
00282 file_copy($file->filename, $path . '/' . $file->basename);
00283 }
00284 $generated = TRUE;
00285 }
00286
00287 if ($generated) {
00288 $ret[] = array('success' => TRUE, 'query' => 'Extra test files generated.');
00289 }
00290 }
00291
00292
00293 $schema['simpletest'] = array(
00294 'description' => t('Stores simpletest messages'),
00295 'fields' => array(
00296 'message_id' => array(
00297 'type' => 'serial',
00298 'not null' => TRUE,
00299 'description' => t('Primary Key: Unique simpletest message ID.'),
00300 ),
00301 'test_id' => array(
00302 'type' => 'int',
00303 'not null' => TRUE,
00304 'default' => 0,
00305 'description' => t('Test ID, messages belonging to the same ID are reported together'),
00306 ),
00307 'test_class' => array(
00308 'type' => 'varchar',
00309 'length' => 255,
00310 'not null' => TRUE,
00311 'default' => '',
00312 'description' => t('The name of the class that created this message.'),
00313 ),
00314 'status' => array(
00315 'type' => 'varchar',
00316 'length' => 9,
00317 'not null' => TRUE,
00318 'default' => '',
00319 'description' => t('Message status. Core understands pass, fail, exception.'),
00320 ),
00321 'message' => array(
00322 'type' => 'varchar',
00323 'length' => 255,
00324 'not null' => TRUE,
00325 'default' => '',
00326 'description' => t('The message itself.'),
00327 ),
00328 'message_group' => array(
00329 'type' => 'varchar',
00330 'length' => 255,
00331 'not null' => TRUE,
00332 'default' => '',
00333 'description' => t('The message group this message belongs to. For example: warning, browser, user.'),
00334 ),
00335 'caller' => array(
00336 'type' => 'varchar',
00337 'length' => 255,
00338 'not null' => TRUE,
00339 'default' => '',
00340 'description' => t('Name of the caller function or method that created this message.'),
00341 ),
00342 'line' => array(
00343 'type' => 'int',
00344 'not null' => TRUE,
00345 'default' => 0,
00346 'description' => t('Line number on which the function is called.'),
00347 ),
00348 'file' => array(
00349 'type' => 'varchar',
00350 'length' => 255,
00351 'not null' => TRUE,
00352 'default' => '',
00353 'description' => t('Name of the file where the function is called.'),
00354 ),
00355 ),
00356 'primary key' => array('message_id'),
00357 'indexes' => array(
00358 'reporter' => array('test_class', 'message_id'),
00359 ),
00360 );
00361 $schema['simpletest_test_id'] = array(
00362 'description' => t('Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.'),
00363 'fields' => array(
00364 'test_id' => array(
00365 'type' => 'serial',
00366 'not null' => TRUE,
00367 'description' => t('Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
00368 are run a new test ID is used.')
00369 )
00370 ),
00371 'primary key' => array('test_id')
00372 );
00373
00374
00375 db_create_table($ret, 'simpletest', $schema['simpletest']);
00376
00377
00378 if (db_table_exists('simpletest_test_id')) {
00379 db_drop_table($ret, 'simpletest_test_id');
00380 }
00381 db_create_table($ret, 'simpletest_test_id', $schema['simpletest_test_id']);
00382
00383 return $ret;
00384 }
00385
00389 function simpletest_update_6001() {
00390 $ret = array();
00391 $schema = array();
00392
00393 $schema = array(
00394 'type' => 'text',
00395 'not null' => TRUE
00396 );
00397
00398
00399 db_query('DELETE FROM {simpletest}');
00400
00401 db_drop_field($ret, 'simpletest', 'message');
00402 db_add_field($ret, 'simpletest', 'message', $schema);
00403
00404 return $ret;
00405 }
00406
00410 function simpletest_update_6002() {
00411 $ret = array();
00412 $schema = array();
00413
00414 $schema = array(
00415 'type' => 'varchar',
00416 'length' => 255,
00417 'not null' => TRUE,
00418 'default' => ''
00419 );
00420
00421
00422 db_query('DELETE FROM {simpletest}');
00423
00424 db_drop_field($ret, 'simpletest', 'caller');
00425 db_add_field($ret, 'simpletest', 'function', $schema);
00426
00427 return $ret;
00428 }