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

Line #Times calledCode
1
<?php
2
// $Id: simpletest.install,v 1.11 2008/10/09 00:02:29 webchick Exp $
3
4
/**
5
 * Implementation of hook_install().
6
 */
71
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_unmanaged_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
 */
501
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
 */
801
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
 */
941
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
 */
1051
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_ERROR,
1240
          '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')),
125
        );
1260
      }
1270
      break;
1280
  }
129
1300
  return $requirements;
1310
}
132
1331
function simpletest_schema() {
1341
  $schema['simpletest'] = array(
1351
    'description' => t('Stores simpletest messages'),
136
    'fields' => array(
137
      'message_id'  => array(
1381
        'type' => 'serial',
1391
        'not null' => TRUE,
1401
        'description' => t('Primary Key: Unique simpletest message ID.'),
1411
      ),
142
      'test_id' => array(
1431
        'type' => 'int',
1441
        'not null' => TRUE,
1451
        'default' => 0,
1461
        'description' => t('Test ID, messages belonging to the same ID are
reported together'),
1471
      ),
148
      'test_class' => array(
1491
        'type' => 'varchar',
1501
        'length' => 255,
1511
        'not null' => TRUE,
1521
        'default' => '',
1531
        'description' => t('The name of the class that created this
message.'),
1541
      ),
155
      'status' => array(
1561
        'type' => 'varchar',
1571
        'length' => 9,
1581
        'not null' => TRUE,
1591
        'default' => '',
1601
        'description' => t('Message status. Core understands pass, fail,
exception.'),
1611
      ),
162
      'message' => array(
1631
        'type' => 'text',
1641
        'not null' => TRUE,
1651
        'description' => t('The message itself.'),
1661
      ),
167
      'message_group' => array(
1681
        'type' => 'varchar',
1691
        'length' => 255,
1701
        'not null' => TRUE,
1711
        'default' => '',
1721
        'description' => t('The message group this message belongs to. For
example: warning, browser, user.'),
1731
      ),
174
      'function' => array(
1751
        'type' => 'varchar',
1761
        'length' => 255,
1771
        'not null' => TRUE,
1781
        'default' => '',
1791
        'description' => t('Name of the assertion function or method that
created this message.'),
1801
      ),
181
      'line' => array(
1821
        'type' => 'int',
1831
        'not null' => TRUE,
1841
        'default' => 0,
1851
        'description' => t('Line number on which the function is called.'),
1861
      ),
187
      'file' => array(
1881
        'type' => 'varchar',
1891
        'length' => 255,
1901
        'not null' => TRUE,
1911
        'default' => '',
1921
        'description' => t('Name of the file where the function is
called.'),
1931
      ),
1941
    ),
1951
    'primary key' => array('message_id'),
196
    'indexes' => array(
1971
      'reporter' => array('test_class', 'message_id'),
1981
    ),
199
  );
2001
  $schema['simpletest_test_id'] = array(
2011
    'description' => t('Stores simpletest test IDs, used to auto-incrament
the test ID so that a fresh test ID is used.'),
202
    'fields' => array(
203
      'test_id'  => array(
2041
        'type' => 'serial',
2051
        'not null' => TRUE,
2061
        'description' => t('Primary Key: Unique simpletest ID used to group
test results together. Each time a set of tests
2071
                            are run a new test ID is used.'),
2081
      ),
2091
    ),
2101
    'primary key' => array('test_id'),
211
  );
2121
  return $schema;
2130
}
2141