-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Tests/Application/ExampleTestBundle/Link/ExampleLinkProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Link; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Link\ContentLinkProvider; | ||
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; | ||
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkConfiguration; | ||
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkConfigurationBuilder; | ||
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface; | ||
|
||
class ExampleLinkProvider extends ContentLinkProvider | ||
{ | ||
public function __construct( | ||
ContentManagerInterface $contentManager, | ||
StructureMetadataFactoryInterface $structureMetadataFactory, | ||
EntityManagerInterface $entityManager | ||
) { | ||
parent::__construct($contentManager, $structureMetadataFactory, $entityManager, Example::class); | ||
} | ||
|
||
public function getConfiguration(): LinkConfiguration | ||
{ | ||
return LinkConfigurationBuilder::create() | ||
->setTitle('Example') | ||
->setResourceKey(Example::RESOURCE_KEY) | ||
->setListAdapter('table') | ||
->setDisplayProperties(['id']) | ||
->setOverlayTitle('Select Example') | ||
->setEmptyText('No example selected') | ||
->setIcon('su-document') | ||
->getLinkConfiguration(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
Tests/Functional/Content/Infrastructure/Sulu/Link/ContentLinkProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ContentBundle\Tests\Functional\Content\Infrastructure\Sulu\Link; | ||
|
||
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; | ||
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Link\ExampleLinkProvider; | ||
use Sulu\Bundle\ContentBundle\Tests\Traits\AssertSnapshotTrait; | ||
use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait; | ||
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkItem; | ||
use Sulu\Bundle\TestBundle\Testing\WebsiteTestCase; | ||
|
||
class ContentLinkProviderTest extends WebsiteTestCase | ||
{ | ||
use AssertSnapshotTrait; | ||
use CreateExampleTrait; | ||
private ExampleLinkProvider $exampleLinkProvider; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
private static $exampleIds = []; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
static::purgeDatabase(); | ||
parent::setUpBeforeClass(); | ||
|
||
// Example 1 (both locales, both published) | ||
$example1 = static::createExample([ | ||
'en' => [ | ||
'live' => [ | ||
'title' => 'example-1', | ||
'article' => 'example-1-article', | ||
], | ||
], | ||
'de' => [ | ||
'live' => [ | ||
'title' => 'beispiel-1', | ||
'article' => null, | ||
], | ||
], | ||
]); | ||
|
||
// Example 2 (only en, published) | ||
$example2 = static::createExample([ | ||
'en' => [ | ||
'live' => [ | ||
'title' => 'example-2', | ||
], | ||
], | ||
]); | ||
|
||
// Example 3 (both locales, only en published) | ||
$example3 = static::createExample([ | ||
'en' => [ | ||
'live' => [ | ||
'title' => 'example-3', | ||
'article' => '<p>Test article</p>', | ||
], | ||
], | ||
'de' => [ | ||
'draft' => [ | ||
'title' => 'beispiel-3', | ||
], | ||
], | ||
]); | ||
|
||
// Example 4 (only de, published) | ||
$example4 = static::createExample([ | ||
'de' => [ | ||
'live' => [ | ||
'title' => 'beispiel-4', | ||
'article' => '<p>Test article</p>', | ||
], | ||
], | ||
]); | ||
|
||
// Example 5 (only en, not published) | ||
$example5 = static::createExample([ | ||
'en' => [ | ||
'draft' => [ | ||
'title' => 'example-5', | ||
], | ||
], | ||
]); | ||
|
||
static::getEntityManager()->flush(); | ||
|
||
static::$exampleIds[] = $example1->getId(); | ||
static::$exampleIds[] = $example2->getId(); | ||
static::$exampleIds[] = $example3->getId(); | ||
static::$exampleIds[] = $example4->getId(); | ||
static::$exampleIds[] = $example5->getId(); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
/** @var ExampleLinkProvider $provider */ | ||
$provider = self::getContainer()->get('example_test.example_link_provider'); | ||
$this->exampleLinkProvider = $provider; | ||
} | ||
|
||
public function testEmpty(): void | ||
{ | ||
$links = $this->exampleLinkProvider->preload([], 'de'); | ||
|
||
$this->assertCount(0, $links); | ||
} | ||
|
||
public function testPreloadDE(): void | ||
{ | ||
$links = $this->exampleLinkProvider->preload(static::$exampleIds, 'de'); | ||
$this->assertArraySnapshot('links_de.json', $this->mapLinks($links)); | ||
} | ||
|
||
public function testPreloadEN(): void | ||
{ | ||
$links = $this->exampleLinkProvider->preload(static::$exampleIds, 'en'); | ||
$this->assertArraySnapshot('links_en.json', $this->mapLinks($links)); | ||
} | ||
|
||
/** | ||
* @param LinkItem[] $links | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
private function mapLinks(array $links): array | ||
{ | ||
return \array_map(function(LinkItem $linkItem) { | ||
return [ | ||
'id' => $linkItem->getId(), | ||
'url' => $linkItem->getUrl(), | ||
'title' => $linkItem->getTitle(), | ||
]; | ||
}, $links); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Tests/Functional/Content/Infrastructure/Sulu/Link/snapshots/links_de.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"id": "@integer@", | ||
"url": "/beispiel-1", | ||
"title": "beispiel-1" | ||
}, | ||
{ | ||
"id": "@integer@", | ||
"url": "/beispiel-4", | ||
"title": "beispiel-4" | ||
} | ||
] |
17 changes: 17 additions & 0 deletions
17
Tests/Functional/Content/Infrastructure/Sulu/Link/snapshots/links_en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[ | ||
{ | ||
"id": "@integer@", | ||
"url": "/example-1", | ||
"title": "example-1" | ||
}, | ||
{ | ||
"id": "@integer@", | ||
"url": "/example-2", | ||
"title": "example-2" | ||
}, | ||
{ | ||
"id": "@integer@", | ||
"url": "/example-3", | ||
"title": "example-3" | ||
} | ||
] |