summaryrefslogtreecommitdiff
path: root/modules/simpletest/simpletest.install
blob: 31827d9e905a23dd6f5e3e4f4a8c46cefdb66e3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
// $Id$

/**
 * @file
 * Install, update and uninstall functions for the simpletest module.
 */

/**
 * Implements hook_uninstall().
 */
function simpletest_uninstall() {
  simpletest_clean_environment();

  // Remove settings variables.
  variable_del('simpletest_httpauth_method');
  variable_del('simpletest_httpauth_username');
  variable_del('simpletest_httpauth_password');
  variable_del('simpletest_clear_results');
  variable_del('simpletest_verbose');

  // Remove generated files.
  $path = file_directory_path() . '/simpletest';
  $files = file_scan_directory($path, '/.*/');
  foreach ($files as $file) {
    file_unmanaged_delete($file->uri);
  }
  rmdir($path);
}

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

  $has_curl = function_exists('curl_init');
  $has_hash = function_exists('hash_hmac');
  $has_domdocument = class_exists('DOMDocument');
  $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('Simpletest 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'));
  }
  $requirements['hash'] = array(
    'title' => $t('hash'),
    'value' => $has_hash ? $t('Enabled') : $t('Not found'),
  );
  if (!$has_hash) {
    $requirements['hash']['severity'] = REQUIREMENT_ERROR;
    $requirements['hash']['description'] = $t('Simpletest 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'));
  }

  $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('SimpleTest requires the DOMDocument class to be available. Please check the configure command at the <a href="@link-phpinfo">PHP info page</a>.', array('@link-phpinfo' => url('admin/reports/status/php')));
  }

  // SimpleTest currently needs 2 cURL options which are incompatible with
  // having PHP's open_basedir restriction set.
  // @see http://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. Please check your webserver configuration or contact your web host.', array('@open_basedir-url' => 'http://php.net/manual/en/ini.core.php#ini.open-basedir'));
  }

  return $requirements;
}

function simpletest_schema() {
  $schema['simpletest'] = array(
    'description' => 'Stores simpletest messages',
    'fields' => array(
      'message_id'  => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique simpletest message ID.',
      ),
      'test_id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Test ID, messages belonging to the same ID are reported together',
      ),
      'test_class' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The name of the class that created this message.',
      ),
      'status' => array(
        'type' => 'varchar',
        'length' => 9,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Message status. Core understands pass, fail, exception.',
      ),
      'message' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'The message itself.',
      ),
      'message_group' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The message group this message belongs to. For example: warning, browser, user.',
      ),
      'function' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Name of the assertion function or method that created this message.',
      ),
      'line' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Line number on which the function is called.',
      ),
      'file' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Name of the file where the function is called.',
      ),
    ),
    'primary key' => array('message_id'),
    'indexes' => array(
      'reporter' => array('test_class', 'message_id'),
    ),
  );
  $schema['simpletest_test_id'] = array(
    'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',
    'fields' => array(
      'test_id'  => array(
        '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.',
      ),
      'last_prefix' => array(
        'type' => 'varchar',
        'length' => 60,
        'not null' => FALSE,
        'default' => '',
        'description' => 'The last database prefix used during testing.',
      ),
    ),
    'primary key' => array('test_id'),
  );
  return $schema;
}