Skip to content

Commit

Permalink
add check if shadow-base-locale is published
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Dec 15, 2023
1 parent 8ccbbf7 commit cacefbf
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Routing/ArticleRouteDefaultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ public function isPublished($entityClass, $id, $locale)
]
);

if (!$object instanceof ArticleInterface) {
return false;
}

if ($object->isShadowLocaleEnabled()) {

Check failure on line 134 in Routing/ArticleRouteDefaultProvider.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Call to an undefined method Sulu\Bundle\ArticleBundle\Document\ArticleInterface::isShadowLocaleEnabled().
$object = $this->documentManager->find(
$id,
$object->getShadowLocale(),

Check failure on line 137 in Routing/ArticleRouteDefaultProvider.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Call to an undefined method Sulu\Bundle\ArticleBundle\Document\ArticleInterface::getShadowLocale().
[
'load_ghost_content' => false,
],
);
}

if (!$object instanceof ArticleInterface || WorkflowStage::PUBLISHED !== $object->getWorkflowStage()) {
return false;
}
Expand Down
64 changes: 64 additions & 0 deletions Tests/Unit/Routing/ArticleRouteDefaultProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,70 @@ public function testIsPublished(
$this->assertEquals($result, $this->provider->isPublished($this->entityClass, $this->entityId, $this->locale));
}

public function publishedDataProviderWithShadow()
{
$articleDocument = new ArticleDocument();
$articleDocument->setWorkflowStage(WorkflowStage::TEST);
$articleDocument->setShadowLocale('en');
$articleDocument->setShadowLocaleEnabled(true);

$baseDocument = new ArticleDocument();
$baseDocument->setWorkflowStage(WorkflowStage::TEST);

$baseDocumentPublished = new ArticleDocument();
$baseDocumentPublished->setWorkflowStage(WorkflowStage::PUBLISHED);

$unknownDocument = new UnknownDocument();

return [
[$articleDocument, $baseDocument, false],
[$articleDocument, $baseDocumentPublished, true],
[$articleDocument, $unknownDocument, false],
];
}

/**
* @dataProvider publishedDataProviderWithShadow
*/
public function testIsPublishedWithShadow(
$document,
$baseDocument,
$result
) {
$webspace = $this->prophesize(Webspace::class);
$webspace->getKey()->willReturn('test');

$this->requestAnalyzer->getWebspace()->willReturn($webspace->reveal());

if ($document instanceof ArticleDocument) {
$this->webspaceResolver->resolveMainWebspace($baseDocument)->willReturn('test');
$this->webspaceResolver->resolveAdditionalWebspaces($baseDocument)->willReturn([]);
}

$this->documentManager->find(
$this->entityId,
$this->locale,
[
'load_ghost_content' => false,
]
)->willReturn($document);

$this->documentManager->find(
$this->entityId,
'en',
[
'load_ghost_content' => false,
]
)->willReturn($baseDocument);

$webspace = $this->prophesize(Webspace::class);
$webspace->getKey()->willReturn('test');

$this->requestAnalyzer->getWebspace()->willReturn($webspace->reveal());

$this->assertEquals($result, $this->provider->isPublished($this->entityClass, $this->entityId, $this->locale));
}

public function testGetByEntity()
{
$article = $this->prophesize(ArticleDocument::class);
Expand Down

0 comments on commit cacefbf

Please sign in to comment.