function FormSubmitterTest::testRedirectWithUrl

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testRedirectWithUrl()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testRedirectWithUrl()
  3. 10 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 146

Class

FormSubmitterTest
@coversDefaultClass \Drupal\Core\Form\FormSubmitter[[api-linebreak]] @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testRedirectWithUrl(Url $redirect_value, $result, $status = 303) : void {
  $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());
}

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