Inheritance: extends Sulu\Component\Persistence\Repository\RepositoryInterface
 public function setUp()
 {
     $this->accessControlManager = $this->prophesize(AccessControlManagerInterface::class);
     $this->securityChecker = $this->prophesize(SecurityCheckerInterface::class);
     $this->roleRepository = $this->prophesize(RoleRepositoryInterface::class);
     $this->viewHandler = $this->prophesize(ViewHandlerInterface::class);
     $this->permissionController = new PermissionController($this->accessControlManager->reveal(), $this->securityChecker->reveal(), $this->roleRepository->reveal(), $this->viewHandler->reveal());
 }
 public function testSetPermissionsWithExistingAccessControl()
 {
     $role = new Role();
     $this->roleRepository->findRoleById(1)->willReturn($role);
     $this->maskConverter->convertPermissionsToNumber(['view' => true, 'edit' => false])->willReturn(64);
     $accessControl = $this->prophesize(AccessControl::class);
     $accessControl->setPermissions(64)->shouldBeCalled();
     $this->accessControlRepository->findByTypeAndIdAndRole('AcmeBundle\\Example', 1, 1)->willReturn($accessControl);
     $this->objectManager->persist(Argument::any())->shouldNotBeCalled();
     $this->objectManager->flush()->shouldBeCalled();
     $this->doctrineAccessControlProvider->setPermissions('AcmeBundle\\Example', 1, [1 => ['view' => true, 'edit' => false]]);
 }
 /**
  * Sets the permissions for the object with the given class and id for the given security identity.
  *
  * @param string $type The name of the class to protect
  * @param string $identifier
  * @param $permissions
  */
 public function setPermissions($type, $identifier, $permissions)
 {
     foreach ($permissions as $roleId => $rolePermissions) {
         $accessControl = $this->accessControlRepository->findByTypeAndIdAndRole($type, $identifier, $roleId);
         if ($accessControl) {
             $accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
         } else {
             $role = $this->roleRepository->findRoleById($roleId);
             $accessControl = new AccessControl();
             $accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
             $accessControl->setRole($role);
             $accessControl->setEntityId($identifier);
             $accessControl->setEntityClass($type);
             $this->objectManager->persist($accessControl);
         }
     }
     $this->objectManager->flush();
 }