/** * {@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(); }
public function testInstallPermission() { $category = new PermissionCategoryEntity(); $category->setName('Foo category'); $category->setTechnicalName('foo_category'); self::$em->persist($category); self::$em->flush(); $permission = new Permission('foo name', 'FOO_ROLE', $category->getTechnicalName(), 'foo description'); $pp = $this->permissionsProvider; $pp->expects($this->atLeastOnce())->method('getItems')->will($this->returnValue(array($permission))); $result = $this->installer->installPermissions(); $this->assertValidResultStructure($result); $this->assertEquals(1, $result['installed']); $this->assertEquals(0, $result['removed']); /* @var PermissionEntity $installedPermission */ $installedPermission = $this->getLastRecordInDatabase(PermissionEntity::clazz()); $this->assertNotNull($installedPermission); $this->assertEquals($permission->getName(), $installedPermission->getName()); $this->assertEquals($permission->getDescription(), $installedPermission->getDescription()); $this->assertEquals($permission->getRole(), $installedPermission->getRole()); $this->assertNotNull($installedPermission->getCategory()); $this->assertEquals($category->getId(), $installedPermission->getCategory()->getId()); // --- $result = $this->installer->installPermissions(); $this->assertValidResultStructure($result); $this->assertEquals(0, $result['installed']); $this->assertEquals(0, $result['removed']); }