eZ\Publish\Core\Limitation\Tests\ParentDepthLimitationTypeTest::testEvaluate PHP Method

testEvaluate() public method

public testEvaluate ( eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation $limitation, eZ\Publish\API\Repository\Values\ValueObject $object, $targets, array $persistenceLocations, $expected )
$limitation eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation
$object eZ\Publish\API\Repository\Values\ValueObject
$persistenceLocations array
    public function testEvaluate(ParentDepthLimitation $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)) {
            $persistenceMock->expects($this->never())->method($this->anything());
        } elseif ($object instanceof ContentCreateStruct) {
            $this->getPersistenceMock()->expects($this->once())->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
            foreach ($targets as $target) {
                $this->locationHandlerMock->expects($this->once())->method('load')->with($target->parentLocationId)->will($this->returnValue($persistenceLocations[$target->parentLocationId]));
            }
        } 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);
    }