function 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[[api-linebreak]] @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());
}

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