This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/core/modules/simpletest/simpletest.install

194 lines
7.2 KiB
Plaintext
Raw Normal View History

<?php
/**
* @file
* Install, update and uninstall functions for the simpletest module.
*/
use Drupal\Component\Utility\Environment;
2018-11-23 12:29:20 +00:00
use PHPUnit\Framework\TestCase;
/**
* Minimum value of PHP memory_limit for SimpleTest.
*/
const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '128M';
/**
* Implements hook_requirements().
*/
function simpletest_requirements($phase) {
2017-04-13 14:53:35 +00:00
$requirements = [];
2018-11-23 12:29:20 +00:00
$has_phpunit = class_exists(TestCase::class);
$has_curl = function_exists('curl_init');
$open_basedir = ini_get('open_basedir');
2017-04-13 14:53:35 +00:00
$requirements['phpunit'] = [
'title' => t('PHPUnit dependency'),
'value' => $has_phpunit ? t('Found') : t('Not found'),
2017-04-13 14:53:35 +00:00
];
if (!$has_phpunit) {
$requirements['phpunit']['severity'] = REQUIREMENT_ERROR;
2018-11-23 12:29:20 +00:00
$requirements['phpunit']['description'] = t("The testing framework requires the PHPUnit package. Please run 'composer install' to ensure it is present.");
}
2017-04-13 14:53:35 +00:00
$requirements['curl'] = [
'title' => t('cURL'),
'value' => $has_curl ? t('Enabled') : t('Not found'),
2017-04-13 14:53:35 +00:00
];
if (!$has_curl) {
$requirements['curl']['severity'] = REQUIREMENT_ERROR;
2017-04-13 14:53:35 +00:00
$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>.');
}
// SimpleTest currently needs 2 cURL options which are incompatible with
// having PHP's open_basedir restriction set.
// See https://www.drupal.org/node/674304.
2017-04-13 14:53:35 +00:00
$requirements['php_open_basedir'] = [
'title' => t('PHP open_basedir restriction'),
'value' => $open_basedir ? t('Enabled') : t('Disabled'),
2017-04-13 14:53:35 +00:00
];
if ($open_basedir) {
$requirements['php_open_basedir']['severity'] = REQUIREMENT_ERROR;
$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.');
}
// 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');
if (!Environment::checkMemoryLimit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
$requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
2017-04-13 14:53:35 +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>.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, ':url' => 'https://www.drupal.org/node/207036']);
}
$site_directory = 'sites/simpletest';
if (!drupal_verify_install_file(\Drupal::root() . '/' . $site_directory, FILE_EXIST | FILE_READABLE | FILE_WRITABLE | FILE_EXECUTABLE, 'dir')) {
2017-04-13 14:53:35 +00:00
$requirements['simpletest_site_directory'] = [
'title' => t('Simpletest site directory'),
'value' => is_dir(\Drupal::root() . '/' . $site_directory) ? t('Not writable') : t('Missing'),
'severity' => REQUIREMENT_ERROR,
2017-04-13 14:53:35 +00:00
'description' => t('The testing framework requires the %sites-simpletest directory to exist and be writable in order to run tests.', [
'%sites-simpletest' => $site_directory,
2017-04-13 14:53:35 +00:00
]),
];
}
elseif (!file_save_htaccess(\Drupal::root() . '/' . $site_directory, FALSE)) {
2017-04-13 14:53:35 +00:00
$requirements['simpletest_site_directory'] = [
'title' => t('Simpletest site directory'),
'value' => t('Not protected'),
'severity' => REQUIREMENT_ERROR,
2017-04-13 14:53:35 +00:00
'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.', [
'%file' => $site_directory . '/.htaccess',
2017-04-13 14:53:35 +00:00
]),
];
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function simpletest_schema() {
2017-04-13 14:53:35 +00:00
$schema['simpletest'] = [
'description' => 'Stores simpletest messages',
2017-04-13 14:53:35 +00:00
'fields' => [
'message_id' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique simpletest message ID.',
2017-04-13 14:53:35 +00:00
],
'test_id' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Test ID, messages belonging to the same ID are reported together',
2017-04-13 14:53:35 +00:00
],
'test_class' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The name of the class that created this message.',
2017-04-13 14:53:35 +00:00
],
'status' => [
'type' => 'varchar',
'length' => 9,
'not null' => TRUE,
'default' => '',
'description' => 'Message status. Core understands pass, fail, exception.',
2017-04-13 14:53:35 +00:00
],
'message' => [
'type' => 'text',
'not null' => TRUE,
'description' => 'The message itself.',
2017-04-13 14:53:35 +00:00
],
'message_group' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The message group this message belongs to. For example: warning, browser, user.',
2017-04-13 14:53:35 +00:00
],
'function' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the assertion function or method that created this message.',
2017-04-13 14:53:35 +00:00
],
'line' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Line number on which the function is called.',
2017-04-13 14:53:35 +00:00
],
'file' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the file where the function is called.',
2017-04-13 14:53:35 +00:00
],
],
'primary key' => ['message_id'],
'indexes' => [
'reporter' => ['test_class', 'message_id'],
],
];
$schema['simpletest_test_id'] = [
'description' => 'Stores simpletest test IDs, used to auto-increment the test ID so that a fresh test ID is used.',
2017-04-13 14:53:35 +00:00
'fields' => [
'test_id' => [
'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.',
2017-04-13 14:53:35 +00:00
],
'last_prefix' => [
'type' => 'varchar',
'length' => 60,
'not null' => FALSE,
'default' => '',
'description' => 'The last database prefix used during testing.',
2017-04-13 14:53:35 +00:00
],
],
'primary key' => ['test_id'],
];
return $schema;
}
/**
* Implements hook_uninstall().
*/
function simpletest_uninstall() {
// Do not clean the environment in case the Simpletest module is uninstalled
// in a (recursive) test for itself, since simpletest_clean_environment()
// would also delete the test site of the parent test process.
if (!drupal_valid_test_ua()) {
simpletest_clean_environment();
}
// Delete verbose test output and any other testing framework files.
file_unmanaged_delete_recursive('public://simpletest');
}