BrokenSetUpTest.php in SimpleTest 8.3
File
src/Tests/BrokenSetUpTest.php
View source
<?php
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
class BrokenSetUpTest extends WebTestBase {
public static $modules = [
'simpletest',
];
protected $sharedTriggerFile;
protected function setUp() {
if (!$this
->isInChildSite()) {
parent::setUp();
$this->sharedTriggerFile = $this->publicFilesDirectory . '/trigger';
$admin_user = $this
->drupalCreateUser([
'administer unit tests',
]);
$this
->drupalLogin($admin_user);
}
else {
$this->sharedTriggerFile = $this->originalFileDirectory . '/trigger';
if (file_get_contents($this->sharedTriggerFile) === 'setup') {
throw new \Exception('Broken setup');
}
$this
->pass('The setUp() method has run.');
}
}
protected function tearDown() {
if (!$this
->isInChildSite()) {
unlink($this->sharedTriggerFile);
parent::tearDown();
}
else {
if (file_get_contents($this->sharedTriggerFile) === 'teardown') {
throw new \Exception('Broken teardown');
}
$this
->pass('The tearDown() method has run.');
}
}
public function testMethod() {
if (!$this
->isInChildSite()) {
file_put_contents($this->sharedTriggerFile, 'setup');
$edit['tests[Drupal\\simpletest\\Tests\\BrokenSetUpTest]'] = TRUE;
$this
->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
$this
->assertRaw('Broken setup');
$this
->assertNoRaw('The setUp() method has run.');
$this
->assertNoRaw('Broken test');
$this
->assertNoRaw('The test method has run.');
$this
->assertNoRaw('Broken teardown');
$this
->assertNoRaw('The tearDown() method has run.');
file_put_contents($this->sharedTriggerFile, 'teardown');
$edit['tests[Drupal\\simpletest\\Tests\\BrokenSetUpTest]'] = TRUE;
$this
->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
$this
->assertNoRaw('Broken setup');
$this
->assertRaw('The setUp() method has run.');
$this
->assertNoRaw('Broken test');
$this
->assertRaw('The test method has run.');
$this
->assertRaw('Broken teardown');
$this
->assertNoRaw('The tearDown() method has run.');
file_put_contents($this->sharedTriggerFile, 'test');
$edit['tests[Drupal\\simpletest\\Tests\\BrokenSetUpTest]'] = TRUE;
$this
->drupalPostForm('admin/config/development/testing', $edit, t('Run tests'));
$this
->assertNoRaw('Broken setup');
$this
->assertRaw('The setUp() method has run.');
$this
->assertRaw('Broken test');
$this
->assertNoRaw('The test method has run.');
$this
->assertNoRaw('Broken teardown');
$this
->assertRaw('The tearDown() method has run.');
}
else {
if (file_get_contents($this->sharedTriggerFile) === 'test') {
throw new \Exception('Broken test');
}
$this
->pass('The test method has run.');
}
}
}