예제 #1
0
 /**
  * Deletes all ACEs the given type and security identity
  *
  * @param SID $sid
  * @param OID $oid
  * @param string $type The ACE type. Can be one of self::*_ACE constants
  * @param string|null $field The name of a field.
  *                           Set to null for class-based or object-based ACE
  *                           Set to not null class-field-based or object-field-based ACE
  */
 protected function doDeleteAllPermissions(SID $sid, OID $oid, $type, $field)
 {
     $acl = $this->getAcl($oid);
     $key = $this->getKey($oid);
     if ($this->items[$key]->getState() !== BatchItem::STATE_DELETE) {
         if ($acl === null && $this->items[$key]->getState() === BatchItem::STATE_CREATE) {
             $this->items[$key]->removeAces($type, $field, $sid);
         } else {
             $hasChanges = $this->aceProvider->deleteAllPermissions($acl, $type, $field, $sid);
             if ($hasChanges) {
                 $this->items[$key]->setState(BatchItem::STATE_UPDATE);
             }
         }
     }
 }
 /**
  * @dataProvider aceTypesProvider
  */
 public function testDeleteAllPermissions($type, $field)
 {
     $sid = $this->createMock('Symfony\\Component\\Security\\Acl\\Model\\SecurityIdentityInterface');
     $aceSid1 = $this->createMock('Symfony\\Component\\Security\\Acl\\Model\\SecurityIdentityInterface');
     $aceSid2 = $this->createMock('Symfony\\Component\\Security\\Acl\\Model\\SecurityIdentityInterface');
     $ace1 = $this->getAce($aceSid1);
     $ace2 = $this->getAce($aceSid2);
     $sid->expects($this->at(0))->method('equals')->with($this->identicalTo($aceSid1))->will($this->returnValue(true));
     $sid->expects($this->at(1))->method('equals')->with($this->identicalTo($aceSid2))->will($this->returnValue(false));
     if ($field === null) {
         $this->acl->expects($this->once())->method('get' . $type . 'Aces')->will($this->returnValue([$ace1, $ace2]));
     } else {
         $this->acl->expects($this->once())->method('get' . $type . 'FieldAces')->with($this->equalTo($field))->will($this->returnValue([$ace1, $ace2]));
     }
     if ($field === null) {
         $this->acl->expects($this->once())->method('delete' . $type . 'Ace')->with($this->equalTo(0));
     } else {
         $this->acl->expects($this->once())->method('delete' . $type . 'FieldAce')->with($this->equalTo(0), $this->equalTo($field));
     }
     $this->assertTrue($this->manipulator->deleteAllPermissions($this->acl, $type, $field, $sid));
 }