You are here

public function RedirectTest::testRedirectFromErrorPages in Zircon Profile 8

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

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

File

core/modules/system/src/Tests/Form/RedirectTest.php, line 85
Contains \Drupal\system\Tests\Form\RedirectTest.

Class

RedirectTest
Tests form redirection functionality.

Namespace

Drupal\system\Tests\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(array(
    'administer themes',
  ));
  $this
    ->drupalLogin($user);

  // Visit page 'foo' (404 page) and submit the form. Verify it ends up
  // at the right URL.
  $expected = \Drupal::url('form_test.route1', array(), array(
    'query' => array(
      'test1' => 'test2',
    ),
    'absolute' => TRUE,
  ));
  $this
    ->drupalGet('foo');
  $this
    ->assertResponse(404);
  $this
    ->drupalPostForm(NULL, array(), t('Submit'));
  $this
    ->assertResponse(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
    ->assertResponse(403);
  $this
    ->drupalPostForm(NULL, array(), t('Submit'));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl($expected, [], 'Redirected to correct url/query.');
}