Skip to content

Commit

Permalink
Add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn committed Jul 30, 2021
1 parent 29bf9d0 commit 57639c0
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 10 deletions.
9 changes: 2 additions & 7 deletions DependencyInjection/Compiler/SettingsFormPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ public function process(ContainerBuilder $container): void
$settingsForms = [];
foreach ($finder as $file) {
$document = new \DOMDocument();

if (!$xmlContent = file_get_contents($file->getPathname())) {
continue;
}

$document->loadXML($xmlContent);
$document->load($file->getPathname());
$path = new \DOMXPath($document);
$path->registerNamespace('x', FormXmlLoader::SCHEMA_NAMESPACE_URI);
$tagNodes = $path->query('/x:form/x:tag');
Expand All @@ -60,7 +55,7 @@ public function process(ContainerBuilder $container): void
}

uasort($settingsForms, static function ($a, $b) {
return $b['priority'] <=> $a['priority'];
return $b['priority'] ?? 0 <=> $a['priority'] ?? 0;
});

$container->setParameter('sulu_content.settings_forms', $settingsForms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\ContentDataMapperInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector\ContentMetadataInspectorInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\ContentResolverInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentTrait;
Expand All @@ -45,10 +46,14 @@

class ContentViewBuilderFactoryTest extends TestCase
{
/**
* @param mixed[] $settingsForms
*/
protected function createContentViewBuilder(
ContentMetadataInspectorInterface $contentMetadataInspector,
SecurityCheckerInterface $securityChecker,
PreviewObjectProviderRegistryInterface $previewObjectProviderRegistry = null
PreviewObjectProviderRegistryInterface $previewObjectProviderRegistry = null,
array $settingsForms = []
): ContentViewBuilderFactoryInterface {
if (null === $previewObjectProviderRegistry) {
$previewObjectProviderRegistry = $this->createPreviewObjectProviderRegistry([]);
Expand All @@ -59,7 +64,7 @@ protected function createContentViewBuilder(
$previewObjectProviderRegistry,
$contentMetadataInspector,
$securityChecker,
[]
$settingsForms
);
}

Expand Down Expand Up @@ -96,7 +101,13 @@ public function testCreateViews(): void
$contentMetadataInspector->getDimensionContentClass(Example::class)
->willReturn(ExampleDimensionContent::class);

$contentViewBuilder = $this->createContentViewBuilder($contentMetadataInspector->reveal(), $securityChecker->reveal());
$settingsForms = [
'content_settings_author' => [
'instanceOf' => AuthorInterface::class,
'priority' => 128,
],
];
$contentViewBuilder = $this->createContentViewBuilder($contentMetadataInspector->reveal(), $securityChecker->reveal(), null, $settingsForms);

$views = $contentViewBuilder->createViews(Example::class, 'edit_parent_key');

Expand Down
49 changes: 49 additions & 0 deletions Tests/Unit/DependencyInjection/Compiler/SettingsFormPassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\DependencyInjection\Compiler;

use PHPUnit\Framework\TestCase;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface;
use Sulu\Bundle\ContentBundle\DependencyInjection\Compiler\SettingsFormPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class SettingsFormPassTest extends TestCase
{
public function testProcess(): void
{
$directories = [
__DIR__ . \DIRECTORY_SEPARATOR . 'SettingsFormXml',
];

$container = $this->prophesize(ContainerBuilder::class);
$container->getParameter('sulu_admin.forms.directories')
->shouldBeCalled()
->willReturn($directories);

$container->setParameter('sulu_content.settings_forms', [
'content_settings_seo' => [
'instanceOf' => SeoInterface::class,
'priority' => 256,
],
'content_settings_author' => [
'instanceOf' => AuthorInterface::class,
'priority' => 128,
],
])->shouldBeCalled();

$settingsFormPass = new SettingsFormPass();
$settingsFormPass->process($container->reveal());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" ?>
<form xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
<key>content_settings_author</key>

<tag name="content_settings_author" instanceOf="Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface" priority="128"/>

<properties>
<section name="author">
<meta>
<title>sulu_content.author</title>
</meta>
<properties>
<property name="authored" type="datetime" colspan="6">
<meta>
<title>sulu_content.authored_date</title>
</meta>
</property>
<property name="author" type="single_contact_selection" colspan="6">
<meta>
<title>sulu_content.author</title>
</meta>
</property>
</properties>
</section>
</properties>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<form xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
<key>content_settings_no_interface</key>

<tag name="content_settings_no_interface" priority="64"/>

<properties>
</properties>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<form xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
<key>content_settings_no_tag</key>

<properties>
</properties>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<form xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
<key>content_settings_seo</key>

<tag name="content_settings_seo" instanceOf="Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface" priority="256"/>

<properties>
</properties>
</form>

0 comments on commit 57639c0

Please sign in to comment.