public function FormSubmitterTest::testRedirectWithUrl in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testRedirectWithUrl()
- 9 core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testRedirectWithUrl()
Tests redirectForm() when a redirect is a Url object.
@covers ::redirectForm
@dataProvider providerTestRedirectWithUrl
File
- core/
tests/ Drupal/ Tests/ Core/ Form/ FormSubmitterTest.php, line 134
Class
- FormSubmitterTest
- @coversDefaultClass \Drupal\Core\Form\FormSubmitter @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testRedirectWithUrl(Url $redirect_value, $result, $status = 303) {
$container = new ContainerBuilder();
$container
->set('url_generator', $this->urlGenerator);
\Drupal::setContainer($container);
$form_submitter = $this
->getFormSubmitter();
$this->urlGenerator
->expects($this
->once())
->method('generateFromRoute')
->willReturnMap([
[
'test_route_a',
[],
[
'absolute' => TRUE,
],
FALSE,
'test-route',
],
[
'test_route_b',
[
'key' => 'value',
],
[
'absolute' => TRUE,
],
FALSE,
'test-route/value',
],
]);
$form_state = $this
->createMock('Drupal\\Core\\Form\\FormStateInterface');
$form_state
->expects($this
->once())
->method('getRedirect')
->willReturn($redirect_value);
$redirect = $form_submitter
->redirectForm($form_state);
$this
->assertSame($result, $redirect
->getTargetUrl());
$this
->assertSame($status, $redirect
->getStatusCode());
}