Skip to content

Commit

Permalink
EZP-31076: Skipped rendering hidden embedded content (#77)
Browse files Browse the repository at this point in the history
* EZP-31076: Marking embed content as hidden doesn't change its visibility

* Added unit test
  • Loading branch information
kmadejski authored and lserwatka committed Oct 31, 2019
1 parent c9399e5 commit af5d031
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/bundle/eZ/RichText/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ function (Repository $repository) use ($contentId) {
return null;
}

if ($content->contentInfo->isHidden) {
$this->logger->error(
"Could not render embedded resource: Content #{$contentId} is hidden."
);

return null;
}

$this->checkContentPermissions($content);
} catch (AccessDeniedException $e) {
$this->logger->error(
Expand Down
49 changes: 47 additions & 2 deletions tests/bundle/eZ/RichText/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,47 @@ public function testRenderContentEmbedTrashed()
);
}

public function testRenderContentEmbedHidden()
{
$renderer = $this->getMockedRenderer(['checkContentPermissions']);
$contentId = 42;
$viewType = 'embedTest';
$parameters = ['parameters'];
$isInline = true;

$contentInfoMock = $this->createMock(ContentInfo::class);
$contentInfoMock
->expects($this->at(0))
->method('__get')
->with('mainLocationId')
->willReturn(2);
$contentInfoMock
->expects($this->at(1))
->method('__get')
->with('isHidden')
->willReturn(true);

$contentMock = $this->createMock(Content::class);
$contentMock
->method('__get')
->with('contentInfo')
->willReturn($contentInfoMock);

$this->repositoryMock
->expects($this->once())
->method('sudo')
->willReturn($contentMock);

$this->loggerMock
->expects($this->once())
->method('error')
->with("Could not render embedded resource: Content #{$contentId} is hidden.");

$this->assertNull(
$renderer->renderContentEmbed($contentId, $viewType, $parameters, $isInline)
);
}

public function providerForTestRenderContentEmbedNotFound()
{
return [
Expand Down Expand Up @@ -1480,14 +1521,18 @@ protected function getContentMock($mainLocationId)
{
$contentInfoMock = $this->createMock(ContentInfo::class);
$contentInfoMock
->expects($this->once())
->expects($this->at(0))
->method('__get')
->with('mainLocationId')
->willReturn($mainLocationId);
$contentInfoMock
->expects($this->at(1))
->method('__get')
->with('isHidden')
->willReturn(false);

$contentMock = $this->createMock(Content::class);
$contentMock
->expects($this->once())
->method('__get')
->with('contentInfo')
->willReturn($contentInfoMock);
Expand Down

0 comments on commit af5d031

Please sign in to comment.