simpletest.install 5.92 KB
Newer Older
1 2 3
<?php
// $Id$

4 5 6 7 8
/**
 * @file
 * Install, update and uninstall functions for the simpletest module.
 */

9
/**
10
 * Implements hook_uninstall().
11 12
 */
function simpletest_uninstall() {
13 14
  simpletest_clean_environment();

15
  // Remove settings variables.
16 17 18
  variable_del('simpletest_httpauth_method');
  variable_del('simpletest_httpauth_username');
  variable_del('simpletest_httpauth_password');
19
  variable_del('simpletest_clear_results');
20
  variable_del('simpletest_verbose');
21 22

  // Remove generated files.
23
  $path = 'public://simpletest';
24 25
  $files = file_scan_directory($path, '/.*/');
  foreach ($files as $file) {
26
    file_unmanaged_delete($file->uri);
27
  }
28
  drupal_rmdir($path);
29
}
30 31 32 33 34 35 36 37 38

/**
 * Check that the cURL extension exists for PHP.
 */
function simpletest_requirements($phase) {
  $requirements = array();
  $t = get_t();

  $has_curl = function_exists('curl_init');
39
  $has_hash = function_exists('hash_hmac');
40
  $has_domdocument = method_exists('DOMDocument', 'loadHTML');
41
  $open_basedir = ini_get('open_basedir');
42

43 44 45 46 47 48
  $requirements['curl'] = array(
    'title' => $t('cURL'),
    'value' => $has_curl ? $t('Enabled') : $t('Not found'),
  );
  if (!$has_curl) {
    $requirements['curl']['severity'] = REQUIREMENT_ERROR;
49
    $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/en/curl.setup.php'));
50
  }
51 52 53 54 55 56
  $requirements['hash'] = array(
    'title' => $t('hash'),
    'value' => $has_hash ? $t('Enabled') : $t('Not found'),
  );
  if (!$has_hash) {
    $requirements['hash']['severity'] = REQUIREMENT_ERROR;
57
    $requirements['hash']['description'] = $t('The testing framework could not be installed because the PHP <a href="@hash_url">hash</a> extension is disabled.', array('@hash_url' => 'http://php.net/manual/en/book.hash.php'));
58
  }
59 60 61 62 63 64 65

  $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;
66
    $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' => url('admin/reports/status/php')));
67 68
  }

69 70
  // SimpleTest currently needs 2 cURL options which are incompatible with
  // having PHP's open_basedir restriction set.
71
  // See http://drupal.org/node/674304.
72 73 74 75 76 77
  $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;
78
    $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/en/ini.core.php#ini.open-basedir'));
79 80
  }

81 82
  return $requirements;
}
83 84 85

function simpletest_schema() {
  $schema['simpletest'] = array(
86
    'description' => 'Stores simpletest messages',
87 88 89 90
    'fields' => array(
      'message_id'  => array(
        'type' => 'serial',
        'not null' => TRUE,
91
        'description' => 'Primary Key: Unique simpletest message ID.',
92 93 94 95 96
      ),
      'test_id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
97
        'description' => 'Test ID, messages belonging to the same ID are reported together',
98 99 100 101 102 103
      ),
      'test_class' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
104
        'description' => 'The name of the class that created this message.',
105 106 107 108 109 110
      ),
      'status' => array(
        'type' => 'varchar',
        'length' => 9,
        'not null' => TRUE,
        'default' => '',
111
        'description' => 'Message status. Core understands pass, fail, exception.',
112 113
      ),
      'message' => array(
114
        'type' => 'text',
115
        'not null' => TRUE,
116
        'description' => 'The message itself.',
117 118 119 120 121 122
      ),
      'message_group' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
123
        'description' => 'The message group this message belongs to. For example: warning, browser, user.',
124
      ),
125
      'function' => array(
126 127 128 129
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
130
        'description' => 'Name of the assertion function or method that created this message.',
131 132 133 134 135
      ),
      'line' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
136
        'description' => 'Line number on which the function is called.',
137 138 139 140 141 142
      ),
      'file' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
143
        'description' => 'Name of the file where the function is called.',
144 145 146 147
      ),
    ),
    'primary key' => array('message_id'),
    'indexes' => array(
148
      'reporter' => array('test_class', 'message_id'),
149 150 151
    ),
  );
  $schema['simpletest_test_id'] = array(
152
    'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',
153
    'fields' => array(
154
      'test_id'  => array(
155 156
        'type' => 'serial',
        'not null' => TRUE,
157 158
        '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.',
159
      ),
160 161 162 163 164 165 166
      'last_prefix' => array(
        'type' => 'varchar',
        'length' => 60,
        'not null' => FALSE,
        'default' => '',
        'description' => 'The last database prefix used during testing.',
      ),
167
    ),
168
    'primary key' => array('test_id'),
169 170 171
  );
  return $schema;
}