You are here

public function FormSubmitterTest::testRedirectWithNull in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testRedirectWithNull()
  2. 9 core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testRedirectWithNull()

Tests the redirectForm() method when the redirect is NULL.

@covers ::redirectForm

File

core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php, line 108

Class

FormSubmitterTest
@coversDefaultClass \Drupal\Core\Form\FormSubmitter @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testRedirectWithNull() {
  $form_submitter = $this
    ->getFormSubmitter();
  $form_state = $this
    ->createMock('Drupal\\Core\\Form\\FormStateInterface');
  $form_state
    ->expects($this
    ->once())
    ->method('getRedirect')
    ->willReturn(NULL);
  $this->urlGenerator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with('<current>', [], [
    'query' => [],
    'absolute' => TRUE,
  ])
    ->willReturn('http://localhost/test-path');
  $redirect = $form_submitter
    ->redirectForm($form_state);

  // If we have no redirect, we redirect to the current URL.
  $this
    ->assertSame('http://localhost/test-path', $redirect
    ->getTargetUrl());
  $this
    ->assertSame(303, $redirect
    ->getStatusCode());
}