eZ\Publish\Core\MVC\Symfony\Cache\Tests\Http\EventListener\RelatedLocationsListenerTest::testOnContentCacheClear PHP Метод

testOnContentCacheClear() публичный Метод

    public function testOnContentCacheClear()
    {
        $contentId = 123;
        $contentInfo = new ContentInfo(['id' => $contentId]);
        $event = new ContentCacheClearEvent($contentInfo);
        $versionInfo = new VersionInfo();
        $this->contentService->expects($this->once())->method('loadVersionInfo')->with($contentInfo)->will($this->returnValue($versionInfo));
        // Relation
        $relatedContentInfo1 = new ContentInfo(['id' => 1]);
        $relatedLocation1 = new Location();
        $relatedContentInfo2 = new ContentInfo(['id' => 2]);
        $relatedLocation2 = new Location();
        $relatedLocation3 = new Location();
        $relations = [new Relation(['destinationContentInfo' => $relatedContentInfo1]), new Relation(['destinationContentInfo' => $relatedContentInfo2])];
        $this->contentService->expects($this->once())->method('loadRelations')->with($versionInfo)->will($this->returnValue($relations));
        // Reverse relations
        $reverseRelatedContentInfo = new ContentInfo();
        $relatedLocation4 = new Location();
        $reverseRelations = [new Relation(['sourceContentInfo' => $reverseRelatedContentInfo])];
        $this->contentService->expects($this->once())->method('loadReverseRelations')->with($contentInfo)->will($this->returnValue($reverseRelations));
        // Relation locations loading with locationService
        $this->locationService->expects($this->exactly(count($relations) + count($reverseRelations)))->method('loadLocations')->will($this->returnValueMap([[$relatedContentInfo1, null, [$relatedLocation1]], [$relatedContentInfo2, null, [$relatedLocation2, $relatedLocation3]], [$reverseRelatedContentInfo, null, [$relatedLocation4]]]));
        $allRelatedLocations = [$relatedLocation1, $relatedLocation2, $relatedLocation3, $relatedLocation4];
        $this->listener->onContentCacheClear($event);
        $this->assertSame($allRelatedLocations, $event->getLocationsToClear());
    }