function RedirectTest::testRedirect in Zircon Profile 8
Same name in this branch
- 8 core/modules/views_ui/src/Tests/RedirectTest.php \Drupal\views_ui\Tests\RedirectTest::testRedirect()
- 8 core/modules/system/src/Tests/Form/RedirectTest.php \Drupal\system\Tests\Form\RedirectTest::testRedirect()
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Form/RedirectTest.php \Drupal\system\Tests\Form\RedirectTest::testRedirect()
Tests form redirection.
File
- core/
modules/ system/ src/ Tests/ Form/ RedirectTest.php, line 29 - Contains \Drupal\system\Tests\Form\RedirectTest.
Class
- RedirectTest
- Tests form redirection functionality.
Namespace
Drupal\system\Tests\FormCode
function testRedirect() {
$path = 'form-test/redirect';
$options = array(
'query' => array(
'foo' => 'bar',
),
);
$options['absolute'] = TRUE;
// Test basic redirection.
$edit = array(
'redirection' => TRUE,
'destination' => $this
->randomMachineName(),
);
$this
->drupalPostForm($path, $edit, t('Submit'));
$this
->assertUrl($edit['destination'], array(), 'Basic redirection works.');
// Test without redirection.
$edit = array(
'redirection' => FALSE,
);
$this
->drupalPostForm($path, $edit, t('Submit'));
$this
->assertUrl($path, array(), 'When redirect is set to FALSE, there should be no redirection.');
// Test redirection with query parameters.
$edit = array(
'redirection' => TRUE,
'destination' => $this
->randomMachineName(),
);
$this
->drupalPostForm($path, $edit, t('Submit'), $options);
$this
->assertUrl($edit['destination'], array(), 'Redirection with query parameters works.');
// Test without redirection but with query parameters.
$edit = array(
'redirection' => FALSE,
);
$this
->drupalPostForm($path, $edit, t('Submit'), $options);
$this
->assertUrl($path, $options, 'When redirect is set to FALSE, there should be no redirection, and the query parameters should be passed along.');
// Test redirection back to the original path.
$edit = array(
'redirection' => TRUE,
'destination' => '',
);
$this
->drupalPostForm($path, $edit, t('Submit'));
$this
->assertUrl($path, array(), 'When using an empty redirection string, there should be no redirection.');
// Test redirection back to the original path with query parameters.
$edit = array(
'redirection' => TRUE,
'destination' => '',
);
$this
->drupalPostForm($path, $edit, t('Submit'), $options);
$this
->assertUrl($path, $options, 'When using an empty redirection string, there should be no redirection, and the query parameters should be passed along.');
}