Ejemplo n.º 1
0
 public function testHasAssignmentsWithCustomChecker()
 {
     $owner = new TestOwnerEntity();
     $ownerId = 123;
     $owner->setId($ownerId);
     $entity = new TestEntity();
     $entityClassName = get_class($entity);
     $entityOwnerType = 'USER';
     $entityConfig = $this->getEntityConfig($entityClassName, ['owner_type' => $entityOwnerType]);
     $entityOwnershipMetadata = new OwnershipMetadata($entityOwnerType, 'owner', 'owner_id');
     $this->ownershipProvider->expects($this->once())->method('getConfigs')->with(null, true)->will($this->returnValue([$entityConfig]));
     $this->ownershipMetadata->expects($this->once())->method('getMetadata')->with($entityClassName)->will($this->returnValue($entityOwnershipMetadata));
     $customChecker = $this->getMock('Oro\\Bundle\\OrganizationBundle\\Ownership\\OwnerAssignmentCheckerInterface');
     $customChecker->expects($this->once())->method('hasAssignments')->with($ownerId, $entityClassName, 'owner', $this->identicalTo($this->em))->will($this->returnValue(true));
     $this->defaultChecker->expects($this->never())->method('hasAssignments');
     $this->ownerDeletionManager->registerAssignmentChecker($entityClassName, $customChecker);
     $result = $this->ownerDeletionManager->hasAssignments($owner);
     $this->assertEquals(true, $result);
 }
Ejemplo n.º 2
0
 /**
  * Checks if a delete operation is allowed
  *
  * @param object        $entity
  * @param ObjectManager $em
  * @throws ForbiddenException if a delete operation is forbidden
  */
 protected function checkPermissions($entity, ObjectManager $em)
 {
     if ($this->ownerDeletionManager->isOwner($entity) && $this->ownerDeletionManager->hasAssignments($entity)) {
         throw new ForbiddenException('has assignments');
     }
 }