3 namespace Drupal\system\Tests\Form;
5 use Drupal\Component\Serialization\Json;
6 use Drupal\simpletest\WebTestBase;
9 * Tests the form API Response element.
13 class ResponseTest extends WebTestBase {
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 $content = Json::decode($this->drupalPostForm('form-test/response', $edit, 'Submit'));
31 $this->assertResponse(200);
32 $this->assertIdentical($edit['content'], $content, 'Response content matches');
33 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
34 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');
37 'content' => $this->randomString(),
40 $content = Json::decode($this->drupalPostForm('form-test/response', $edit, 'Submit'));
41 $this->assertResponse(418);
42 $this->assertIdentical($edit['content'], $content, 'Response content matches');
43 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
44 $this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');