public function testGetPreviewLocationNoLocation()
 {
     $contentId = 123;
     $contentInfo = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo')->setConstructorArgs(array(array('id' => $contentId)))->getMockForAbstractClass();
     $this->contentService->expects($this->once())->method('loadContentInfo')->with($contentId)->will($this->returnValue($contentInfo));
     $this->locationHandler->expects($this->once())->method('loadParentLocationsForDraftContent')->with($contentId)->will($this->returnValue(array()));
     $this->locationHandler->expects($this->never())->method('loadLocation');
     $this->assertNull($this->provider->loadMainLocation($contentId));
 }
 /**
  * @dataProvider providerForTestEvaluate
  */
 public function testEvaluate(ParentContentTypeLimitation $limitation, ValueObject $object, $targets, array $persistence, $expected)
 {
     // Need to create inline instead of depending on testConstruct() to get correct mock instance
     $limitationType = $this->testConstruct();
     $userMock = $this->getUserMock();
     $userMock->expects($this->never())->method($this->anything());
     $persistenceMock = $this->getPersistenceMock();
     // ContentTypeHandler is never used in evaluate()
     $persistenceMock->expects($this->never())->method('contentTypeHandler');
     if (empty($persistence)) {
         // Covers API targets, where no additional loading is required
         $persistenceMock->expects($this->never())->method($this->anything());
     } elseif (!empty($targets)) {
         foreach ($targets as $index => $target) {
             if ($target instanceof LocationCreateStruct) {
                 $this->getPersistenceMock()->expects($this->once($index))->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
                 $this->locationHandlerMock->expects($this->at($index))->method('load')->with($target->parentLocationId)->will($this->returnValue($location = $persistence['locations'][$index]));
                 $contentId = $location->contentId;
             } else {
                 $contentId = $target->contentId;
             }
             $this->assertContentHandlerExpectations($index, $target instanceof LocationCreateStruct, $contentId, $persistence['contentInfos'][$index]);
         }
     } else {
         $this->getPersistenceMock()->expects($this->at(0))->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
         $this->locationHandlerMock->expects($this->once())->method($object instanceof ContentInfo && $object->published ? 'loadLocationsByContent' : 'loadParentLocationsForDraftContent')->with($object->id)->will($this->returnValue($persistence['locations']));
         foreach ($persistence['locations'] as $index => $location) {
             $this->assertContentHandlerExpectations($index, true, $location->contentId, $persistence['contentInfos'][$index]);
         }
     }
     $value = $limitationType->evaluate($limitation, $userMock, $object, $targets);
     self::assertInternalType('boolean', $value);
     self::assertEquals($expected, $value);
 }
 /**
  * @dataProvider providerForTestEvaluate
  */
 public function testEvaluate(LocationLimitation $limitation, ValueObject $object, $targets, array $persistenceLocations, $expected)
 {
     // Need to create inline instead of depending on testConstruct() to get correct mock instance
     $limitationType = $this->testConstruct();
     $userMock = $this->getUserMock();
     $userMock->expects($this->never())->method($this->anything());
     $persistenceMock = $this->getPersistenceMock();
     if (empty($persistenceLocations) && $targets !== null) {
         $persistenceMock->expects($this->never())->method($this->anything());
     } else {
         $this->getPersistenceMock()->expects($this->once())->method("locationHandler")->will($this->returnValue($this->locationHandlerMock));
         $this->locationHandlerMock->expects($this->once())->method($object instanceof ContentInfo && $object->published ? "loadLocationsByContent" : "loadParentLocationsForDraftContent")->with($object->id)->will($this->returnValue($persistenceLocations));
     }
     $value = $limitationType->evaluate($limitation, $userMock, $object, $targets);
     self::assertInternalType('boolean', $value);
     self::assertEquals($expected, $value);
 }
 /**
  * @dataProvider providerForTestEvaluate
  */
 public function testEvaluate(SubtreeLimitation $limitation, ValueObject $object, $targets, array $persistenceLocations, $expected)
 {
     // Need to create inline instead of depending on testConstruct() to get correct mock instance
     $limitationType = $this->testConstruct();
     $userMock = $this->getUserMock();
     $userMock->expects($this->never())->method($this->anything());
     $persistenceMock = $this->getPersistenceMock();
     if (empty($persistenceLocations) && $targets !== null) {
         $persistenceMock->expects($this->never())->method($this->anything());
     } elseif ($object instanceof ContentCreateStruct) {
         foreach ((array) $targets as $key => $target) {
             $this->getPersistenceMock()->expects($this->at($key))->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
             $this->locationHandlerMock->expects($this->at($key))->method('load')->with($target->parentLocationId)->will($this->returnValue($persistenceLocations[$key]));
         }
     } else {
         $this->getPersistenceMock()->expects($this->once())->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
         $this->locationHandlerMock->expects($this->once())->method($object instanceof ContentInfo && $object->published ? 'loadLocationsByContent' : 'loadParentLocationsForDraftContent')->with($object->id)->will($this->returnValue($persistenceLocations));
     }
     $value = $limitationType->evaluate($limitation, $userMock, $object, $targets);
     self::assertEquals($expected, $value);
 }