public function ResponseTest::testFormResponse in Drupal 8
Same name and namespace in other branches
- 9 core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest::testFormResponse()
- 10 core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest::testFormResponse()
Tests that enforced responses propagate through subscribers and middleware.
File
- core/
modules/ system/ tests/ src/ Functional/ Form/ ResponseTest.php, line 30
Class
- ResponseTest
- Tests the form API Response element.
Namespace
Drupal\Tests\system\Functional\FormCode
public function testFormResponse() {
$edit = [
'content' => $this
->randomString(),
'status' => 200,
];
$this
->drupalPostForm('form-test/response', $edit, 'Submit');
$content = Json::decode($this
->getSession()
->getPage()
->getContent());
$this
->assertSession()
->statusCodeEquals(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,
];
$this
->drupalPostForm('form-test/response', $edit, 'Submit');
$content = Json::decode($this
->getSession()
->getPage()
->getContent());
$this
->assertSession()
->statusCodeEquals(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');
}