/** * @return array */ public function installPermissions() { $permissionInstalled = 0; $permissions = $this->permissionsProvider->getItems(); foreach ($permissions as $permission) { /* @var \Modera\SecurityBundle\Model\PermissionInterface $permission */ $entityPermission = $this->em->getRepository(Permission::clazz())->findOneBy(array('roleName' => $permission->getRole())); if (!$entityPermission) { $entityPermission = new Permission(); $entityPermission->setRoleName($permission->getRole()); $this->em->persist($entityPermission); ++$permissionInstalled; } $entityPermission->setDescription($permission->getDescription()); $entityPermission->setName($permission->getName()); $category = $this->em->getRepository(PermissionCategory::clazz())->findOneBy(array('technicalName' => $permission->getCategory())); if ($category) { $entityPermission->setCategory($category); } } $this->em->flush(); return array('installed' => $permissionInstalled, 'removed' => 0); }
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']); }
/** * @return array */ private static function getTablesClasses() { return array(Permission::clazz(), PermissionCategory::clazz(), User::clazz(), Group::clazz(), Activity::clazz()); }