1212use Ibexa \Contracts \Core \Repository \LocationService ;
1313use Ibexa \Contracts \Core \Repository \Values \Content \Content ;
1414use Ibexa \Contracts \Core \Repository \Values \Content \Location ;
15+ use Ibexa \Core \Base \Exceptions \NotFoundException ;
1516use Ibexa \Core \Base \Exceptions \UnauthorizedException ;
1617use Ibexa \Core \Helper \ContentPreviewHelper ;
1718use Ibexa \Core \Helper \PreviewLocationProvider ;
1819use Ibexa \Core \MVC \Symfony \Controller \Content \PreviewController ;
1920use Ibexa \Core \MVC \Symfony \SiteAccess ;
2021use Ibexa \Core \MVC \Symfony \View \CustomLocationControllerChecker ;
2122use PHPUnit \Framework \TestCase ;
23+ use Psr \Log \LoggerInterface ;
2224use Symfony \Component \HttpFoundation \Request ;
2325use Symfony \Component \HttpFoundation \Response ;
2426use Symfony \Component \HttpKernel \HttpKernelInterface ;
@@ -51,6 +53,9 @@ final class PreviewControllerTest extends TestCase
5153 /** @var \Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker&\PHPUnit\Framework\MockObject\MockObject */
5254 protected CustomLocationControllerChecker $ controllerChecker ;
5355
56+ /** @var LoggerInterface&\PHPUnit\Framework\MockObject\MockObject */
57+ private LoggerInterface $ logger ;
58+
5459 protected function setUp (): void
5560 {
5661 parent ::setUp ();
@@ -62,6 +67,7 @@ protected function setUp(): void
6267 $ this ->authorizationChecker = $ this ->createMock (AuthorizationCheckerInterface::class);
6368 $ this ->locationProvider = $ this ->createMock (PreviewLocationProvider::class);
6469 $ this ->controllerChecker = $ this ->createMock (CustomLocationControllerChecker::class);
70+ $ this ->logger = $ this ->createMock (LoggerInterface::class);
6571 }
6672
6773 protected function getPreviewController (): PreviewController
@@ -75,7 +81,7 @@ protected function getPreviewController(): PreviewController
7581 $ this ->locationProvider ,
7682 $ this ->controllerChecker ,
7783 false ,
78- null
84+ $ this -> logger
7985 );
8086 }
8187
@@ -130,6 +136,43 @@ public function testPreviewCanUserFail(): void
130136 $ controller ->previewContentAction (new Request (), $ contentId , $ versionNo , $ lang , 'test ' );
131137 }
132138
139+ public function testPreviewWithLogMessage (): void
140+ {
141+ $ controller = $ this ->getPreviewController ();
142+ $ contentId = 123 ;
143+ $ lang = 'eng-GB ' ;
144+ $ versionNo = 3 ;
145+ $ content = $ this ->createMock (Content::class);
146+
147+ $ location = $ this ->createMock (Location::class);
148+ $ location ->method ('__get ' )->with ('id ' )->willReturn ('42 ' );
149+
150+ $ siteAccess = $ this ->createMock (SiteAccess::class);
151+ $ this ->locationProvider
152+ ->method ('loadMainLocationByContent ' )
153+ ->with ($ content )
154+ ->willReturn ($ location )
155+ ;
156+ $ this ->contentService
157+ ->method ('loadContent ' )
158+ ->with ($ contentId , [$ lang ], $ versionNo )
159+ ->willReturn ($ content )
160+ ;
161+
162+ $ this ->authorizationChecker ->method ('isGranted ' )->willReturn (true );
163+ $ siteAccess ->name = 'test ' ;
164+ $ this ->previewHelper ->method ('getOriginalSiteAccess ' )->willReturn ($ siteAccess );
165+ $ this ->httpKernel ->method ('handle ' )->willThrowException (new NotFoundException ('Foo Property ' , 'foobar ' ));
166+
167+ $ this ->logger ->expects (
168+ self ::once ()
169+ )
170+ ->method ('warning ' )
171+ ->with ('Location (42) not found or not available in requested language (eng-GB) when loading the preview page ' );
172+
173+ $ controller ->previewContentAction (new Request (), $ contentId , $ versionNo , $ lang , 'test ' );
174+ }
175+
133176 /**
134177 * @return iterable<string, array{SiteAccess|null, int, string, int, int|null, string|null}>
135178 */
0 commit comments