class ResponseTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest
- 10 core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest
- 9 core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest
Tests the form API Response element.
@group Form
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpunitCompatibilityTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Form\ResponseTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ResponseTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ ResponseTest.php, line 13
Namespace
Drupal\Tests\system\Functional\FormView source
class ResponseTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'form_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* 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->assertSession()
->statusCodeEquals(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->assertSession()
->statusCodeEquals(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');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.