Пример #1
0
 public function testAutoCreateFailOnLogin()
 {
     $username = self::usernameForCreation();
     $mock = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class, [], "MockPrimaryAuthenticationProvider");
     $mock->expects($this->any())->method('getUniqueId')->will($this->returnValue('primary'));
     $mock->expects($this->any())->method('beginPrimaryAuthentication')->will($this->returnValue(AuthenticationResponse::newPass($username)));
     $mock->expects($this->any())->method('accountCreationType')->will($this->returnValue(PrimaryAuthenticationProvider::TYPE_CREATE));
     $mock->expects($this->any())->method('testUserExists')->will($this->returnValue(true));
     $mock->expects($this->any())->method('testUserForCreation')->will($this->returnValue(StatusValue::newFatal('fail-from-primary')));
     $this->primaryauthMocks = [$mock];
     $this->initializeManager(true);
     $this->manager->setLogger(new \Psr\Log\NullLogger());
     $session = $this->request->getSession();
     $session->clear();
     $this->assertSame(0, $session->getUser()->getId(), 'sanity check');
     $this->assertSame(0, \User::newFromName($username)->getId(), 'sanity check');
     $this->hook('UserLoggedIn', $this->never());
     $this->hook('LocalUserCreated', $this->never());
     $ret = $this->manager->beginAuthentication([], 'http://localhost/');
     $this->unhook('LocalUserCreated');
     $this->unhook('UserLoggedIn');
     $this->assertSame(AuthenticationResponse::FAIL, $ret->status);
     $this->assertSame('authmanager-authn-autocreate-failed', $ret->message->getKey());
     $this->assertSame(0, \User::newFromName($username)->getId());
     $this->assertSame(0, $session->getUser()->getId());
 }