You are here

public function ServiceControllerTest::testSuccessfulLoginProxyEnabled in CAS 8

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

Tests that a user is validated and logged in with Drupal acting as proxy.

@dataProvider parameterDataProvider

File

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

Class

ServiceControllerTest
ServiceController unit tests.

Namespace

Drupal\Tests\cas\Unit\Controller

Code

public function testSuccessfulLoginProxyEnabled($returnto) {
  $this
    ->setupRequestParameters($returnto, FALSE, TRUE);
  $this->requestStack
    ->expects($this
    ->once())
    ->method('getCurrentRequest')
    ->will($this
    ->returnValue($this->requestObject));
  if ($returnto) {
    $this
      ->assertDestinationSetFromReturnTo();
  }
  $this
    ->assertSuccessfulValidation($returnto, TRUE);
  $validation_data = new CasPropertyBag('testuser');
  $validation_data
    ->setPgt('testpgt');

  // Login should be called.
  $this->casUserManager
    ->expects($this
    ->once())
    ->method('login')
    ->with($this
    ->equalTo($validation_data), $this
    ->equalTo('ST-foobar'));
  $configFactory = $this
    ->getConfigFactoryStub([
    'cas.settings' => [
      'server.hostname' => 'example-server.com',
      'server.port' => 443,
      'server.path' => '/cas',
      'proxy.initialize' => TRUE,
    ],
  ]);
  $serviceController = new ServiceController($this->casHelper, $this->casValidator, $this->casUserManager, $this->casLogout, $this->requestStack, $this->urlGenerator, $configFactory, $this->messenger, $this->eventDispatcher
    ->reveal(), $this->externalAuth
    ->reveal());
  $serviceController
    ->setStringTranslation($this
    ->getStringTranslationStub());
  $this
    ->assertRedirectedToFrontPageOnHandle($serviceController);
}