Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check if shadow-base-locale is published #653

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Routing/ArticleRouteDefaultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Sulu\Bundle\RouteBundle\Routing\Defaults\RouteDefaultsProviderInterface;
use Sulu\Component\Content\Compat\Structure\StructureBridge;
use Sulu\Component\Content\Compat\StructureManagerInterface;
use Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior;
use Sulu\Component\Content\Document\WorkflowStage;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;
use Sulu\Component\Content\Metadata\StructureMetadata;
Expand Down Expand Up @@ -127,6 +128,20 @@ public function isPublished($entityClass, $id, $locale)
]
);

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

if ($object instanceof ShadowLocaleBehavior && $object->isShadowLocaleEnabled()) {
$object = $this->documentManager->find(
$id,
$object->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
7 changes: 6 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ parameters:
count: 1
path: Admin/ArticleAdmin.php

-
message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Admin\\\\ArticleAdmin\\:\\:getSecurityContexts\\(\\) should return array\\<string, array\\<string, array\\<string, array\\<string\\>\\>\\>\\> but returns array\\<string, array\\<string, array\\<int\\|string, array\\<int, string\\>\\>\\>\\>\\.$#"
count: 1
path: Admin/ArticleAdmin.php

-
message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Admin\\\\ArticleAdmin\\:\\:getTypes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -2147,7 +2152,7 @@ parameters:

-
message: "#^Cannot access offset 'pageNumber' on mixed\\.$#"
count: 2
count: 1
path: Preview/ArticleObjectProvider.php

-
Expand Down
Loading