public function ServiceControllerTest::testEventListenerChangesCasUsername in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Controller/ServiceControllerTest.php \Drupal\Tests\cas\Unit\Controller\ServiceControllerTest::testEventListenerChangesCasUsername()
An event listener alters username before attempting to load user.
@covers ::handle
@dataProvider parameterDataProvider
File
- tests/
src/ Unit/ Controller/ ServiceControllerTest.php, line 470
Class
- ServiceControllerTest
- ServiceController unit tests.
Namespace
Drupal\Tests\cas\Unit\ControllerCode
public function testEventListenerChangesCasUsername($returnto) {
$this
->setupRequestParameters($returnto, FALSE, TRUE);
$this->requestStack
->expects($this
->once())
->method('getCurrentRequest')
->will($this
->returnValue($this->requestObject));
$this->eventDispatcher
->dispatch(Argument::type('string'), Argument::type(Event::class))
->will(function (array $args) {
if ($args[0] === CasHelper::EVENT_PRE_USER_LOAD_REDIRECT && $args[1] instanceof CasPreUserLoadRedirectEvent) {
$args[1]
->getPropertyBag()
->setUsername('foobar');
}
});
$expected_bag = new CasPropertyBag('foobar');
$this->casUserManager
->expects($this
->once())
->method('login')
->with($this
->equalTo($expected_bag), 'ST-foobar');
$this->casValidator
->expects($this
->once())
->method('validateTicket')
->with($this
->equalTo('ST-foobar'))
->will($this
->returnValue($expected_bag));
$this->urlGenerator
->expects($this
->once())
->method('generate')
->with('<front>')
->willReturn('/user/login');
$serviceController = new ServiceController($this->casHelper, $this->casValidator, $this->casUserManager, $this->casLogout, $this->requestStack, $this->urlGenerator, $this->configFactory, $this->messenger, $this->eventDispatcher
->reveal(), $this->externalAuth
->reveal());
$serviceController
->handle();
}