Skip to content

Commit

Permalink
Add missing shadow logic (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn authored Apr 17, 2023
1 parent 70f3f85 commit b5c3eeb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
30 changes: 25 additions & 5 deletions Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ShadowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Component\Content\Compat\Property;
use Sulu\Component\Content\Compat\PropertyInterface;
Expand Down Expand Up @@ -402,23 +404,35 @@ public function getNavContexts(): array
}

/**
* @return string[]
* @return array<string, string>
*/
public function getShadowLocales(): array
{
$content = $this->getContent();
if ($content instanceof ShadowInterface) {
return $content->getShadowLocales() ?? [];
}

return [];
}

/**
* @return mixed|null
*/
public function getShadowBaseLanguage()
public function getShadowBaseLanguage(): ?string
{
$content = $this->getContent();
if ($content instanceof ShadowInterface) {
return $content->getShadowLocale();
}

return null;
}

public function getIsShadow(): bool
{
$content = $this->getContent();
if ($content instanceof ShadowInterface) {
return (bool) $content->getShadowLocale();
}

return false;
}

Expand All @@ -427,6 +441,12 @@ public function getIsShadow(): bool
*/
public function getContentLocales(): array
{
$content = $this->getContent();

if ($content instanceof DimensionContentInterface) {
return $content->getAvailableLocales() ?? [];
}

return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ShadowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentDocument;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentStructureBridge;
Expand Down Expand Up @@ -727,13 +729,56 @@ public function testGetIsShadow(): void
$this->assertFalse($structure->getIsShadow());
}

public function testGetShadowLocalesWithShadowEnabled(): void
{
$content = $this->prophesize(TemplateInterface::class);
$content->willImplement(ShadowInterface::class);
$content->getShadowLocales()->shouldBeCalled()->willReturn(['de' => 'en', 'en' => 'en']);

$structure = $this->createStructureBridge($content->reveal());

$this->assertSame(['de' => 'en', 'en' => 'en'], $structure->getShadowLocales());
}

public function testGetShadowBaseLanguageWithShadowEnabled(): void
{
$content = $this->prophesize(TemplateInterface::class);
$content->willImplement(ShadowInterface::class);
$content->getShadowLocale()->shouldBeCalled()->willReturn('de');

$structure = $this->createStructureBridge($content->reveal());

$this->assertSame('de', $structure->getShadowBaseLanguage());
}

public function testGetIsShadowWithShadowEnabled(): void
{
$content = $this->prophesize(TemplateInterface::class);
$content->willImplement(ShadowInterface::class);
$content->getShadowLocale()->shouldBeCalled()->willReturn('de');

$structure = $this->createStructureBridge($content->reveal());

$this->assertTrue($structure->getIsShadow());
}

public function testGetContentLocales(): void
{
$structure = $this->createStructureBridge();

$this->assertSame([], $structure->getContentLocales());
}

public function testGetContentLocalesWithDimensionContentInterface(): void
{
$content = $this->prophesize(TemplateInterface::class);
$content->willImplement(DimensionContentInterface::class);
$content->getAvailableLocales()->shouldBeCalled()->willReturn(['de', 'en']);
$structure = $this->createStructureBridge($content->reveal());

$this->assertSame(['de', 'en'], $structure->getContentLocales());
}

public function testGetOriginalTemplate(): void
{
$structure = $this->createStructureBridge();
Expand Down

0 comments on commit b5c3eeb

Please sign in to comment.