
| Current Path : /var/www/html/dataninja.cn/core/modules/system/tests/src/Functional/Form/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/dataninja.cn/core/modules/system/tests/src/Functional/Form/ResponseTest.php |
<?php
namespace Drupal\Tests\system\Functional\Form;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the form API Response element.
*
* @group Form
*/
class ResponseTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['form_test'];
/**
* Tests that enforced responses propagate through subscribers and middleware.
*/
public function testFormResponse() {
$edit = [
'content' => $this->randomString(),
'status' => 200,
];
$this->drupalPostForm('form-test/response', $edit, 'Submit');
$content = Json::decode($this->getSession()->getPage()->getContent());
$this->assertResponse(200);
$this->assertIdentical($edit['content'], $content, 'Response content matches');
$this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
$this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');
$edit = [
'content' => $this->randomString(),
'status' => 418,
];
$this->drupalPostForm('form-test/response', $edit, 'Submit');
$content = Json::decode($this->getSession()->getPage()->getContent());
$this->assertResponse(418);
$this->assertIdentical($edit['content'], $content, 'Response content matches');
$this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Response-Event'), 'Response handled by kernel response subscriber');
$this->assertIdentical('invoked', $this->drupalGetHeader('X-Form-Test-Stack-Middleware'), 'Response handled by kernel middleware');
}
}