5 * Install, update and uninstall functions for the simpletest module.
8 use Drupal\Component\Utility\Environment;
11 * Minimum value of PHP memory_limit for SimpleTest.
13 const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '128M';
16 * Implements hook_requirements().
18 function simpletest_requirements($phase) {
21 $has_phpunit = class_exists('\PHPUnit_Framework_TestCase');
22 $has_curl = function_exists('curl_init');
23 $open_basedir = ini_get('open_basedir');
25 $requirements['phpunit'] = [
26 'title' => t('PHPUnit dependency'),
27 'value' => $has_phpunit ? t('Found') : t('Not found'),
30 $requirements['phpunit']['severity'] = REQUIREMENT_ERROR;
31 $requirements['phpunit']['description'] = t("The testing framework requires the PHPUnit package. Please run 'composer install --dev' to ensure it is present.");
34 $requirements['curl'] = [
36 'value' => $has_curl ? t('Enabled') : t('Not found'),
39 $requirements['curl']['severity'] = REQUIREMENT_ERROR;
40 $requirements['curl']['description'] = t('The testing framework requires the <a href="https://secure.php.net/manual/en/curl.setup.php">PHP cURL library</a>. For more information, see the <a href="https://www.drupal.org/requirements/php/curl">online information on installing the PHP cURL extension</a>.');
43 // SimpleTest currently needs 2 cURL options which are incompatible with
44 // having PHP's open_basedir restriction set.
45 // See https://www.drupal.org/node/674304.
46 $requirements['php_open_basedir'] = [
47 'title' => t('PHP open_basedir restriction'),
48 'value' => $open_basedir ? t('Enabled') : t('Disabled'),
51 $requirements['php_open_basedir']['severity'] = REQUIREMENT_ERROR;
52 $requirements['php_open_basedir']['description'] = t('The testing framework requires the PHP <a href="http://php.net/manual/ini.core.php#ini.open-basedir">open_basedir</a> restriction to be disabled. Check your webserver configuration or contact your web host.');
55 // Check the current memory limit. If it is set too low, SimpleTest will fail
56 // to load all tests and throw a fatal error.
57 $memory_limit = ini_get('memory_limit');
58 if (!Environment::checkMemoryLimit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
59 $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
60 $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>.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, ':url' => 'https://www.drupal.org/node/207036']);
63 $site_directory = 'sites/simpletest';
64 if (!drupal_verify_install_file(\Drupal::root() . '/' . $site_directory, FILE_EXIST | FILE_READABLE | FILE_WRITABLE | FILE_EXECUTABLE, 'dir')) {
65 $requirements['simpletest_site_directory'] = [
66 'title' => t('Simpletest site directory'),
67 'value' => is_dir(\Drupal::root() . '/' . $site_directory) ? t('Not writable') : t('Missing'),
68 'severity' => REQUIREMENT_ERROR,
69 'description' => t('The testing framework requires the %sites-simpletest directory to exist and be writable in order to run tests.', [
70 '%sites-simpletest' => $site_directory,
74 elseif (!file_save_htaccess(\Drupal::root() . '/' . $site_directory, FALSE)) {
75 $requirements['simpletest_site_directory'] = [
76 'title' => t('Simpletest site directory'),
77 'value' => t('Not protected'),
78 'severity' => REQUIREMENT_ERROR,
79 'description' => t('The file %file does not exist and could not be created automatically, which poses a security risk. Ensure that the directory is writable.', [
80 '%file' => $site_directory . '/.htaccess',
89 * Implements hook_schema().
91 function simpletest_schema() {
92 $schema['simpletest'] = [
93 'description' => 'Stores simpletest messages',
98 'description' => 'Primary Key: Unique simpletest message ID.',
104 'description' => 'Test ID, messages belonging to the same ID are reported together',
107 'type' => 'varchar_ascii',
111 'description' => 'The name of the class that created this message.',
118 'description' => 'Message status. Core understands pass, fail, exception.',
123 'description' => 'The message itself.',
126 'type' => 'varchar_ascii',
130 'description' => 'The message group this message belongs to. For example: warning, browser, user.',
133 'type' => 'varchar_ascii',
137 'description' => 'Name of the assertion function or method that created this message.',
143 'description' => 'Line number on which the function is called.',
150 'description' => 'Name of the file where the function is called.',
153 'primary key' => ['message_id'],
155 'reporter' => ['test_class', 'message_id'],
158 $schema['simpletest_test_id'] = [
159 'description' => 'Stores simpletest test IDs, used to auto-increment the test ID so that a fresh test ID is used.',
164 'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
165 are run a new test ID is used.',
172 'description' => 'The last database prefix used during testing.',
175 'primary key' => ['test_id'],
181 * Implements hook_uninstall().
183 function simpletest_uninstall() {
184 // Do not clean the environment in case the Simpletest module is uninstalled
185 // in a (recursive) test for itself, since simpletest_clean_environment()
186 // would also delete the test site of the parent test process.
187 if (!drupal_valid_test_ua()) {
188 simpletest_clean_environment();
190 // Delete verbose test output and any other testing framework files.
191 file_unmanaged_delete_recursive('public://simpletest');