function RedirectTest::testRedirectFromErrorPages
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirectFromErrorPages()
- 10 core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirectFromErrorPages()
- 11.x 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 85
Class
- RedirectTest
- Tests form redirection functionality.
Namespace
Drupal\Tests\system\Functional\FormCode
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->drupalPostForm(NULL, [], t('Submit'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertUrl($expected, [], 'Redirected to correct URL/query.');
// 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->drupalPostForm(NULL, [], t('Submit'));
$this->assertSession()
->statusCodeEquals(200);
$this->assertUrl($expected, [], 'Redirected to correct URL/query.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.