You are here

public function ResponseTest::testFormResponse in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Form/ResponseTest.php \Drupal\system\Tests\Form\ResponseTest::testFormResponse()

Tests that enforced responses propagate through subscribers and middleware.

File

core/modules/system/src/Tests/Form/ResponseTest.php, line 30
Contains \Drupal\system\Tests\Form\ResponseTest.

Class

ResponseTest
Tests the form API Response element.

Namespace

Drupal\system\Tests\Form

Code

public function testFormResponse() {
  $edit = [
    'content' => $this
      ->randomString(),
    'status' => 200,
  ];
  $content = Json::decode($this
    ->drupalPostForm('form-test/response', $edit, 'Submit'));
  $this
    ->assertResponse(200);
  $this
    ->assertIdentical($edit['content'], $content, 'Response content matches');
  $this
    ->assertIdentical('invoked', $this
    ->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
  $this
    ->assertIdentical('invoked', $this
    ->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');
  $edit = [
    'content' => $this
      ->randomString(),
    'status' => 418,
  ];
  $content = Json::decode($this
    ->drupalPostForm('form-test/response', $edit, 'Submit'));
  $this
    ->assertResponse(418);
  $this
    ->assertIdentical($edit['content'], $content, 'Response content matches');
  $this
    ->assertIdentical('invoked', $this
    ->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
  $this
    ->assertIdentical('invoked', $this
    ->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');
}