You are here

function DrupalTestCase::tearDown in SimpleTest 5

Same name and namespace in other branches
  1. 6 drupal_test_case.php \DrupalTestCase::tearDown()

tearDown implementation, setting back switched modules etc

1 call to DrupalTestCase::tearDown()
UserAccessTest::tearDown in tests/user_access.test
tearDown implementation, setting back switched modules etc
1 method overrides DrupalTestCase::tearDown()
UserAccessTest::tearDown in tests/user_access.test
tearDown implementation, setting back switched modules etc

File

./drupal_test_case.php, line 337

Class

DrupalTestCase
Test case for typical Drupal tests. Extends WebTestCase for comfortable browser usage but also implements all UnitTestCase methods, I wish WebTestCase would do this.

Code

function tearDown() {
  foreach ($this->_cleanupModules as $name => $status) {
    db_query("UPDATE {system} SET status = %d WHERE name = '%s' AND type = 'module'", $status, $name);
  }
  $this->_cleanupModules = array();

  // Refresh the modules list
  module_list(TRUE, FALSE);
  menu_rebuild();
  foreach ($this->_cleanupVariables as $name => $value) {
    if (is_null($value)) {
      variable_del($name);
    }
    else {
      variable_set($name, $value);
    }
  }
  $this->_cleanupVariables = array();
  while (sizeof($this->_cleanupRoles) > 0) {
    $rid = array_pop($this->_cleanupRoles);
    db_query("DELETE FROM {role} WHERE rid = %d", $rid);
    db_query("DELETE FROM {permission} WHERE rid = %d", $rid);
  }
  while (sizeof($this->_cleanupUsers) > 0) {
    $uid = array_pop($this->_cleanupUsers);

    // cleanup nodes this user created
    $result = db_query("SELECT nid FROM {node} WHERE uid = %d", $uid);
    while ($node = db_fetch_array($result)) {
      node_delete($node['nid']);
    }
    user_delete(array(), $uid);
  }

  //Output drupal warnings and messages into assert messages
  $drupal_msgs = drupal_get_messages();
  foreach ($drupal_msgs as $type => $msgs) {
    foreach ($msgs as $msg) {
      $this
        ->assertTrue(TRUE, "{$type}: {$msg}");
    }
  }
  parent::tearDown();
}