Exemplo n.º 1
0
 public function testInsertUser()
 {
     $this->loadFixtures(array());
     /** @var EntityManager $manager */
     $manager = $this->getContainer()->get('doctrine')->getManager();
     $user = new User('foo', 'bar', 'foo@bar', false);
     $user->setAdmin(true);
     $manager->persist($user);
     $manager->flush();
     $user_id = $user->getId();
     $user_salt = $user->getSalt();
     $manager->clear();
     $qb = $manager->createQueryBuilder();
     $qb->select('u')->from('CiscajaUhsaUserBundle:User', 'u')->where($qb->expr()->eq('u.id', '?1'));
     $qb->setParameter(1, $user_id);
     /** @var User $user */
     $user = $qb->getQuery()->getSingleResult();
     $this->assertEquals($user_id, $user->getId());
     $this->assertEquals($user_salt, $user->getSalt());
     $this->assertEquals('foo', $user->getUsername());
     $this->assertEquals('bar', $user->getPassword());
     $this->assertEquals('foo@bar', $user->getEmail());
     $this->assertFalse($user->isDisabled());
     $this->assertFalse($user->isDeleted());
     $this->assertTrue($user->isAdmin());
 }
Exemplo n.º 2
0
 public function testRemoveRoleFromUser()
 {
     $role = new Role('foo');
     $user = new User('bar');
     $user->addRole($role);
     $user->removeRole($role);
     $this->assertFalse($user->hasRole($role));
     $this->assertFalse($role->hasUser($user));
 }
Exemplo n.º 3
0
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername('foo');
     $user->setPassword('oof');
     $user->setEmail('foo@bar');
     $manager->persist($user);
     $manager->flush();
     $this->addReference('foo-user', $user);
 }
Exemplo n.º 4
0
 public function testInsertUserWithRole()
 {
     $this->loadFixtures(array());
     /** @var EntityManager $manager */
     $manager = $this->getContainer()->get('doctrine')->getManager();
     $role = new Role('foo');
     $user = new User('foo', 'bar', 'foo@bar');
     $user->addRole($role);
     $manager->persist($user);
     $manager->flush();
     $user_id = $user->getId();
     $manager->clear();
     $qb = $manager->createQueryBuilder();
     $qb->select('u')->from('CiscajaUhsaUserBundle:User', 'u')->where($qb->expr()->eq('u.id', '?1'))->setParameter(1, $user_id);
     /** @var User $user */
     $user = $qb->getQuery()->getSingleResult();
     $this->assertSame('foo', $user->getUsername());
     $roles = $user->getRoles();
     $this->assertCount(1, $roles);
     $this->assertSame('foo', $roles[0]->getRole());
 }
Exemplo n.º 5
0
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername('admin');
     $user->setEmail('*****@*****.**');
     $user->setDisabled(false);
     $user->addRole($this->getReference('user-role'));
     $encoder = $this->container->get('security.password_encoder');
     $password = $encoder->encodePassword($user, 'admin');
     $user->setPassword($password);
     $manager->persist($user);
     $manager->flush();
 }