You are here

function simpletest_requirements in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/simpletest.install \simpletest_requirements()

Implements hook_requirements().

File

core/modules/simpletest/simpletest.install, line 18
Install, update and uninstall functions for the simpletest module.

Code

function simpletest_requirements($phase) {
  $requirements = array();
  $has_curl = function_exists('curl_init');
  $has_domdocument = method_exists('DOMDocument', 'loadHTML');
  $open_basedir = ini_get('open_basedir');
  $requirements['curl'] = array(
    'title' => t('cURL'),
    'value' => $has_curl ? t('Enabled') : t('Not found'),
  );
  if (!$has_curl) {
    $requirements['curl']['severity'] = REQUIREMENT_ERROR;
    $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',
    ));
  }
  $requirements['php_domdocument'] = array(
    'title' => t('PHP DOMDocument class'),
    'value' => $has_domdocument ? t('Enabled') : t('Not found'),
  );
  if (!$has_domdocument) {
    $requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;
    $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' => \Drupal::url('system.php'),
    ));
  }

  // SimpleTest currently needs 2 cURL options which are incompatible with
  // having PHP's open_basedir restriction set.
  // See https://www.drupal.org/node/674304.
  $requirements['php_open_basedir'] = array(
    'title' => t('PHP open_basedir restriction'),
    'value' => $open_basedir ? t('Enabled') : t('Disabled'),
  );
  if ($open_basedir) {
    $requirements['php_open_basedir']['severity'] = REQUIREMENT_ERROR;
    $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',
    ));
  }

  // 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;
    $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' => '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')) {
    $requirements['simpletest_site_directory'] = array(
      'title' => t('Simpletest site directory'),
      'value' => is_dir(\Drupal::root() . '/' . $site_directory) ? t('Not writable') : t('Missing'),
      'severity' => REQUIREMENT_ERROR,
      'description' => t('The testing framework requires the %sites-simpletest directory to exist and be writable in order to run tests.', array(
        '%sites-simpletest' => $site_directory,
      )),
    );
  }
  elseif (!file_save_htaccess(\Drupal::root() . '/' . $site_directory, FALSE)) {
    $requirements['simpletest_site_directory'] = array(
      'title' => t('Simpletest site directory'),
      'value' => t('Not protected'),
      'severity' => REQUIREMENT_ERROR,
      '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.', array(
        '%file' => $site_directory . '/.htaccess',
      )),
    );
  }
  return $requirements;
}