public function CasUserManagerTest::testUserNotFoundAndEventListenerDeniesAutoRegistration in CAS 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Service/CasUserManagerTest.php \Drupal\Tests\cas\Unit\Service\CasUserManagerTest::testUserNotFoundAndEventListenerDeniesAutoRegistration()
User account doesn't exist, auto reg is enabled, but listener denies.
@covers ::login
File
- tests/
src/ Unit/ Service/ CasUserManagerTest.php, line 212
Class
- CasUserManagerTest
- CasUserManager unit tests.
Namespace
Drupal\Tests\cas\Unit\ServiceCode
public function testUserNotFoundAndEventListenerDeniesAutoRegistration() {
$config_factory = $this
->getConfigFactoryStub([
'cas.settings' => [
'user_accounts.auto_register' => TRUE,
'user_accounts.email_assignment_strategy' => CasUserManager::EMAIL_ASSIGNMENT_STANDARD,
'user_accounts.email_hostname' => 'sample.com',
],
]);
$cas_user_manager = $this
->getMockBuilder('Drupal\\cas\\Service\\CasUserManager')
->setMethods([
'storeLoginSessionData',
'register',
])
->setConstructorArgs([
$this->externalAuth,
$this->authmap,
$config_factory,
$this->session,
$this->connection,
$this->eventDispatcher,
$this->casHelper,
$this->casProxyHelper
->reveal(),
])
->getMock();
$this->externalAuth
->method('load')
->willReturn(FALSE);
$this->eventDispatcher
->method('dispatch')
->willReturnCallback(function ($event_type, $event) {
if ($event instanceof CasPreRegisterEvent) {
$event
->setAllowAutomaticRegistration(FALSE);
}
});
$cas_user_manager
->expects($this
->never())
->method('register');
$this->externalAuth
->expects($this
->never())
->method('userLoginFinalize');
$this
->expectException('Drupal\\cas\\Exception\\CasLoginException', 'Cannot register user, an event listener denied access.');
$cas_user_manager
->login(new CasPropertyBag('test'), 'ticket');
}