Esempio n. 1
0
    public function previewContentAction( $contentId, $versionNo, $language, $siteAccessName = null )
    {
        try
        {
            $content = $this->contentService->loadContent( $contentId, array( $language ), $versionNo );
            $location = $this->previewHelper->getPreviewLocation( $contentId );
        }
        catch ( UnauthorizedException $e )
        {
            throw new AccessDeniedException();
        }

        if ( !$this->securityContext->isGranted( new AuthorizationAttribute( 'content', 'versionread', array( 'valueObject' => $content ) ) ) )
        {
            throw new AccessDeniedException();
        }

        $siteAccess = $this->previewHelper->getOriginalSiteAccess();
        // Only switch if $siteAccessName is set and different from original
        if ( $siteAccessName !== null && $siteAccessName !== $siteAccess->name )
        {
            $siteAccess = $this->previewHelper->changeConfigScope( $siteAccessName );
        }

        $response = $this->kernel->handle(
            $this->getForwardRequest( $location, $content, $siteAccess ),
            HttpKernelInterface::SUB_REQUEST
        );
        $response->headers->remove( 'cache-control' );
        $response->headers->remove( 'expires' );

        $this->previewHelper->restoreConfigScope();

        return $response;
    }
 public function testGetPreviewLocation()
 {
     $contentId = 123;
     $locationId = 456;
     $contentInfo = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo')->setConstructorArgs(array(array('id' => $contentId, 'mainLocationId' => $locationId)))->getMockForAbstractClass();
     $location = $this->getMockBuilder('eZ\\Publish\\Core\\Repository\\Values\\Content\\Location')->setConstructorArgs(array(array('id' => $locationId, 'contentInfo' => $contentInfo)))->getMockForAbstractClass();
     $this->contentService->expects($this->once())->method('loadContentInfo')->with($contentId)->will($this->returnValue($contentInfo));
     $this->locationService->expects($this->once())->method('loadLocation')->with($locationId)->will($this->returnValue($location));
     $helper = new ContentPreviewHelper($this->contentService, $this->locationService, $this->eventDispatcher);
     $returnedLocation = $helper->getPreviewLocation($contentId);
     $this->assertSame($location, $returnedLocation);
     $this->assertSame($contentInfo, $returnedLocation->contentInfo);
 }