Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / system / tests / src / Functional / Form / ResponseTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Form;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests the form API Response element.
10  *
11  * @group Form
12  */
13 class ResponseTest extends BrowserTestBase {
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     $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');
36
37     $edit = [
38       'content' => $this->randomString(),
39       'status' => 418,
40     ];
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');
47   }
48
49 }