Chris@0: t('PHPUnit dependency'),
Chris@0: 'value' => $has_phpunit ? t('Found') : t('Not found'),
Chris@0: ];
Chris@0: if (!$has_phpunit) {
Chris@0: $requirements['phpunit']['severity'] = REQUIREMENT_ERROR;
Chris@16: $requirements['phpunit']['description'] = t("The testing framework requires the PHPUnit package. Please run 'composer install' to ensure it is present.");
Chris@0: }
Chris@0:
Chris@0: $requirements['curl'] = [
Chris@0: 'title' => t('cURL'),
Chris@0: 'value' => $has_curl ? t('Enabled') : t('Not found'),
Chris@0: ];
Chris@0: if (!$has_curl) {
Chris@0: $requirements['curl']['severity'] = REQUIREMENT_ERROR;
Chris@0: $requirements['curl']['description'] = t('The testing framework requires the PHP cURL library. For more information, see the online information on installing the PHP cURL extension.');
Chris@0: }
Chris@0:
Chris@0: // SimpleTest currently needs 2 cURL options which are incompatible with
Chris@0: // having PHP's open_basedir restriction set.
Chris@0: // See https://www.drupal.org/node/674304.
Chris@0: $requirements['php_open_basedir'] = [
Chris@0: 'title' => t('PHP open_basedir restriction'),
Chris@0: 'value' => $open_basedir ? t('Enabled') : t('Disabled'),
Chris@0: ];
Chris@0: if ($open_basedir) {
Chris@0: $requirements['php_open_basedir']['severity'] = REQUIREMENT_ERROR;
Chris@0: $requirements['php_open_basedir']['description'] = t('The testing framework requires the PHP open_basedir restriction to be disabled. Check your webserver configuration or contact your web host.');
Chris@0: }
Chris@0:
Chris@0: // Check the current memory limit. If it is set too low, SimpleTest will fail
Chris@0: // to load all tests and throw a fatal error.
Chris@0: $memory_limit = ini_get('memory_limit');
Chris@0: if (!Environment::checkMemoryLimit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
Chris@0: $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
Chris@0: $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. Follow these steps to continue.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, ':url' => 'https://www.drupal.org/node/207036']);
Chris@0: }
Chris@0:
Chris@0: $site_directory = 'sites/simpletest';
Chris@0: if (!drupal_verify_install_file(\Drupal::root() . '/' . $site_directory, FILE_EXIST | FILE_READABLE | FILE_WRITABLE | FILE_EXECUTABLE, 'dir')) {
Chris@0: $requirements['simpletest_site_directory'] = [
Chris@0: 'title' => t('Simpletest site directory'),
Chris@0: 'value' => is_dir(\Drupal::root() . '/' . $site_directory) ? t('Not writable') : t('Missing'),
Chris@0: 'severity' => REQUIREMENT_ERROR,
Chris@0: 'description' => t('The testing framework requires the %sites-simpletest directory to exist and be writable in order to run tests.', [
Chris@0: '%sites-simpletest' => $site_directory,
Chris@0: ]),
Chris@0: ];
Chris@0: }
Chris@0: elseif (!file_save_htaccess(\Drupal::root() . '/' . $site_directory, FALSE)) {
Chris@0: $requirements['simpletest_site_directory'] = [
Chris@0: 'title' => t('Simpletest site directory'),
Chris@0: 'value' => t('Not protected'),
Chris@0: 'severity' => REQUIREMENT_ERROR,
Chris@0: '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.', [
Chris@0: '%file' => $site_directory . '/.htaccess',
Chris@0: ]),
Chris@0: ];
Chris@0: }
Chris@0:
Chris@0: return $requirements;
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Implements hook_schema().
Chris@0: */
Chris@0: function simpletest_schema() {
Chris@0: $schema['simpletest'] = [
Chris@0: 'description' => 'Stores simpletest messages',
Chris@0: 'fields' => [
Chris@0: 'message_id' => [
Chris@0: 'type' => 'serial',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'Primary Key: Unique simpletest message ID.',
Chris@0: ],
Chris@0: 'test_id' => [
Chris@0: 'type' => 'int',
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => 0,
Chris@0: 'description' => 'Test ID, messages belonging to the same ID are reported together',
Chris@0: ],
Chris@0: 'test_class' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'The name of the class that created this message.',
Chris@0: ],
Chris@0: 'status' => [
Chris@0: 'type' => 'varchar',
Chris@0: 'length' => 9,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Message status. Core understands pass, fail, exception.',
Chris@0: ],
Chris@0: 'message' => [
Chris@0: 'type' => 'text',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'The message itself.',
Chris@0: ],
Chris@0: 'message_group' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'The message group this message belongs to. For example: warning, browser, user.',
Chris@0: ],
Chris@0: 'function' => [
Chris@0: 'type' => 'varchar_ascii',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Name of the assertion function or method that created this message.',
Chris@0: ],
Chris@0: 'line' => [
Chris@0: 'type' => 'int',
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => 0,
Chris@0: 'description' => 'Line number on which the function is called.',
Chris@0: ],
Chris@0: 'file' => [
Chris@0: 'type' => 'varchar',
Chris@0: 'length' => 255,
Chris@0: 'not null' => TRUE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'Name of the file where the function is called.',
Chris@0: ],
Chris@0: ],
Chris@0: 'primary key' => ['message_id'],
Chris@0: 'indexes' => [
Chris@0: 'reporter' => ['test_class', 'message_id'],
Chris@0: ],
Chris@0: ];
Chris@0: $schema['simpletest_test_id'] = [
Chris@0: 'description' => 'Stores simpletest test IDs, used to auto-increment the test ID so that a fresh test ID is used.',
Chris@0: 'fields' => [
Chris@0: 'test_id' => [
Chris@0: 'type' => 'serial',
Chris@0: 'not null' => TRUE,
Chris@0: 'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests
Chris@0: are run a new test ID is used.',
Chris@0: ],
Chris@0: 'last_prefix' => [
Chris@0: 'type' => 'varchar',
Chris@0: 'length' => 60,
Chris@0: 'not null' => FALSE,
Chris@0: 'default' => '',
Chris@0: 'description' => 'The last database prefix used during testing.',
Chris@0: ],
Chris@0: ],
Chris@0: 'primary key' => ['test_id'],
Chris@0: ];
Chris@0: return $schema;
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Implements hook_uninstall().
Chris@0: */
Chris@0: function simpletest_uninstall() {
Chris@0: // Do not clean the environment in case the Simpletest module is uninstalled
Chris@0: // in a (recursive) test for itself, since simpletest_clean_environment()
Chris@0: // would also delete the test site of the parent test process.
Chris@0: if (!drupal_valid_test_ua()) {
Chris@0: simpletest_clean_environment();
Chris@0: }
Chris@0: // Delete verbose test output and any other testing framework files.
Chris@18: try {
Chris@18: \Drupal::service('file_system')->deleteRecursive('public://simpletest');
Chris@18: }
Chris@18: catch (FileException $e) {
Chris@18: // Ignore.
Chris@18: }
Chris@18:
Chris@0: }