function RedirectTest::testRedirectFromErrorPages

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirectFromErrorPages()
  2. 8.9.x core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirectFromErrorPages()
  3. 10 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 116

Class

RedirectTest
Tests form redirection functionality.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRedirectFromErrorPages() : void {
    // 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.