3 namespace Drupal\Tests\system\Functional\Form;
5 use Drupal\Component\Serialization\Json;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests the form API Response element.
13 class ResponseTest extends BrowserTestBase {
20 public static $modules = ['form_test'];
23 * Tests that enforced responses propagate through subscribers and middleware.
25 public function testFormResponse() {
27 'content' => $this->randomString(),
30 $this->drupalPostForm('form-test/response', $edit, 'Submit');
31 $content = Json::decode($this->getSession()->getPage()->getContent());
32 $this->assertResponse(200);
33 $this->assertIdentical($edit['content'], $content, 'Response content matches');
34 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
35 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');
38 'content' => $this->randomString(),
41 $this->drupalPostForm('form-test/response', $edit, 'Submit');
42 $content = Json::decode($this->getSession()->getPage()->getContent());
43 $this->assertResponse(418);
44 $this->assertIdentical($edit['content'], $content, 'Response content matches');
45 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
46 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');