You are here

function simpletest_install in SimpleTest 7

Same name and namespace in other branches
  1. 6.2 simpletest.install \simpletest_install()

Implement hook_install().

File

./simpletest.install, line 11
Install, update and uninstall functions for the simpletest module.

Code

function simpletest_install() {

  // Check for files directory.
  $path = 'public://simpletest';
  if (file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {

    // Generate binary and text test files.
    $generated = FALSE;
    if (simpletest_get_file_count($path, 'binary') == 0) {
      $lines = array(
        64,
        1024,
      );
      foreach ($lines as $line) {
        simpletest_generate_file('binary', 64, $line, 'binary');
      }
      $generated = TRUE;
    }
    if (simpletest_get_file_count($path, 'text') == 0) {
      $lines = array(
        16,
        256,
        1024,
        2048,
        20480,
      );
      foreach ($lines as $line) {
        simpletest_generate_file('text', 64, $line);
      }
      $generated = TRUE;
    }

    // Copy other test files for consistency.
    $original = drupal_get_path('module', 'simpletest') . '/files';
    $files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/');

    // If there are more files in SimpleTest's files directory than the site's
    // files directory, restore all the files. This situation might occur when
    // an errant test deletes one or more files from the site's files
    // directory. It serves a convenience to developers so that they can get
    // the test files back easily.
    if (count($files) > count(file_scan_directory($path, '/(html|image|javascript|php|sql)-.*/'))) {
      foreach ($files as $file) {
        file_unmanaged_copy($file->uri, $path, FILE_EXISTS_REPLACE);
      }
      $generated = TRUE;
    }
    if ($generated) {
      drupal_set_message('Extra test files generated/copied.');
    }
  }
}