5 * Install, update and uninstall functions for the simpletest module.
8 use Drupal\Component\Utility\Environment;
9 use PHPUnit\Framework\TestCase;
12 * Minimum value of PHP memory_limit for SimpleTest.
14 const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '128M';
17 * Implements hook_requirements().
19 function simpletest_requirements($phase) {
22 $has_phpunit = class_exists(TestCase::class);
23 $has_curl = function_exists('curl_init');
24 $open_basedir = ini_get('open_basedir');
26 $requirements['phpunit'] = [
27 'title' => t('PHPUnit dependency'),
28 'value' => $has_phpunit ? t('Found') : t('Not found'),
31 $requirements['phpunit']['severity'] = REQUIREMENT_ERROR;
32 $requirements['phpunit']['description'] = t("The testing framework requires the PHPUnit package. Please run 'composer install --dev' to ensure it is present.");
35 $requirements['curl'] = [
37 'value' => $has_curl ? t('Enabled') : t('Not found'),
40 $requirements['curl']['severity'] = REQUIREMENT_ERROR;
41 $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>.');
44 // SimpleTest currently needs 2 cURL options which are incompatible with
45 // having PHP's open_basedir restriction set.
46 // See https://www.drupal.org/node/674304.
47 $requirements['php_open_basedir'] = [
48 'title' => t('PHP open_basedir restriction'),
49 'value' => $open_basedir ? t('Enabled') : t('Disabled'),
52 $requirements['php_open_basedir']['severity'] = REQUIREMENT_ERROR;
53 $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.');
56 // Check the current memory limit. If it is set too low, SimpleTest will fail
57 // to load all tests and throw a fatal error.
58 $memory_limit = ini_get('memory_limit');
59 if (!Environment::checkMemoryLimit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
60 $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
61 $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']);
64 $site_directory = 'sites/simpletest';
65 if (!drupal_verify_install_file(\Drupal::root() . '/' . $site_directory, FILE_EXIST | FILE_READABLE | FILE_WRITABLE | FILE_EXECUTABLE, 'dir')) {
66 $requirements['simpletest_site_directory'] = [
67 'title' => t('Simpletest site directory'),
68 'value' => is_dir(\Drupal::root() . '/' . $site_directory) ? t('Not writable') : t('Missing'),
69 'severity' => REQUIREMENT_ERROR,
70 'description' => t('The testing framework requires the %sites-simpletest directory to exist and be writable in order to run tests.', [
71 '%sites-simpletest' => $site_directory,
75 elseif (!file_save_htaccess(\Drupal::root() . '/' . $site_directory, FALSE)) {
76 $requirements['simpletest_site_directory'] = [
77 'title' => t('Simpletest site directory'),
78 'value' => t('Not protected'),
79 'severity' => REQUIREMENT_ERROR,
80 '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.', [
81 '%file' => $site_directory . '/.htaccess',
90 * Implements hook_schema().
92 function simpletest_schema() {
93 $schema['simpletest'] = [
94 'description' => 'Stores simpletest messages',
99 'description' => 'Primary Key: Unique simpletest message ID.',
105 'description' => 'Test ID, messages belonging to the same ID are reported together',
108 'type' => 'varchar_ascii',
112 'description' => 'The name of the class that created this message.',
119 'description' => 'Message status. Core understands pass, fail, exception.',
124 'description' => 'The message itself.',
127 'type' => 'varchar_ascii',
131 'description' => 'The message group this message belongs to. For example: warning, browser, user.',
134 'type' => 'varchar_ascii',
138 'description' => 'Name of the assertion function or method that created this message.',
144 'description' => 'Line number on which the function is called.',
151 'description' => 'Name of the file where the function is called.',
154 'primary key' => ['message_id'],
156 'reporter' => ['test_class', 'message_id'],
159 $schema['simpletest_test_id'] = [
160 'description' => 'Stores simpletest test IDs, used to auto-increment the test ID so that a fresh test ID is used.',
165 'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
166 are run a new test ID is used.',
173 'description' => 'The last database prefix used during testing.',
176 'primary key' => ['test_id'],
182 * Implements hook_uninstall().
184 function simpletest_uninstall() {
185 // Do not clean the environment in case the Simpletest module is uninstalled
186 // in a (recursive) test for itself, since simpletest_clean_environment()
187 // would also delete the test site of the parent test process.
188 if (!drupal_valid_test_ua()) {
189 simpletest_clean_environment();
191 // Delete verbose test output and any other testing framework files.
192 file_unmanaged_delete_recursive('public://simpletest');