You are here

public function RedirectTest::testRedirectFromErrorPages in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirectFromErrorPages()

Tests form redirection from 404/403 pages with the Block form.

File

core/modules/system/tests/src/Functional/Form/RedirectTest.php, line 95

Class

RedirectTest
Tests form redirection functionality.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRedirectFromErrorPages() {

  // Make sure the block containing the redirect form is placed.
  $this
    ->drupalPlaceBlock('redirect_form_block');

  // Create a user that does not have permission to administer blocks.
  $user = $this
    ->drupalCreateUser([
    'administer themes',
  ]);
  $this
    ->drupalLogin($user);

  // Visit page 'foo' (404 page) and submit the form. Verify it ends up
  // at the right URL.
  $expected = Url::fromRoute('form_test.route1', [], [
    'query' => [
      'test1' => 'test2',
    ],
    'absolute' => TRUE,
  ])
    ->toString();
  $this
    ->drupalGet('foo');
  $this
    ->assertSession()
    ->statusCodeEquals(404);
  $this
    ->submitForm([], 'Submit');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->addressEquals($expected);

  // Visit the block admin page (403 page) and submit the form. Verify it
  // ends up at the right URL.
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->submitForm([], 'Submit');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->addressEquals($expected);
}