You are here

function simpletest_requirements in SimpleTest 6

Same name and namespace in other branches
  1. 8.3 simpletest.install \simpletest_requirements()
  2. 6.2 simpletest.install \simpletest_requirements()
  3. 7.2 simpletest.install \simpletest_requirements()
  4. 7 simpletest.install \simpletest_requirements()

Implementation of hook_requirements().

File

./simpletest.install, line 18
SimpleTest installation file; ensures presence of SimpleTest library.

Code

function simpletest_requirements($phase) {
  $requirements = array();
  $module_path = drupal_get_path('module', 'simpletest');

  // When installing from a profile, drupal_get_path() doesn't work since
  // the {system} table doesn't exist yet.
  if (empty($module_path)) {
    $module_path = dirname(__FILE__);
  }
  $simpletest_path = $module_path . '/simpletest/simpletest.php';

  // Ensure translations don't break at install time.
  $t = get_t();

  // Check installed SimpleTest library version.
  $simpletest_version = 0;
  if (is_file($simpletest_path)) {
    include_once $simpletest_path;
    $simpletest_version = SimpleTest::getVersion();
  }

  // Check for presence of required version of SimpleTest library.
  $requirements['simpletest'] = array(
    'title' => $t('SimpleTest library'),
    'value' => $simpletest_version > 0 ? $simpletest_version : $t('Not found'),
  );
  $install_link = base_path() . $module_path . '/INSTALL.txt';
  $download_link = 'http://sourceforge.net/project/showfiles.php?group_id=76550&package_id=77275';
  if ($simpletest_version == 0) {
    $requirements['simpletest']['description'] = $t('The SimpleTest library is not installed. You must <a href="@download">download the SimpleTest library</a> and place it your SimpleTest module folder. For more detailed instructions, see <a href="@install">INSTALL.txt</a>.', array(
      '@download' => $download_link,
      '@install' => $install_link,
    ));
    $requirements['simpletest']['severity'] = REQUIREMENT_ERROR;
  }
  elseif (version_compare($simpletest_version, SIMPLETEST_MINIMUM_VERSION) < 0) {
    $requirements['simpletest']['description'] = $t('The SimpleTest module requires at least version %minimum-version of the SimpleTest library. Please <a href="@download">download a more recent SimpleTest library</a>. For more detailed instructions, see <a href="@install">INSTALL.txt</a>.', array(
      '%minimum-version' => SIMPLETEST_MINIMUM_VERSION,
      '@download' => $download_link,
      '@install' => $install_link,
    ));
    $requirements['simpletest']['severity'] = REQUIREMENT_ERROR;
  }
  return $requirements;
}