Code coverage for /20080809/modules/simpletest/simpletest.install

Line #Times calledCode
1
<?php
2
// $Id: simpletest.install,v 1.4 2008/06/24 21:51:02 dries Exp $
3
4
/**
5
 * Implementation of hook_install().
6
 */
72
function simpletest_install() {
81
  drupal_install_schema('simpletest');
9
  // Check for files directory.
101
  $path = file_directory_path() . '/simpletest';
111
  if (file_check_directory($path, FILE_CREATE_DIRECTORY)) {
12
    // Generate binary and text test files.
131
    $generated = FALSE;
141
    if (simpletest_get_file_count($path, 'binary') == 0) {
150
      $lines = array(64, 1024);
160
      foreach ($lines as $line) {
170
        simpletest_generate_file('binary', 64, $line, 'binary');
180
      }
190
      $generated = TRUE;
200
    }
21
221
    if (simpletest_get_file_count($path, 'text') == 0) {
230
      $lines = array(16, 256, 1024, 2048, 20480);
240
      foreach ($lines as $line) {
250
        simpletest_generate_file('text', 64, $line);
260
      }
270
      $generated = TRUE;
280
    }
29
30
    // Copy other test files for consistency.
311
    $files = file_scan_directory($path,
'(html|image|javascript|php|sql)-.*');
321
    if (count($files) == 0) {
330
      $original = drupal_get_path('module', 'simpletest') . '/files';
340
      $files = file_scan_directory($original,
'(html|image|javascript|php|sql)-.*');
350
      foreach ($files as $file) {
360
        file_copy($file->filename, $path . '/' . $file->basename);
370
      }
380
      $generated = TRUE;
390
    }
40
411
    if ($generated) {
420
      drupal_set_message('Extra test files generated.');
430
    }
441
  }
451
}
46
47
/**
48
 * Generate test file.
49
 */
502
function simpletest_generate_file($filename, $width, $lines, $type =
'binary-text') {
510
  $size = $width * $lines - $lines;
52
53
  // Generate random text
540
  $text = '';
550
  for ($i = 0; $i < $size; $i++) {
56
    switch ($type) {
570
      case 'text':
580
        $text .= chr(rand(32, 126));
590
        break;
600
      case 'binary':
610
        $text .= chr(rand(0, 31));
620
        break;
630
      case 'binary-text':
640
      default:
650
        $text .= rand(0, 1);
660
        break;
670
    }
680
  }
690
  $text = wordwrap($text, $width - 1, "\n", TRUE) ."\n"; // Add \n for
symetrical file.
70
71
  // Create filename.
720
  $path = file_directory_path() . '/simpletest/';
730
  $count = simpletest_get_file_count($path, $filename);
740
  file_put_contents($path . $filename . '-' . ($count + 1) . '.txt',
$text);
750
}
76
77
/**
78
 * Get the number of files that have the specified filename base.
79
 */
802
function simpletest_get_file_count($directory, $filename) {
811
  $files = scandir($directory);
821
  $count = 0;
831
  foreach ($files as $file) {
841
    if (preg_match('/' . $filename . '.*?/', $file)) {
851
      $count++;
861
    }
871
  }
881
  return $count;
890
}
90
91
/**
92
 * Implementation of hook_uninstall().
93
 */
942
function simpletest_uninstall() {
950
  variable_del('simpletest_httpauth');
960
  variable_del('simpletest_httpauth_username');
970
  variable_del('simpletest_httpauth_pass');
980
  variable_del('simpletest_devel');
990
  drupal_uninstall_schema('simpletest');
1000
}
101
102
/**
103
 * Check that the cURL extension exists for PHP.
104
 */
1052
function simpletest_requirements($phase) {
1060
  $requirements = array();
1070
  $t = get_t();
108
1090
  $has_curl = function_exists('curl_init');
110
111
  switch ($phase) {
1120
    case 'runtime':
1130
      $requirements['simpletest'] = array(
1140
        'title' => $t('cURL'),
1150
        'value' => $has_curl ? $t('Enabled') : $t('Not found'),
1160
        'severity' => $has_curl ? REQUIREMENT_OK : REQUIREMENT_ERROR,
117
      );
1180
      break;
1190
    case 'install':
1200
      if ($has_curl) {
1210
        $requirements['simpletest'] = array(
1220
          'title' => $t('cURL'),
1230
          'severity' => REQUIREMENT_OK,
124
        );
1250
      }
126
      else {
1270
        $requirements['simpletest'] = array(
1280
          'title' => $t('cURL'),
1290
          'severity' => REQUIREMENT_ERROR,
1300
          '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')),
131
        );
132
      }
1330
      break;
1340
  }
135
1360
  return $requirements;
