Chris@0: isInChildSite()) { Chris@0: parent::setUp(); Chris@0: Chris@0: $this->sharedTriggerFile = $this->publicFilesDirectory . '/trigger'; Chris@0: Chris@0: // Create and log in user. Chris@0: $admin_user = $this->drupalCreateUser(['administer unit tests']); Chris@0: $this->drupalLogin($admin_user); Chris@0: } Chris@0: // If the test is being run from within simpletest, set up the broken test. Chris@0: else { Chris@0: $this->sharedTriggerFile = $this->originalFileDirectory . '/trigger'; Chris@0: Chris@0: if (file_get_contents($this->sharedTriggerFile) === 'setup') { Chris@0: throw new \Exception('Broken setup'); Chris@0: } Chris@0: $this->pass('The setUp() method has run.'); Chris@0: } Chris@0: } Chris@0: Chris@0: protected function tearDown() { Chris@0: // If the test is being run from the main site, tear down normally. Chris@0: if (!$this->isInChildSite()) { Chris@0: unlink($this->sharedTriggerFile); Chris@0: parent::tearDown(); Chris@0: } Chris@0: // If the test is being run from within simpletest, output a message. Chris@0: else { Chris@0: if (file_get_contents($this->sharedTriggerFile) === 'teardown') { Chris@0: throw new \Exception('Broken teardown'); Chris@0: } Chris@0: $this->pass('The tearDown() method has run.'); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Runs this test case from within the simpletest child site. Chris@0: */ Chris@0: public function testMethod() { Chris@0: // If the test is being run from the main site, run it again from the web Chris@0: // interface within the simpletest child site. Chris@0: if (!$this->isInChildSite()) { Chris@0: // Verify that a broken setUp() method is caught. Chris@0: file_put_contents($this->sharedTriggerFile, 'setup'); Chris@0: $edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE; Chris@0: $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests')); Chris@0: $this->assertRaw('Broken setup'); Chris@0: $this->assertNoRaw('The setUp() method has run.'); Chris@0: $this->assertNoRaw('Broken test'); Chris@0: $this->assertNoRaw('The test method has run.'); Chris@0: $this->assertNoRaw('Broken teardown'); Chris@0: $this->assertNoRaw('The tearDown() method has run.'); Chris@0: Chris@0: // Verify that a broken tearDown() method is caught. Chris@0: file_put_contents($this->sharedTriggerFile, 'teardown'); Chris@0: $edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE; Chris@0: $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests')); Chris@0: $this->assertNoRaw('Broken setup'); Chris@0: $this->assertRaw('The setUp() method has run.'); Chris@0: $this->assertNoRaw('Broken test'); Chris@0: $this->assertRaw('The test method has run.'); Chris@0: $this->assertRaw('Broken teardown'); Chris@0: $this->assertNoRaw('The tearDown() method has run.'); Chris@0: Chris@0: // Verify that a broken test method is caught. Chris@0: file_put_contents($this->sharedTriggerFile, 'test'); Chris@0: $edit['tests[Drupal\simpletest\Tests\BrokenSetUpTest]'] = TRUE; Chris@0: $this->drupalPostForm('admin/config/development/testing', $edit, t('Run tests')); Chris@0: $this->assertNoRaw('Broken setup'); Chris@0: $this->assertRaw('The setUp() method has run.'); Chris@0: $this->assertRaw('Broken test'); Chris@0: $this->assertNoRaw('The test method has run.'); Chris@0: $this->assertNoRaw('Broken teardown'); Chris@0: $this->assertRaw('The tearDown() method has run.'); Chris@0: } Chris@0: // If the test is being run from within simpletest, output a message. Chris@0: else { Chris@0: if (file_get_contents($this->sharedTriggerFile) === 'test') { Chris@0: throw new \Exception('Broken test'); Chris@0: } Chris@0: $this->pass('The test method has run.'); Chris@0: } Chris@0: } Chris@0: Chris@0: }