Skip to content

Commit e3a7e61

Browse files
committed
fixup! IBX-6312: View matcher ParentContentType should not throw execption if parent is not available - Added test of logging
1 parent c80e7d7 commit e3a7e61

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
use Ibexa\Contracts\Core\Repository\LocationService;
1313
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1414
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
15+
use Ibexa\Core\Base\Exceptions\NotFoundException;
1516
use Ibexa\Core\Base\Exceptions\UnauthorizedException;
1617
use Ibexa\Core\Helper\ContentPreviewHelper;
1718
use Ibexa\Core\Helper\PreviewLocationProvider;
1819
use Ibexa\Core\MVC\Symfony\Controller\Content\PreviewController;
1920
use Ibexa\Core\MVC\Symfony\SiteAccess;
2021
use Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker;
2122
use PHPUnit\Framework\TestCase;
23+
use Psr\Log\LoggerInterface;
2224
use Symfony\Component\HttpFoundation\Request;
2325
use Symfony\Component\HttpFoundation\Response;
2426
use 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

Comments
 (0)