public function RedirectTest::testRedirect

Same name in this branch
  1. 9.x drupal/core/modules/views/lib/Drupal/views/Tests/UI/RedirectTest.php \Drupal\views\Tests\UI\RedirectTest::testRedirect()
  2. 9.x drupal/core/modules/system/lib/Drupal/system/Tests/Form/RedirectTest.php \Drupal\system\Tests\Form\RedirectTest::testRedirect()

Tests the redirecting.

File

drupal/core/modules/views/lib/Drupal/views/Tests/UI/RedirectTest.php, line 33
Definition of Drupal\views\tests\UI\RedirectTest.

Class

RedirectTest
Tests the redirecting after saving a views.

Namespace

Drupal\views\Tests\UI

Code

public function testRedirect() {
  $view_name = 'test_view';
  $view = views_get_view($view_name);
  $random_destination = $this
    ->randomName();
  $edit_path = "admin/structure/views/view/{$view_name}/edit";
  $this
    ->drupalPost($edit_path, array(), t('Save'), array(
    'query' => array(
      'destination' => $random_destination,
    ),
  ));
  $this
    ->assertUrl($random_destination, array(), 'Make sure the user got redirected to the expected page defined in the destination.');

  // Setup a view with a certain page display path. If you change the path
  // but have the old url in the destination the user should be redirected to
  // the new path.
  $view_name = 'test_redirect_view';
  $view = views_get_view($view_name);
  $random_destination = $this
    ->randomName();
  $new_path = $this
    ->randomName();
  $edit_path = "admin/structure/views/view/{$view_name}/edit";
  $path_edit_path = "admin/structure/views/nojs/display/{$view_name}/page_1/path";
  $this
    ->drupalPost($path_edit_path, array(
    'path' => $new_path,
  ), t('Apply'));
  $this
    ->drupalPost($edit_path, array(), t('Save'), array(
    'query' => array(
      'destination' => 'test-redirect-view',
    ),
  ));
  $this
    ->assertUrl($new_path, array(), 'Make sure the user got redirected to the expected page after changing the url of a page display.');
}