コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public static function doSetUpBeforeClass()
 {
     static::$schemaTool = new SchemaTool(static::$em);
     static::$schemaTool->dropSchema(static::getTablesMetadata());
     static::$schemaTool->createSchema(static::getTablesMetadata());
     static::$encoder = static::$container->get('security.encoder_factory');
     static::$user = new User();
     static::$user->setEmail('*****@*****.**');
     static::$user->setPassword(static::$encoder->getEncoder(static::$user)->encodePassword('1234', static::$user->getSalt()));
     static::$user->setUsername('testUser');
     $entityPermissionCategory = new PermissionCategory();
     $entityPermissionCategory->setName('backend_user');
     $entityPermissionCategory->setTechnicalName('backend_user');
     static::$em->persist($entityPermissionCategory);
     $entityPermission = new Permission();
     $entityPermission->setRoleName('IS_AUTHENTICATED_FULLY');
     $entityPermission->setDescription('IS_AUTHENTICATED_FULLY');
     $entityPermission->setName('IS_AUTHENTICATED_FULLY');
     $entityPermission->setCategory($entityPermissionCategory);
     $entityPermission2 = new Permission();
     $entityPermission2->setRoleName('ROLE_MANAGE_PERMISSIONS');
     $entityPermission2->setDescription('ROLE_MANAGE_PERMISSIONS');
     $entityPermission2->setName('ROLE_MANAGE_PERMISSIONS');
     $entityPermission2->setCategory($entityPermissionCategory);
     $entityPermission3 = new Permission();
     $entityPermission3->setRoleName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
     $entityPermission3->setDescription('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
     $entityPermission3->setName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
     $entityPermission3->setCategory($entityPermissionCategory);
     $entityPermission4 = new Permission();
     $entityPermission4->setRoleName('ROLE_MANAGE_USER_PROFILES');
     $entityPermission4->setDescription('ROLE_MANAGE_USER_PROFILES');
     $entityPermission4->setName('ROLE_MANAGE_USER_PROFILES');
     $entityPermission4->setCategory($entityPermissionCategory);
     static::$em->persist($entityPermission);
     static::$em->persist($entityPermission2);
     static::$em->persist($entityPermission3);
     static::$em->persist($entityPermission4);
     static::$em->flush();
     $group = new Group();
     $group->setRefName('BACKEND-USER');
     $group->setName('backend-user');
     $group->addPermission($entityPermission);
     $group->addPermission($entityPermission2);
     $group->addPermission($entityPermission3);
     $group->addPermission($entityPermission4);
     static::$user->addToGroup($group);
     static::$em->persist($group);
     static::$em->persist(static::$user);
     static::$em->flush();
 }
コード例 #2
0
 public function testFindByRefName()
 {
     $emptyGroupList = static::$em->getRepository(Group::clazz())->findByRefName('test');
     $this->assertCount(0, $emptyGroupList);
     $group = new Group();
     $group->setName('test');
     $group->setRefName('test');
     static::$em->persist($group);
     static::$em->flush();
     $oneGroupList = static::$em->getRepository(Group::clazz())->findByRefName('test');
     $this->assertCount(1, $oneGroupList);
     $this->assertEquals($group, $oneGroupList[0]);
     $anotherEmptyList = static::$em->getRepository(Group::clazz())->findByRefName('testNew');
     $this->assertCount(0, $anotherEmptyList);
     return $group;
 }
コード例 #3
0
ファイル: UserServiceTest.php プロジェクト: modera/foundation
 public function testGetByRole()
 {
     $user1 = new User();
     $user2 = new User();
     $user3 = new User();
     $user1->setUsername('user1');
     $user1->setPassword('pwd1');
     $user1->setEmail('*****@*****.**');
     $user2->setUsername('user2');
     $user2->setPassword('pwd2');
     $user2->setEmail('*****@*****.**');
     $user3->setUsername('user3');
     $user3->setPassword('pwd3');
     $user3->setEmail('*****@*****.**');
     $permission1 = new Permission();
     $permission2 = new Permission();
     $permission1->setRoleName('ROLE_USER');
     $permission1->addUser($user1);
     $permission2->setRoleName('ROLE_ADMIN');
     $permission2->addUser($user2);
     $group1 = new Group();
     $group2 = new Group();
     $group1->setName('User');
     $group1->addPermission($permission1);
     $group1->addUser($user3);
     $group2->setName('Admin');
     $group2->addPermission($permission2);
     $group2->addUser($user3);
     self::$em->persist($user1);
     self::$em->persist($user2);
     self::$em->persist($user3);
     self::$em->persist($permission1);
     self::$em->persist($permission2);
     self::$em->persist($group1);
     self::$em->persist($group2);
     self::$em->flush();
     $rootUserHandler = \Phake::mock('Modera\\SecurityBundle\\RootUserHandling\\RootUserHandlerInterface');
     $service = new UserService(self::$em, $rootUserHandler);
     $this->assertEquals(array($user1, $user3), $service->getUsersByRole('ROLE_USER'));
     $this->assertEquals(array($user2, $user3), $service->getUsersByRole('ROLE_ADMIN'));
     $this->assertEquals(array($user1->getId(), $user3->getId()), $service->getIdsByRole('ROLE_USER'));
     $this->assertEquals(array($user2->getId(), $user3->getId()), $service->getIdsByRole('ROLE_ADMIN'));
 }
コード例 #4
0
 /**
  * @depends testUpdateAction_SameRefName
  *
  * @param Group $group
  */
 public function testUpdateAction_ExistingRefNameUse(Group $group)
 {
     $newGroup = new Group();
     $newGroup->setName('brandNewGroup');
     $newGroup->setRefName('brandNewRefName');
     static::$em->persist($newGroup);
     static::$em->flush();
     $this->assertEquals('TESTREFNAMEUPDATED', $group->getRefName());
     $params = array('record' => array('id' => $group->getId(), 'name' => 'newTestNameExistingRef', 'refName' => 'brandNewRefName'));
     $result = static::$controller->updateAction($params);
     $this->assertArrayHasKey('success', $result);
     $this->assertFalse($result['success']);
     $this->assertArrayHasKey('field_errors', $result);
     $this->assertCount(1, $result['field_errors']);
     $this->assertArrayHasKey('refName', $result['field_errors']);
 }