-
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
15 changed files
with
681 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
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
87 changes: 87 additions & 0 deletions
87
Tests/Functional/Content/Application/ContentResolver/ContentResolverTest.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,87 @@ | ||
<?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\Application\ContentResolver; | ||
|
||
use Sulu\Bundle\ContentBundle\Content\Application\ContentAggregator\ContentAggregatorInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\ContentResolverInterface; | ||
use Sulu\Bundle\ContentBundle\Tests\Traits\CreateExampleTrait; | ||
use Sulu\Bundle\TestBundle\Testing\SuluTestCase; | ||
|
||
class ContentResolverTest extends SuluTestCase | ||
{ | ||
use CreateExampleTrait; | ||
|
||
private ContentResolverInterface $contentResolver; | ||
private ContentAggregatorInterface $contentAggregator; | ||
|
||
protected function setUp(): void | ||
{ | ||
self::purgeDatabase(); | ||
self::initPhpcr(); | ||
|
||
$this->contentResolver = self::getContainer()->get('sulu_content.content_resolver'); | ||
$this->contentAggregator = self::getContainer()->get('sulu_content.content_aggregator'); | ||
} | ||
|
||
public function testResolveContent(): void | ||
{ | ||
$example1 = static::createExample( | ||
[ | ||
'en' => [ | ||
'live' => [ | ||
'title' => 'example-1', | ||
'description' => 'text-area-1', | ||
'article' => 'editor-1', | ||
'blocks' => [ | ||
[ | ||
'type' => 'heading', | ||
'heading' => 'heading-1', | ||
], | ||
[ | ||
'type' => 'text', | ||
'text' => 'text-1', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
[ | ||
'create_route' => true, | ||
] | ||
); | ||
|
||
static::getEntityManager()->flush(); | ||
|
||
$dimensionContent = $this->contentAggregator->aggregate($example1, ['locale' => 'en', 'stage' => 'live']); | ||
/** @var mixed[] $result */ | ||
$result = $this->contentResolver->resolve($dimensionContent); | ||
|
||
/** @var mixed[] $content */ | ||
$content = $result['content']; | ||
|
||
self::assertSame('example-1', $content['title']); | ||
self::assertSame('text-area-1', $content['description']); | ||
self::assertSame('editor-1', $content['article']); | ||
self::assertCount(2, $content['blocks']); | ||
self::assertSame('heading-1', $content['blocks'][0]['heading']); | ||
self::assertSame('heading', $content['blocks'][0]['type']); | ||
self::assertSame('text-1', $content['blocks'][1]['text']); | ||
self::assertSame('text', $content['blocks'][1]['type']); | ||
|
||
// TODO add tests for categories / tags / images / ... | ||
self::assertNull($content['image']); | ||
|
||
// TODO add excerpt / seo test | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
Tests/Unit/Content/Application/ContentResolver/Resolver/ExcerptResolverTest.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,103 @@ | ||
<?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\Unit\Content\Application\ContentResolver\Resolver; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FormMetadata; | ||
use Sulu\Bundle\AdminBundle\Metadata\MetadataProviderInterface; | ||
use Sulu\Bundle\CategoryBundle\Entity\Category; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Resolver\ExcerptResolver; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView; | ||
use Sulu\Bundle\ContentBundle\Content\Application\MetadataResolver\MetadataResolver; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface; | ||
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; | ||
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent; | ||
use Sulu\Bundle\ContentBundle\Tests\Traits\SetGetPrivatePropertyTrait; | ||
use Sulu\Bundle\TagBundle\Entity\Tag; | ||
|
||
class ExcerptResolverTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
use SetGetPrivatePropertyTrait; | ||
|
||
public function testResolveWithNonTemplateInterface(): void | ||
{ | ||
$templateResolver = new ExcerptResolver( | ||
$this->prophesize(MetadataProviderInterface::class)->reveal(), | ||
$this->prophesize(MetadataResolver::class)->reveal() | ||
); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessage('DimensionContent needs to extend the ' . ExcerptInterface::class); | ||
|
||
$templateResolver->resolve($this->prophesize(DimensionContentInterface::class)->reveal()); | ||
} | ||
|
||
public function testResolve(): void | ||
{ | ||
$example = new Example(); | ||
$dimensionContent = new ExampleDimensionContent($example); | ||
$example->addDimensionContent($dimensionContent); | ||
$dimensionContent->setLocale('en'); | ||
|
||
$dimensionContent->setExcerptTitle('Sulu'); | ||
$dimensionContent->setExcerptDescription('Sulu is awesome'); | ||
$dimensionContent->setExcerptMore('Sulu is more awesome'); | ||
$dimensionContent->setExcerptIcon(['id' => 1]); | ||
$dimensionContent->setExcerptImage(['id' => 2]); | ||
$tag = new Tag(); | ||
$this->setPrivateProperty($tag, 'id', 1); | ||
$dimensionContent->setExcerptTags([$tag]); | ||
$category = new Category(); | ||
$this->setPrivateProperty($category, 'id', 1); | ||
$dimensionContent->setExcerptCategories([$category]); | ||
|
||
$formMetadata = $this->prophesize(FormMetadata::class); | ||
$formMetadata->getItems() | ||
->willReturn([]); | ||
$formMetadataProvider = $this->prophesize(MetadataProviderInterface::class); | ||
$formMetadataProvider->getMetadata('content_excerpt', 'en', []) | ||
->willReturn($formMetadata->reveal()); | ||
|
||
$metadataResolver = $this->prophesize(MetadataResolver::class); | ||
$metadataResolver->resolveItems([], [ | ||
'excerptTitle' => 'Sulu', | ||
'excerptDescription' => 'Sulu is awesome', | ||
'excerptMore' => 'Sulu is more awesome', | ||
'excerptIcon' => ['id' => 1], | ||
'excerptImage' => ['id' => 2], | ||
'excerptTags' => [1], | ||
'excerptCategories' => [1], | ||
], 'en') | ||
->willReturn( | ||
[ | ||
ContentView::create(['dummy' => 'data'], []), | ||
] | ||
); | ||
|
||
$templateResolver = new ExcerptResolver( | ||
$formMetadataProvider->reveal(), | ||
$metadataResolver->reveal() | ||
); | ||
|
||
$contentView = $templateResolver->resolve($dimensionContent); | ||
|
||
$this->assertInstanceOf(ContentView::class, $contentView); | ||
$content = $contentView->getContent(); | ||
$this->assertIsArray($content); | ||
$this->assertCount(1, $content); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Tests/Unit/Content/Application/ContentResolver/Resolver/SeoResolverTest.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,95 @@ | ||
<?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\Unit\Content\Application\ContentResolver\Resolver; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FormMetadata; | ||
use Sulu\Bundle\AdminBundle\Metadata\MetadataProviderInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Resolver\SeoResolver; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView; | ||
use Sulu\Bundle\ContentBundle\Content\Application\MetadataResolver\MetadataResolver; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface; | ||
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example; | ||
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\ExampleDimensionContent; | ||
|
||
class SeoResolverTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testResolveWithNonTemplateInterface(): void | ||
{ | ||
$templateResolver = new SeoResolver( | ||
$this->prophesize(MetadataProviderInterface::class)->reveal(), | ||
$this->prophesize(MetadataResolver::class)->reveal() | ||
); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessage('DimensionContent needs to extend the ' . SeoInterface::class); | ||
|
||
$templateResolver->resolve($this->prophesize(DimensionContentInterface::class)->reveal()); | ||
} | ||
|
||
public function testResolve(): void | ||
{ | ||
$example = new Example(); | ||
$dimensionContent = new ExampleDimensionContent($example); | ||
$example->addDimensionContent($dimensionContent); | ||
$dimensionContent->setLocale('en'); | ||
|
||
$dimensionContent->setSeoTitle('Sulu'); | ||
$dimensionContent->setSeoDescription('Sulu is awesome'); | ||
$dimensionContent->setSeoKeywords('Sulu, awesome'); | ||
$dimensionContent->setSeoCanonicalUrl('https://sulu.io'); | ||
$dimensionContent->setSeoNoIndex(true); | ||
$dimensionContent->setSeoNoFollow(true); | ||
$dimensionContent->setSeoHideInSitemap(true); | ||
|
||
$formMetadata = $this->prophesize(FormMetadata::class); | ||
$formMetadata->getItems() | ||
->willReturn([]); | ||
$formMetadataProvider = $this->prophesize(MetadataProviderInterface::class); | ||
$formMetadataProvider->getMetadata('content_seo', 'en', []) | ||
->willReturn($formMetadata->reveal()); | ||
|
||
$metadataResolver = $this->prophesize(MetadataResolver::class); | ||
$metadataResolver->resolveItems([], [ | ||
'seoTitle' => 'Sulu', | ||
'seoDescription' => 'Sulu is awesome', | ||
'seoKeywords' => 'Sulu, awesome', | ||
'seoCanonicalUrl' => 'https://sulu.io', | ||
'seoNoIndex' => true, | ||
'seoNoFollow' => true, | ||
'seoHideInSitemap' => true, | ||
], 'en') | ||
->willReturn( | ||
[ | ||
ContentView::create(['dummy' => 'data'], []), | ||
] | ||
); | ||
|
||
$templateResolver = new SeoResolver( | ||
$formMetadataProvider->reveal(), | ||
$metadataResolver->reveal() | ||
); | ||
|
||
$contentView = $templateResolver->resolve($dimensionContent); | ||
|
||
$this->assertInstanceOf(ContentView::class, $contentView); | ||
$content = $contentView->getContent(); | ||
$this->assertIsArray($content); | ||
$this->assertCount(1, $content); | ||
} | ||
} |
Oops, something went wrong.