You are here

function DrupalTestCase::tearDown in SimpleTest 6

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

tearDown implementation, setting back switched modules etc

7 calls to DrupalTestCase::tearDown()
MenuModuleCustomMenuTest::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
MenuModuleEnable::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
MenuModuleInvalidPath::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
MenuModuleReset::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
NodeTeaserTest::tearDown in tests/node_teaser.test
tearDown implementation, setting back switched modules etc

... See full list

8 methods override DrupalTestCase::tearDown()
MenuModuleCustomMenuTest::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
MenuModuleEnable::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
MenuModuleInvalidPath::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
MenuModuleReset::tearDown in tests/menu_module.test
tearDown implementation, setting back switched modules etc
NodeTeaserTest::tearDown in tests/node_teaser.test
tearDown implementation, setting back switched modules etc

... See full list

File

./drupal_test_case.php, line 441

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() {
  if ($this->_modules != $this->_originalModules) {
    $form_state['values'] = array(
      'status' => $this->_originalModules,
      'op' => t('Save configuration'),
    );
    drupal_execute('system_modules', $form_state);

    //rebuilding all caches
    drupal_rebuild_theme_registry();
    node_types_rebuild();
    menu_rebuild();
    cache_clear_all('schema', 'cache');
    module_rebuild_cache();
    $this->_modules = $this->_originalModules;
  }
  foreach ($this->_cleanupVariables as $name => $value) {
    if (is_null($value)) {
      variable_del($name);
    }
    else {
      variable_set($name, $value);
    }
  }
  $this->_cleanupVariables = array();

  //delete nodes
  foreach ($this->_cleanupNodes as $nid) {
    node_delete($nid);
  }
  $this->_cleanupNodes = array();

  //delete roles
  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);
  }

  //delete users and their content
  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);
  }

  //delete content types
  foreach ($this->_cleanupContentTypes as $type) {
    node_type_delete($type);
  }
  $this->_cleanupContentTypes = array();

  //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();
}