public function testPreview()
{
$contentId = 123;
$lang = 'eng-GB';
$versionNo = 3;
$locationId = 456;
$content = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
$location = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Location')->setConstructorArgs(array(array('id' => $locationId)))->getMockForAbstractClass();
// Repository expectations
$this->locationProvider->expects($this->once())->method('loadMainLocation')->with($contentId)->will($this->returnValue($location));
$this->contentService->expects($this->once())->method('loadContent')->with($contentId, array($lang), $versionNo)->will($this->returnValue($content));
$this->authorizationChecker->expects($this->once())->method('isGranted')->with($this->equalTo(new AuthorizationAttribute('content', 'versionread', array('valueObject' => $content))))->will($this->returnValue(true));
$previewSiteAccessName = 'test';
$previewSiteAccess = new SiteAccess($previewSiteAccessName, 'preview');
$previousSiteAccessName = 'foo';
$previousSiteAccess = new SiteAccess($previousSiteAccessName);
$request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request', array('duplicate'));
// PreviewHelper expectations
$this->previewHelper->expects($this->exactly(2))->method('setPreviewActive')->will($this->returnValueMap(array(array(true, null), array(false, null))));
$this->previewHelper->expects($this->once())->method('setPreviewedContent')->with($content);
$this->previewHelper->expects($this->once())->method('setPreviewedLocation')->with($location);
$this->previewHelper->expects($this->once())->method('getOriginalSiteAccess')->will($this->returnValue($previousSiteAccess));
$this->previewHelper->expects($this->once())->method('changeConfigScope')->with($previewSiteAccessName)->will($this->returnValue($previewSiteAccess));
$this->previewHelper->expects($this->once())->method('restoreConfigScope');
// Request expectations
$duplicatedRequest = $this->getDuplicatedRequest($location, $content, $previewSiteAccess);
$request->expects($this->once())->method('duplicate')->will($this->returnValue($duplicatedRequest));
// Kernel expectations
$expectedResponse = new Response();
$this->httpKernel->expects($this->once())->method('handle')->with($duplicatedRequest, HttpKernelInterface::SUB_REQUEST)->will($this->returnValue($expectedResponse));
$controller = $this->getPreviewController();
$this->assertSame($expectedResponse, $controller->previewContentAction($request, $contentId, $versionNo, $lang, $previewSiteAccessName));
}