function RedirectTest::testRedirect

Same name in this branch
  1. 8.9.x core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirect()
Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirect()
  2. 9 core/modules/views_ui/tests/src/Functional/RedirectTest.php \Drupal\Tests\views_ui\Functional\RedirectTest::testRedirect()
  3. 10 core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirect()
  4. 10 core/modules/views_ui/tests/src/Functional/RedirectTest.php \Drupal\Tests\views_ui\Functional\RedirectTest::testRedirect()
  5. 11.x core/modules/system/tests/src/Functional/Form/RedirectTest.php \Drupal\Tests\system\Functional\Form\RedirectTest::testRedirect()
  6. 11.x core/modules/views_ui/tests/src/Functional/RedirectTest.php \Drupal\Tests\views_ui\Functional\RedirectTest::testRedirect()

Tests the redirecting.

File

core/modules/views_ui/tests/src/Functional/RedirectTest.php, line 27

Class

RedirectTest
Tests the redirecting after saving a views.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testRedirect() {
    $view_name = 'test_view';
    $random_destination = $this->randomMachineName();
    $edit_path = "admin/structure/views/view/{$view_name}/edit";
    $this->drupalPostForm($edit_path, [], t('Save'), [
        'query' => [
            'destination' => $random_destination,
        ],
    ]);
    $this->assertUrl($random_destination, [], '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';
    $new_path = $this->randomMachineName();
    $edit_path = "admin/structure/views/view/{$view_name}/edit";
    $path_edit_path = "admin/structure/views/nojs/display/{$view_name}/page_1/path";
    $this->drupalPostForm($path_edit_path, [
        'path' => $new_path,
    ], t('Apply'));
    $this->drupalPostForm($edit_path, [], t('Save'), [
        'query' => [
            'destination' => 'test-redirect-view',
        ],
    ]);
    $this->assertUrl($new_path, [], 'Make sure the user got redirected to the expected page after changing the URL of a page display.');
}

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