Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Form/ResponseTest.php \Drupal\Tests\system\Functional\Form\ResponseTest
  2. 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\system\Functional\Form\ResponseTest extends \Drupal\Tests\BrowserTestBase

Expanded class hierarchy of ResponseTest

File

core/modules/system/tests/src/Functional/Form/ResponseTest.php, line 15

Namespace

Drupal\Tests\system\Functional\Form
View source
class ResponseTest extends BrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected 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
      ->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');

    // Verify that response was handled by kernel response subscriber.
    $this
      ->assertSession()
      ->responseHeaderEquals('X-Form-Test-Response-Event', 'invoked');

    // Verify that response was handled by kernel middleware.
    $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');

    // Verify that response was handled by kernel response subscriber.
    $this
      ->assertSession()
      ->responseHeaderEquals('X-Form-Test-Response-Event', 'invoked');

    // Verify that response was handled by kernel middleware.
    $this
      ->assertSession()
      ->responseHeaderEquals('X-Form-Test-Stack-Middleware', 'invoked');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResponseTest::$defaultTheme protected property
ResponseTest::$modules protected static property Modules to enable.
ResponseTest::testFormResponse public function Tests that enforced responses propagate through subscribers and middleware.