- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
<?php
2009-05-13 19:42:18 +00:00
/**
* @file
* Install, update and uninstall functions for the simpletest module.
*/
2011-01-03 06:40:49 +00:00
/**
* Minimum value of PHP memory_limit for SimpleTest.
*/
2011-11-29 09:56:53 +00:00
const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '64M';
2011-01-03 06:40:49 +00:00
2008-04-28 09:30:35 +00:00
/**
2010-10-15 23:40:21 +00:00
* Implements hook_requirements().
2008-04-28 09:30:35 +00:00
*/
function simpletest_requirements($phase) {
$requirements = array();
$has_curl = function_exists('curl_init');
2010-10-08 00:22:17 +00:00
$has_domdocument = method_exists('DOMDocument', 'loadHTML');
2010-01-07 05:34:21 +00:00
$open_basedir = ini_get('open_basedir');
2008-04-28 09:30:35 +00:00
2009-02-01 17:11:00 +00:00
$requirements['curl'] = array(
2013-06-17 13:35:07 +00:00
'title' => t('cURL'),
'value' => $has_curl ? t('Enabled') : t('Not found'),
2009-02-01 17:11:00 +00:00
);
if (!$has_curl) {
$requirements['curl']['severity'] = REQUIREMENT_ERROR;
2013-06-17 13:35:07 +00:00
$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/curl.setup.php'));
2009-02-01 17:11:00 +00:00
}
$requirements['php_domdocument'] = array(
2013-06-17 13:35:07 +00:00
'title' => t('PHP DOMDocument class'),
'value' => $has_domdocument ? t('Enabled') : t('Not found'),
2009-02-01 17:11:00 +00:00
);
if (!$has_domdocument) {
$requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;
2013-06-17 13:35:07 +00:00
$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')));
2008-04-28 09:30:35 +00:00
}
2010-01-07 05:34:21 +00:00
// SimpleTest currently needs 2 cURL options which are incompatible with
// having PHP's open_basedir restriction set.
2010-03-26 17:14:46 +00:00
// See http://drupal.org/node/674304.
2010-01-07 05:34:21 +00:00
$requirements['php_open_basedir'] = array(
2013-06-17 13:35:07 +00:00
'title' => t('PHP open_basedir restriction'),
'value' => $open_basedir ? t('Enabled') : t('Disabled'),
2010-01-07 05:34:21 +00:00
);
if ($open_basedir) {
$requirements['php_open_basedir']['severity'] = REQUIREMENT_ERROR;
2013-06-17 13:35:07 +00:00
$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/ini.core.php#ini.open-basedir'));
2010-01-07 05:34:21 +00:00
}
2011-01-03 06:40:49 +00:00
// Check the current memory limit. If it is set too low, SimpleTest will fail
// to load all tests and throw a fatal error.
$memory_limit = ini_get('memory_limit');
2012-05-07 02:55:11 +00:00
if (!drupal_check_memory_limit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
2011-01-03 06:40:49 +00:00
$requirements['php_memory_limit']['severity'] = REQUIREMENT_ERROR;
2013-06-17 13:35:07 +00:00
$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'));
2011-01-03 06:40:49 +00:00
}
2008-04-28 09:30:35 +00:00
return $requirements;
}
2008-06-24 21:51:03 +00:00
2010-10-15 23:40:21 +00:00
/**
* Implements hook_schema().
*/
2008-06-24 21:51:03 +00:00
function simpletest_schema() {
$schema['simpletest'] = array(
2008-11-15 13:01:11 +00:00
'description' => 'Stores simpletest messages',
2008-06-24 21:51:03 +00:00
'fields' => array(
'message_id' => array(
'type' => 'serial',
'not null' => TRUE,
2008-11-15 13:01:11 +00:00
'description' => 'Primary Key: Unique simpletest message ID.',
2008-06-24 21:51:03 +00:00
),
'test_id' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'Test ID, messages belonging to the same ID are reported together',
2008-06-24 21:51:03 +00:00
),
'test_class' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'The name of the class that created this message.',
2008-06-24 21:51:03 +00:00
),
'status' => array(
'type' => 'varchar',
'length' => 9,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'Message status. Core understands pass, fail, exception.',
2008-06-24 21:51:03 +00:00
),
'message' => array(
2008-08-11 17:43:30 +00:00
'type' => 'text',
2008-06-24 21:51:03 +00:00
'not null' => TRUE,
2008-11-15 13:01:11 +00:00
'description' => 'The message itself.',
2008-06-24 21:51:03 +00:00
),
'message_group' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'The message group this message belongs to. For example: warning, browser, user.',
2008-06-24 21:51:03 +00:00
),
2008-09-10 04:13:01 +00:00
'function' => array(
2008-06-24 21:51:03 +00:00
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'Name of the assertion function or method that created this message.',
2008-06-24 21:51:03 +00:00
),
'line' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'Line number on which the function is called.',
2008-06-24 21:51:03 +00:00
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'Name of the file where the function is called.',
2008-06-24 21:51:03 +00:00
),
),
'primary key' => array('message_id'),
'indexes' => array(
2008-08-16 20:57:14 +00:00
'reporter' => array('test_class', 'message_id'),
2008-06-24 21:51:03 +00:00
),
);
$schema['simpletest_test_id'] = array(
2008-11-15 13:01:11 +00:00
'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',
2008-06-24 21:51:03 +00:00
'fields' => array(
2008-08-13 06:42:04 +00:00
'test_id' => array(
2008-06-24 21:51:03 +00:00
'type' => 'serial',
'not null' => TRUE,
2008-11-15 13:01:11 +00:00
'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.',
2008-06-24 21:51:03 +00:00
),
2009-07-07 07:50:53 +00:00
'last_prefix' => array(
'type' => 'varchar',
'length' => 60,
'not null' => FALSE,
'default' => '',
'description' => 'The last database prefix used during testing.',
),
2008-06-24 21:51:03 +00:00
),
2008-08-13 06:42:04 +00:00
'primary key' => array('test_id'),
2008-06-24 21:51:03 +00:00
);
return $schema;
}
2010-11-12 03:06:52 +00:00
/**
* Implements hook_uninstall().
*/
function simpletest_uninstall() {
2011-06-15 04:45:51 +00:00
drupal_load('module', 'simpletest');
simpletest_clean_database();
2010-11-12 03:06:52 +00:00
// Remove generated files.
file_unmanaged_delete_recursive('public://simpletest');
}
2012-09-04 20:20:31 +00:00
/**
* Move simpletest settings from variables to config.
*/
function simpletest_update_8000() {
update_variables_to_config('simpletest.settings', array(
'simpletest_clear_results' => 'clear_results',
'simpletest_httpauth_method' => 'httpauth.method',
'simpletest_httpauth_password' => 'httpauth.password',
'simpletest_httpauth_username' => 'httpauth.username',
'simpletest_verbose' => 'verbose',
));
}