diff --git a/core/modules/simpletest/drupal_web_test_case.php b/core/modules/simpletest/drupal_web_test_case.php index 6adaf93..05ca908 100644 --- a/core/modules/simpletest/drupal_web_test_case.php +++ b/core/modules/simpletest/drupal_web_test_case.php @@ -502,36 +502,46 @@ abstract class DrupalTestCase { } } else { + // Insert a fail record. This will be deleted on completion to ensure + // that testing completed. + $class_info = new ReflectionClass($class); + $caller = array( + 'file' => $class_info->getFileName(), + 'line' => $class_info->getStartLine(), + 'class' => $class, + ); + $completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller); + + // Setup test environment (once). + $this->setUp(); + if (!$this->setup) { + $this->fail(t("The test cannot be executed because it has not been set up properly.")); + } + + // Run test methods. foreach ($class_methods as $method) { // If the current method starts with "test", run it - it's a test. - if (strtolower(substr($method, 0, 4)) == 'test') { - // Insert a fail record. This will be deleted on completion to ensure - // that testing completed. - $method_info = new ReflectionMethod($class, $method); - $caller = array( - 'file' => $method_info->getFileName(), - 'line' => $method_info->getStartLine(), - 'function' => $class . '->' . $method . '()', - ); - $completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller); - $this->setUp(); - if ($this->setup) { - try { - $this->$method(); - // Finish up. + if ($this->setup && strtolower(substr($method, 0, 4)) == 'test') { + try { + if (is_callable($this, 'setUpTest')) { + $this->setUpTest(); } - catch (Exception $e) { - $this->exceptionHandler($e); + $this->$method(); + if (is_callable($this, 'tearDownTest')) { + $this->tearDownTest(); } - $this->tearDown(); } - else { - $this->fail(t("The test cannot be executed because it has not been set up properly.")); + catch (Exception $e) { + $this->exceptionHandler($e); } - // Remove the completion check record. - DrupalTestCase::deleteAssert($completion_check_id); } } + // Tear down test environment (once). + if ($this->setup) { + $this->tearDown(); + } + // Remove the completion check record. + DrupalTestCase::deleteAssert($completion_check_id); } // Clear out the error messages and restore error handler. drupal_get_messages(); diff --git a/core/modules/simpletest/tests/lock.test b/core/modules/simpletest/tests/lock.test index 0b423ff..14b0745 100644 --- a/core/modules/simpletest/tests/lock.test +++ b/core/modules/simpletest/tests/lock.test @@ -4,6 +4,7 @@ * Tests for the lock system. */ class LockFunctionalTest extends DrupalWebTestCase { + protected $profile = 'testing'; public static function getInfo() { return array(