public function testInstallCategories()
 {
     $category = new PermissionCategory('foo category', 'foo_category');
     $pcp = $this->permissionCategoriesProvider;
     $pcp->expects($this->atLeastOnce())->method('getItems')->will($this->returnValue(array($category)));
     $result = $this->installer->installCategories();
     $this->assertValidResultStructure($result);
     $this->assertEquals(1, $result['installed']);
     $this->assertEquals(0, $result['removed']);
     /* @var PermissionCategoryEntity $installedCategory */
     $installedCategory = $this->getLastRecordInDatabase(PermissionCategoryEntity::clazz());
     $this->assertNotNull($installedCategory);
     $this->assertEquals($category->getName(), $installedCategory->getName());
     $this->assertEquals($category->getTechnicalName(), $installedCategory->getTechnicalName());
     // ---
     $result = $this->installer->installCategories();
     $this->assertValidResultStructure($result);
     $this->assertEquals(0, $result['installed']);
     $this->assertEquals(0, $result['removed']);
 }
 /**
  * @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);
 }
 /**
  * @return array
  */
 private static function getTablesClasses()
 {
     return array(Permission::clazz(), PermissionCategory::clazz(), User::clazz(), Group::clazz(), Activity::clazz());
 }