count(file_scan_directory($path, '/(html|image|javascript|php|sql)-.*/'))) {
if (count($files) > count(file_scan_directory($path, '(html|image|javascript|php|sql)-.*'))) {
foreach ($files as $file) {
// file_unmanaged_copy($file->uri, $path, FILE_EXISTS_REPLACE);
copy($file->filename, $path . '/' . $file->basename);
}
$generated = TRUE;
}
if ($generated) {
drupal_set_message('Extra test files generated/copied.');
}
}
}
/**
* 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() {
simpletest_clean_environment();
// Remove settings variables.
variable_del('simpletest_username');
variable_del('simpletest_password');
variable_del('simpletest_clear_results');
variable_del('simpletest_verbose');
// Uninstall schema.
drupal_uninstall_schema('simpletest');
// Remove generated files.
$path = file_directory_path() . '/simpletest';
// $files = file_scan_directory($path, '/.*/');
$files = file_scan_directory($path, '.*');
foreach ($files as $file) {
// file_unmanaged_delete($file->uri);
unlink($file->filename);
}
rmdir($path);
}
/**
* Check that the cURL extension exists for PHP.
*/
function simpletest_requirements($phase) {
$requirements = array();
$t = get_t();
$has_curl = function_exists('curl_init');
$has_hash = function_exists('hash_hmac');
$has_domdocument = method_exists('DOMDocument', 'loadHTML');
$requirements['curl'] = array(
'title' => $t('cURL'),
'value' => $has_curl ? $t('Enabled') : $t('Not found'),
);
if (!$has_curl) {
$requirements['curl']['severity'] = REQUIREMENT_ERROR;
$requirements['curl']['description'] = $t('Simpletest could not be installed because the PHP cURL library is not available.', array('@curl_url' => 'http://php.net/manual/en/curl.setup.php'));
}
$requirements['hash'] = array(
'title' => $t('hash'),
'value' => $has_hash ? $t('Enabled') : $t('Not found'),
);
if (!$has_hash) {
$requirements['hash']['severity'] = REQUIREMENT_ERROR;
$requirements['hash']['description'] = $t('Simpletest could not be installed because the PHP hash extension is disabled.', array('@hash_url' => 'http://php.net/manual/en/book.hash.php'));
}
$requirements['php_domdocument'] = array(
'title' => $t('PHP DOMDocument class'),
'value' => $has_domdocument ? $t('Enabled') : $t('Not found'),
);
if (!$has_domdocument) {
$requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;
$requirements['php_domdocument']['description'] =t('SimpleTest requires the DOMDocument class to be available. Please check the configure command at the PHP info page.', array('@link-phpinfo' => url('admin/reports/status/php')));
}
// Drupal 6.
// Check that the global variable is defined signifying that the code was inserted correctly.
if (isset($GLOBALS['simpletest_installed'])) {
$requirements['simpletest_settings'] = array(
'title' => $t('SimpleTest code addition'),
'value' => t('Found'),
'severity' => REQUIREMENT_OK
);
}
else {
$requirements['simpletest_settings'] = array(
'title' => $t('SimpleTest code addition'),
'value' => t('Not-found'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('SimpleTest could not be installed. Must apply core patch, please see
INSTALL.txt.',
array('%settings' => realpath(conf_path() . '/settings.php'),
'@install' => base_path() . drupal_get_path('module', 'simpletest') . '/INSTALL.txt')),
);
}
return $requirements;
}
function simpletest_schema() {
$schema['simpletest'] = array(
'description' => 'Stores simpletest messages',
'fields' => array(
'message_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique simpletest message ID.',
),
'test_id' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Test ID, messages belonging to the same ID are reported together',
),
'test_class' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The name of the class that created this message.',
),
'status' => array(
'type' => 'varchar',
'length' => 9,
'not null' => TRUE,
'default' => '',
'description' => 'Message status. Core understands pass, fail, exception.',
),
'message' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'The message itself.',
),
'message_group' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The message group this message belongs to. For example: warning, browser, user.',
),
'function' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the assertion function or method that created this message.',
),
'line' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Line number on which the function is called.',
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the file where the function is called.',
),
),
'primary key' => array('message_id'),
'indexes' => array(
'reporter' => array('test_class', 'message_id'),
),
);
$schema['simpletest_test_id'] = array(
'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',
'fields' => array(
'test_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
are run a new test ID is used.',
),
'last_prefix' => array(
'type' => 'varchar',
'length' => 60,
'not null' => FALSE,
'default' => '',
'description' => 'The last database prefix used during testing.',
),
),
'primary key' => array('test_id'),
);
return $schema;
}
/**
* Upgrade simpletest 5.x-1.x and 6.x-1.x to 6.x-2.1 release.
*
* Provides a basic upgrade path for initial switch to 2.x branch. The update
* path will not be continued as there is no data that needs to be updated and
* any further releases should simply un-install and install just like Drupal
* HEAD development.
*/
function simpletest_update_6200() {
$ret = array();
// Drop any existing SimpleTest tables.
if (db_table_exists('simpletest')) {
db_drop_table($ret, 'simpletest');
}
if (db_table_exists('simpletest_test_id')) {
db_drop_table($ret, 'simpletest_test_id');
}
// Install most recent schema and files.
simpletest_install();
return $ret;
}