You are here

function BrokenSetUpTest::testMethod in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/Tests/BrokenSetUpTest.php \Drupal\simpletest\Tests\BrokenSetUpTest::testMethod()

Runs this test case from within the simpletest child site.

File

core/modules/simpletest/src/Tests/BrokenSetUpTest.php, line 79
Contains \Drupal\simpletest\Tests\BrokenSetUpTest.

Class

BrokenSetUpTest
Tests a test case that does not call parent::setUp().

Namespace

Drupal\simpletest\Tests

Code

function testMethod() {

  // If the test is being run from the main site, run it again from the web
  // interface within the simpletest child site.
  if (!$this
    ->isInChildSite()) {

    // Verify that a broken setUp() method is caught.
    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.');

    // Verify that a broken tearDown() method is caught.
    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.');

    // Verify that a broken test method is caught.
    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.');
  }
}