You are here

private function ServiceControllerTest::assertRedirectedToSpecialPageOnLoginFailure in CAS 2.x

Same name and namespace in other branches
  1. 8 tests/src/Unit/Controller/ServiceControllerTest.php \Drupal\Tests\cas\Unit\Controller\ServiceControllerTest::assertRedirectedToSpecialPageOnLoginFailure()

Asserts that user is redirected to a special page on login failure.

2 calls to ServiceControllerTest::assertRedirectedToSpecialPageOnLoginFailure()
ServiceControllerTest::testLoginError in tests/src/Unit/Controller/ServiceControllerTest.php
Tests for a potential login error.
ServiceControllerTest::testTicketValidationError in tests/src/Unit/Controller/ServiceControllerTest.php
Tests for a potential validation error.

File

tests/src/Unit/Controller/ServiceControllerTest.php, line 526

Class

ServiceControllerTest
ServiceController unit tests.

Namespace

Drupal\Tests\cas\Unit\Controller

Code

private function assertRedirectedToSpecialPageOnLoginFailure($serviceController) {

  // Service controller calls Url:: methods directly, since there's no
  // existing service class to use instead of that. This makes unit testing
  // hard. We need to place mock services that Url:: uses in the container.
  $path_validator = $this
    ->createMock('Drupal\\Core\\Path\\PathValidatorInterface');
  $unrouted_url_assember = $this
    ->createMock('Drupal\\Core\\Utility\\UnroutedUrlAssemblerInterface');
  $unrouted_url_assember
    ->expects($this
    ->atLeastOnce())
    ->method('assemble')
    ->will($this
    ->returnValue('/user/login'));
  $container_builder = new ContainerBuilder();
  $container_builder
    ->set('path.validator', $path_validator);
  $container_builder
    ->set('unrouted_url_assembler', $unrouted_url_assember);
  \Drupal::setContainer($container_builder);
  $response = $serviceController
    ->handle();
  $this
    ->assertTrue($response
    ->isRedirect('/user/login'));
}