You are here

public function CasRedirectorTest::testEventsDispatched in CAS 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/Service/CasRedirectorTest.php \Drupal\Tests\cas\Unit\Service\CasRedirectorTest::testEventsDispatched()

Tests the events dispatched by the listener.

@covers ::buildRedirectResponse

File

tests/src/Unit/Service/CasRedirectorTest.php, line 192

Class

CasRedirectorTest
Cas Redirector Unit Tests.

Namespace

Drupal\Tests\cas\Unit\Service

Code

public function testEventsDispatched() {

  // Mock up listener on dispatched event.
  $this->eventDispatcher
    ->method('dispatch')
    ->willReturnCallback([
    $this,
    'dispatchEvent',
  ]);
  $this->events = [];

  // Fire the redirection event.
  $cas_redirector = new CasRedirector($this->casHelper, $this->eventDispatcher, $this->urlGenerator, $this->configFactory);
  $cas_data = new CasRedirectData();
  $response = $cas_redirector
    ->buildRedirectResponse($cas_data);

  // Verfiy that the event fired and the redirector was appropriately altered.
  $this
    ->assertEquals(1, count($this->events), 'One Event was fired');
  $this
    ->assertEquals('https://example-server.com/cas/login?strong_auth=true&service=http%3A//example.com/casservice', $response
    ->getTargetUrl(), 'Altered parameters');
}