/** * @expectedException \Ma27\ApiKeyAuthenticationBundle\Exception\CredentialException * @expectedExceptionMessage BACKEND_AUTH_LOCKED */ public function testUserIsLocked() { $user = new User(); $user->setState(User::STATE_APPROVED); $user->lock(); $hook = new IncompleteUserCheckListener(); $hook->validateUserOnAuthentication(new OnAuthenticationEvent($user)); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { /* @var \Doctrine\ORM\EntityManager $manager */ $this->checkEntityManager($manager); $passwordHasher = new PhpPasswordHasher(); $roleRepository = $manager->getRepository('Account:Role'); $userRole = $roleRepository->findOneBy(['role' => 'ROLE_USER']); $adminRole = $roleRepository->findOneBy(['role' => 'ROLE_ADMIN']); $admin = new User(); $admin->setState(User::STATE_APPROVED); $admin->setUsername('admin'); $admin->setPassword($passwordHasher->generateHash('123456')); $admin->setEmail('*****@*****.**'); $admin->addRole($adminRole); $admin->addRole($userRole); $admin->setLastAction(new \DateTime()); $manager->persist($admin); $manager->flush(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { /* @var \Doctrine\ORM\EntityManager $manager */ $this->checkEntityManager($manager); $passwordHasher = new PhpPasswordHasher(); $userRole = $manager->getRepository('Account:Role')->findOneBy(['role' => 'ROLE_USER']); $user1 = new User(); $user1->setState(User::STATE_APPROVED); $user1->setUsername('Ma27'); $user1->setPassword($passwordHasher->generateHash('72aM')); $user1->setEmail('*****@*****.**'); $user1->addRole($userRole); $user1->setLastAction(new \DateTime()); $user1->setLocale('de'); $user2 = new User(); $user2->setState(User::STATE_APPROVED); $user2->setUsername('benbieler'); $user2->setPassword($passwordHasher->generateHash('releibneb')); $user2->setEmail('*****@*****.**'); $user2->addRole($userRole); $user2->setLastAction(new \DateTime()); $locked = new User(); $locked->setState(User::STATE_APPROVED); $locked->setUsername('anonymus'); $locked->setPassword($passwordHasher->generateHash('sumynona')); $locked->setEmail('*****@*****.**'); $locked->addRole($userRole); $locked->lock(); $locked->setLastAction(new \DateTime()); $user2->addFollowing($user1); $user1->addFollowing($user2); $user1->addFollowing($manager->getRepository('Account:User')->findOneBy(['username' => 'admin'])); /** @var User $userModel */ foreach ([$user1, $user2, $locked] as $userModel) { $manager->persist($userModel); } $manager->flush(); }
public function testRoles() { $user = new User(); $role = new Role('ROLE_USER'); $user->setState(User::STATE_APPROVED); $user->addRole($role); $this->assertTrue($user->hasRole($role)); $this->assertCount(1, $user->getRoles()); $user->removeRole($role); $this->assertFalse($user->hasRole($role)); $this->assertCount(0, $user->getRoles()); }