function RegistryParseFilesTestCase::setUp

7.x registry.test RegistryParseFilesTestCase::setUp()

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

drupal-7.x/modules/simpletest/tests/registry.test, line 59

Class

RegistryParseFilesTestCase

Code

function setUp() {
  parent::setUp();
  // Create files with some php to parse - one 'new', one 'existing' so
  // we test all the important code paths in _registry_parse_files.
  foreach ($this->fileTypes as $fileType) {
    $chrs = hash('sha256', microtime() . mt_rand());
    $this->$fileType = new stdClass();
    $this->$fileType->fileName = 'public://registry_test_' . substr($chrs, 0, 16);
    $this->$fileType->className = 'registry_test_class' . substr($chrs, 16, 16);
    $this->$fileType->interfaceName = 'registry_test_interface' . substr($chrs, 32, 16);
    $this->$fileType->contents = $this->getFileContents($fileType);
    file_save_data($this->$fileType->contents, $this->$fileType->fileName);

    if ($fileType == 'existing_changed') {
      // Add a record with an incorrect hash.
      $this->$fileType->fakeHash = hash('sha256', mt_rand());
      db_insert('registry_file')
        ->fields(array(
          'hash' => $this->$fileType->fakeHash,
          'filename' => $this->$fileType->fileName,
        ))
        ->execute();

      // Insert some fake resource records.
      foreach (array('class', 'interface') as $type) {
        db_insert('registry')
          ->fields(array(
            'name' => $type . hash('sha256', microtime() . mt_rand()),
            'type' => $type,
            'filename' => $this->$fileType->fileName,
          ))
          ->execute();
      }
    }
  }
}