db backup prior to drupal security update
[yaffs-website] / web / core / modules / system / src / Tests / Form / ResponseTest.php
1 <?php
2
3 namespace Drupal\system\Tests\Form;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\simpletest\WebTestBase;
7
8 /**
9  * Tests the form API Response element.
10  *
11  * @group Form
12  */
13 class ResponseTest extends WebTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['form_test'];
21
22   /**
23    * Tests that enforced responses propagate through subscribers and middleware.
24    */
25   public function testFormResponse() {
26     $edit = [
27       'content' => $this->randomString(),
28       'status' => 200,
29     ];
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');
35
36     $edit = [
37       'content' => $this->randomString(),
38       'status' => 418,
39     ];
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');
45   }
46
47 }