1370
}
138
1392
function simpletest_schema() {
1402
  $schema['simpletest'] = array(
1412
    'description' => t('Stores simpletest messages'),
142
    'fields' => array(
143
      'message_id'  => array(
1442
        'type' => 'serial',
1452
        'not null' => TRUE,
1462
        'description' => t('Primary Key: Unique simpletest message ID.'),
1472
      ),
148
      'test_id' => array(
1492
        'type' => 'int',
1502
        'not null' => TRUE,
1512
        'default' => 0,
1522
        'description' => t('Test id, messages belonging to the same id are
reported together'),
1532
      ),
154
      'test_class' => array(
1552
        'type' => 'varchar',
1562
        'length' => 255,
1572
        'not null' => TRUE,
1582
        'default' => '',
1592
        'description' => t('The name of the class that created this
message.'),
1602
      ),
161
      'status' => array(
1622
        'type' => 'varchar',
1632
        'length' => 9,
1642
        'not null' => TRUE,
1652
        'default' => '',
1662
        'description' => t('Message status. Core understands pass, fail,
exception.'),
1672
      ),
168
      'message' => array(
1692
        'type' => 'varchar',
1702
        'length' => 255,
1712
        'not null' => TRUE,
1722
        'default' => '',
1732
        'description' => t('The message itself.'),
1742
      ),
175
      'message_group' => array(
1762
        'type' => 'varchar',
1772
        'length' => 255,
1782
        'not null' => TRUE,
1792
        'default' => '',
1802
        'description' => t('The message group this message belongs to. For
example: warning, browser, user.'),
1812
      ),
182
      'caller' => array(
1832
        'type' => 'varchar',
1842
        'length' => 255,
1852
        'not null' => TRUE,
1862
        'default' => '',
1872
        'description' => t('Name of the caller function or method that
created this message.'),
1882
      ),
189
      'line' => array(
1902
        'type' => 'int',
1912
        'not null' => TRUE,
1922
        'default' => 0,
1932
        'description' => t('Line number of the caller.'),
1942
      ),
195
      'file' => array(
1962
        'type' => 'varchar',
1972
        'length' => 255,
1982
        'not null' => TRUE,
1992
        'default' => '',
2002
        'description' => t('Name of the file where the caller is.'),
2012
      ),
2022
    ),
2032
    'primary key' => array('message_id'),
204
    'indexes' => array(
2052
      'reporter' => array('test_class, message_id'),
2062
    ),
207
  );
2082
  $schema['simpletest_test_id'] = array(
2092
    'description' => t('Stores simpletest test IDs.'),
210
    'fields' => array(
211
      'message_id'  => array(
2122
        'type' => 'serial',
2132
        'not null' => TRUE,
2142
        'description' => t('Primary Key: Unique simpletest ID.'),
2152
      ),
2162
    ),
2172
    'primary key' => array('message_id'),
218
  );
2192
  return $schema;
2200
}
221
222
/**
223
 * Create the simpletest tables.
224
 */
2252
function simpletest_update_7000() {
2260
  $ret = array();
2270
  $schema = array();
228
2290
  $schema['simpletest'] = array(
230
    'fields' => array(
2310
      'message_id'  => array('type' => 'serial', 'not null' => TRUE),
2320
      'test_id' => array('type' => 'int', 'not null' => TRUE, 'default' =>
0),
2330
      'test_class' => array('type' => 'varchar', 'length' => 255, 'not
null' => TRUE, 'default' => ''),
2340
      'status' => array('type' => 'varchar', 'length' => 9, 'not null' =>
TRUE, 'default' => ''),
2350
      'message' => array('type' => 'varchar', 'length' => 255, 'not null'
=> TRUE, 'default' => ''),
2360
      'message_group' => array('type' => 'varchar', 'length' => 255, 'not
null' => TRUE, 'default' => ''),
2370
      'caller' => array('type' => 'varchar', 'length' => 255, 'not null' =>
TRUE, 'default' => ''),
2380
      'line' => array('type' => 'int', 'not null' => TRUE, 'default' =>
0),
2390
      'file' => array('type' => 'varchar', 'length' => 255, 'not null' =>
TRUE, 'default' => ''),
2400
    ),
2410
    'primary key' => array('message_id'),
242
    'indexes' => array(
2430
      'reporter' => array('test_class, message_id'),
2440
    ),
245
  );
246
2470
  $schema['simpletest_test_id'] = array(
248
    'fields' => array(
2490
      'message_id'  => array('type' => 'serial', 'not null' => TRUE),
2500
    ),
2510
    'primary key' => array('message_id'),
252
  );
253
2540
  foreach ($schema as $name => $definition) {
2550
    db_create_table($ret, $name, $definition);
2560
  }
257
2580
  return $ret;
2592
}