ResponseTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/Form/ResponseTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Form;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\BrowserTestBase;
class ResponseTest extends BrowserTestBase {
protected static $modules = [
'form_test',
];
protected $defaultTheme = 'stark';
public function testFormResponse() {
$edit = [
'content' => $this
->randomString(),
'status' => 200,
];
$this
->drupalGet('form-test/response');
$this
->submitForm($edit, 'Submit');
$content = Json::decode($this
->getSession()
->getPage()
->getContent());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSame($edit['content'], $content, 'Response content matches');
$this
->assertSession()
->responseHeaderEquals('X-Form-Test-Response-Event', 'invoked');
$this
->assertSession()
->responseHeaderEquals('X-Form-Test-Stack-Middleware', 'invoked');
$edit = [
'content' => $this
->randomString(),
'status' => 418,
];
$this
->drupalGet('form-test/response');
$this
->submitForm($edit, 'Submit');
$content = Json::decode($this
->getSession()
->getPage()
->getContent());
$this
->assertSession()
->statusCodeEquals(418);
$this
->assertSame($edit['content'], $content, 'Response content matches');
$this
->assertSession()
->responseHeaderEquals('X-Form-Test-Response-Event', 'invoked');
$this
->assertSession()
->responseHeaderEquals('X-Form-Test-Stack-Middleware', 'invoked');
}
}