diff options
Diffstat (limited to 'modules/simpletest/simpletest.test')
-rw-r--r-- | modules/simpletest/simpletest.test | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test index e5b6042ac..500ee7b4b 100644 --- a/modules/simpletest/simpletest.test +++ b/modules/simpletest/simpletest.test @@ -503,3 +503,70 @@ class SimpleTestMissingDependentModuleUnitTest extends DrupalUnitTestCase { $this->fail(t('Running test with missing required module.')); } } + +/** + * Tests a test case that does not run parent::setUp() in its setUp() method. + * + * If a test case does not call parent::setUp(), running + * DrupalTestCase::tearDown() would destroy the main site's database tables. + * Therefore, we ensure that tests which are not set up properly are skipped. + * + * @see DrupalTestCase + */ +class SimpleTestBrokenSetUp extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Broken SimpleTest method', + 'description' => 'Tests a test case that does not call parent::setUp().', + 'group' => 'SimpleTest' + ); + } + + function setUp() { + // If the test is being run from the main site, set up normally. + if (!drupal_valid_test_ua()) { + parent::setUp('simpletest'); + // Create and log in user. + $admin_user = $this->drupalCreateUser(array('administer unit tests')); + $this->drupalLogin($admin_user); + } + // If the test is being run from within simpletest, set up the broken test. + else { + $this->pass(t('The test setUp() method has been run.')); + // Don't call parent::setUp(). This should trigger an error message. + } + } + + function tearDown() { + // If the test is being run from the main site, tear down normally. + if (!drupal_valid_test_ua()) { + parent::tearDown(); + } + else { + // If the test is being run from within simpletest, output a message. + $this->pass(t('The tearDown() method has run.')); + } + } + + /** + * Runs this test case from within the simpletest child site. + */ + function testBreakSetUp() { + // If the test is being run from the main site, run it again from the web + // interface within the simpletest child site. + if (!drupal_valid_test_ua()) { + $edit['SimpleTestBrokenSetUp'] = TRUE; + $this->drupalPost('admin/config/development/testing', $edit, t('Run tests')); + + // Verify that the broken test and its tearDown() method are skipped. + $this->assertRaw(t('The test setUp() method has been run.')); + $this->assertRaw(t('The test cannot be executed because it has not been set up properly.')); + $this->assertNoRaw(t('The test method has run.')); + $this->assertNoRaw(t('The tearDown() method has run.')); + } + // If the test is being run from within simpletest, output a message. + else { + $this->pass(t('The test method has run.')); + } + } +} |