Skip to content

Commit

Permalink
fixup! IBX-6312: View matcher ParentContentType should not throw exec…
Browse files Browse the repository at this point in the history
…ption if parent is not available - Added test of logging
  • Loading branch information
vidarl committed Nov 18, 2024
1 parent e8b703d commit f7437ad
Showing 1 changed file with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Core\Base\Exceptions\NotFoundException;
use Ibexa\Core\Base\Exceptions\UnauthorizedException;
use Ibexa\Core\Helper\ContentPreviewHelper;
use Ibexa\Core\Helper\PreviewLocationProvider;
use Ibexa\Core\MVC\Symfony\Controller\Content\PreviewController;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
Expand Down Expand Up @@ -51,6 +53,9 @@ final class PreviewControllerTest extends TestCase
/** @var \Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker&\PHPUnit\Framework\MockObject\MockObject */
protected CustomLocationControllerChecker $controllerChecker;

/** @var \Psr\Log\LoggerInterface&\PHPUnit\Framework\MockObject\MockObject */
private LoggerInterface $logger;

protected function setUp(): void
{
parent::setUp();
Expand All @@ -62,6 +67,7 @@ protected function setUp(): void
$this->authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$this->locationProvider = $this->createMock(PreviewLocationProvider::class);
$this->controllerChecker = $this->createMock(CustomLocationControllerChecker::class);
$this->logger = $this->createMock(LoggerInterface::class);
}

protected function getPreviewController(): PreviewController
Expand All @@ -75,7 +81,7 @@ protected function getPreviewController(): PreviewController
$this->locationProvider,
$this->controllerChecker,
false,
null
$this->logger
);
}

Expand Down Expand Up @@ -130,6 +136,42 @@ public function testPreviewCanUserFail(): void
$controller->previewContentAction(new Request(), $contentId, $versionNo, $lang, 'test');
}

public function testPreviewWithLogMessage(): void
{
$controller = $this->getPreviewController();
$contentId = 123;
$lang = 'eng-GB';
$versionNo = 3;
$content = $this->createMock(Content::class);

$location = $this->createMock(Location::class);
$location->method('__get')->with('id')->willReturn('42');

$siteAccess = $this->createMock(SiteAccess::class);
$this->locationProvider
->method('loadMainLocationByContent')
->with($content)
->willReturn($location)
;
$this->contentService
->method('loadContent')
->with($contentId, [$lang], $versionNo)
->willReturn($content)
;

$this->authorizationChecker->method('isGranted')->willReturn(true);
$siteAccess->name = 'test';
$this->previewHelper->method('getOriginalSiteAccess')->willReturn($siteAccess);
$this->httpKernel->method('handle')->willThrowException(new NotFoundException('Foo Property', 'foobar'));

$this->logger
->expects(self::once())
->method('warning')
->with('Location (42) not found or not available in requested language (eng-GB) when loading the preview page');

$controller->previewContentAction(new Request(), $contentId, $versionNo, $lang, 'test');
}

/**
* @return iterable<string, array{SiteAccess|null, int, string, int, int|null, string|null}>
*/
Expand Down

0 comments on commit f7437ad

Please sign in to comment.