simpletest_install

Versions
7
simpletest_install()

Implements hook_install().

Code

modules/simpletest/simpletest.install, line 11

<?php
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.');
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.