function ResponseTest::testFormResponse
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest::testFormResponse()
- 8.9.x core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest::testFormResponse()
- 11.x 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() : void {
$edit = [
'content' => $this->randomString(),
'status' => 200,
];
$this->drupalGet('form-test/response');
$this->submitForm($edit, 'Submit');
$content = Json::decode($this->getSession()
->getPage()
->getContent());
$this->assertSession()
->statusCodeEquals(200);
$this->assertSame($edit['content'], $content, 'Response content matches');
// Verify that response was handled by kernel response subscriber.
$this->assertSession()
->responseHeaderEquals('X-Form-Test-Response-Event', 'invoked');
// Verify that response was handled by kernel middleware.
$this->assertSession()
->responseHeaderEquals('X-Form-Test-Stack-Middleware', 'invoked');
$edit = [
'content' => $this->randomString(),
'status' => 418,
];
$this->drupalGet('form-test/response');
$this->submitForm($edit, 'Submit');
$content = Json::decode($this->getSession()
->getPage()
->getContent());
$this->assertSession()
->statusCodeEquals(418);
$this->assertSame($edit['content'], $content, 'Response content matches');
// Verify that response was handled by kernel response subscriber.
$this->assertSession()
->responseHeaderEquals('X-Form-Test-Response-Event', 'invoked');
// Verify that response was handled by kernel middleware.
$this->assertSession()
->responseHeaderEquals('X-Form-Test-Stack-Middleware', 'invoked');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.