RedirectTest.php in Drupal 8
File
core/modules/views_ui/tests/src/Functional/RedirectTest.php
View source
<?php
namespace Drupal\Tests\views_ui\Functional;
class RedirectTest extends UITestBase {
public static $testViews = [
'test_view',
'test_redirect_view',
];
protected $defaultTheme = 'stark';
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.');
$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.');
}
}