Skip to content

Commit

Permalink
Merge remote-tracking branch 'sulu/release/2.0' into release/2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
danrot committed Aug 26, 2020
2 parents 89d38b2 + 327a723 commit 0df2f39
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG for Sulu
==================

* 1.6.36 (2020-08-26)
* BUGFIX #5415 [ContentBundle] Fix teaser-selection deselecting
* BUGFIX #5442 [AudienceTargetingBundle] Fix export data function of audience-target selection
* BUGFIX #5418 [MediaBundle] Store values from image crop as integers

* 1.6.35 (2020-07-30)
* BUGFIX #5435 [ContactBundle] Fix type of tag names for serialization of contacts

Expand Down
45 changes: 45 additions & 0 deletions src/Sulu/Bundle/AdminBundle/Exception/InvalidRootTagException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* 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\AdminBundle\Exception;

class InvalidRootTagException extends \Exception
{
/**
* @var string
*/
private $resource;

/**
* @var string
*/
private $rootTag;

public function __construct(string $resource, string $rootTag)
{
parent::__construct(
\sprintf('The resource "%s" does not have a root tag named "%s"', $resource, $rootTag)
);

$this->resource = $resource;
$this->rootTag = $rootTag;
}

public function getResource()
{
return $this->resource;
}

public function getRootTag()
{
return $this->rootTag;
}
}
5 changes: 5 additions & 0 deletions src/Sulu/Bundle/AdminBundle/FormMetadata/FormXmlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Sulu\Bundle\AdminBundle\FormMetadata;

use Sulu\Bundle\AdminBundle\Exception\InvalidRootTagException;
use Sulu\Bundle\AdminBundle\FormMetadata\FormMetadata as ExternalFormMetadata;
use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FormMetadata;
use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\LocalizedFormMetadataCollection;
Expand Down Expand Up @@ -69,6 +70,10 @@ protected function parse($resource, \DOMXPath $xpath, $type): LocalizedFormMetad
// init running vars
$tags = [];

if (0 === $xpath->query('/x:form')->count()) {
throw new InvalidRootTagException($resource, 'form');
}

$form = new ExternalFormMetadata();
$form->setResource($resource);
$form->setKey($xpath->query('/x:form/x:key')->item(0)->nodeValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sulu\Bundle\AdminBundle\Tests\Unit\FormMetadata;

use PHPUnit\Framework\TestCase;
use Sulu\Bundle\AdminBundle\Exception\InvalidRootTagException;
use Sulu\Bundle\AdminBundle\FormMetadata\FormMetadataMapper;
use Sulu\Bundle\AdminBundle\FormMetadata\FormXmlLoader;
use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FormMetadata;
Expand Down Expand Up @@ -504,6 +505,16 @@ public function testLoadFormWithSizedSections()
$this->assertCount(1, $formMetadata->getItems()['name']->getItems());
}

public function testLoadFormInvalidRootTag()
{
$this->expectException(InvalidRootTagException::class);
$this->expectExceptionMessageRegExp('/"form"/');

$this->loader->load(
__DIR__ . \DIRECTORY_SEPARATOR . 'data' . \DIRECTORY_SEPARATOR . 'form_invalid_root_tag.xml'
);
}

public function testLoadFormInvalid()
{
$this->expectException(\InvalidArgumentException::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" ?>
<properties 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"
>
<property name="audience_targeting_groups" type="target_group_select" onInvalid="ignore" />
</properties>
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function exportData($propertyValue)
return \json_encode($propertyValue);
}

return [];
return \json_encode([]);
}

public function importData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroup"
repository-class="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroupRepository"
table="at_target_groups">

<mapped-superclass
name="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroup"
repository-class="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroupRepository"
table="at_target_groups"
>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
Expand All @@ -16,16 +17,20 @@
<field name="allWebspaces" column="allWebspaces" type="boolean" nullable="false"/>
<field name="active" column="active" type="boolean" nullable="false"/>

<one-to-many field="webspaces"
mapped-by="targetGroup"
target-entity="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroupWebspace">
<one-to-many
field="webspaces"
mapped-by="targetGroup"
target-entity="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroupWebspace"
>
<cascade>
<cascade-persist/>
</cascade>
</one-to-many>
<one-to-many field="rules"
mapped-by="targetGroup"
target-entity="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroupRule">
<one-to-many
field="rules"
mapped-by="targetGroup"
target-entity="Sulu\Bundle\AudienceTargetingBundle\Entity\TargetGroupRule"
>
<cascade>
<cascade-persist/>
</cascade>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,39 @@ public function testRemoveNotExisting()

$this->audienceTargetingGroups->remove($node->reveal(), $property->reveal(), 'sulu_io', 'en', null);
}

public function testExportData()
{
$this->assertEquals('[]', $this->audienceTargetingGroups->exportData(null));
$this->assertEquals('[]', $this->audienceTargetingGroups->exportData([]));
$this->assertEquals('[1]', $this->audienceTargetingGroups->exportData([1]));
}

public function testImportDataEmpty()
{
$node = $this->prophesize(NodeInterface::class);
$property = $this->prophesize(PropertyInterface::class);

$property->getName()->willReturn('test');

$property->setValue([])->shouldBeCalled();
$property->getValue()->willReturn([]);
$node->setProperty('test', [])->shouldBeCalled();

$this->audienceTargetingGroups->importData($node->reveal(), $property->reveal(), '[]', 1, 'sulu_io', 'en');
}

public function testImportData()
{
$node = $this->prophesize(NodeInterface::class);
$property = $this->prophesize(PropertyInterface::class);

$property->getName()->willReturn('test');

$property->setValue([1, 2])->shouldBeCalled();
$property->getValue()->willReturn([1, 2]);
$node->setProperty('test', [1, 2])->shouldBeCalled();

$this->audienceTargetingGroups->importData($node->reveal(), $property->reveal(), '[1, 2]', 1, 'sulu_io', 'en');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* 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\CoreBundle\DependencyInjection\Compiler;

use JMS\Serializer\Construction\DoctrineObjectConstructor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @internal
*/
final class JmsObjectConstructorCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (null === $container->getDefinition('jms_serializer.doctrine_object_constructor')->getDecoratedService()) {
return;
}

$container->removeDefinition('jms_serializer.object_constructor');
$container->setAlias('jms_serializer.doctrine_object_constructor', DoctrineObjectConstructor::class);
$container->setAlias('jms_serializer.object_constructor', 'jms_serializer.unserialize_object_constructor');
}
}
2 changes: 2 additions & 0 deletions src/Sulu/Bundle/CoreBundle/SuluCoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Sulu\Bundle\CoreBundle\DependencyInjection\Compiler\CsvHandlerCompilerPass;
use Sulu\Bundle\CoreBundle\DependencyInjection\Compiler\ExceptionHandlerCompilerPass;
use Sulu\Bundle\CoreBundle\DependencyInjection\Compiler\JmsObjectConstructorCompilerPass;
use Sulu\Bundle\CoreBundle\DependencyInjection\Compiler\ListBuilderMetadataProviderCompilerPass;
use Sulu\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterContentTypesCompilerPass;
use Sulu\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterLocalizationProvidersPass;
Expand Down Expand Up @@ -51,5 +52,6 @@ public function build(ContainerBuilder $container)
);

$container->addCompilerPass(new ExceptionHandlerCompilerPass());
$container->addCompilerPass(new JmsObjectConstructorCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1024);
}
}
8 changes: 4 additions & 4 deletions src/Sulu/Bundle/MediaBundle/Entity/FormatOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FormatOptions
*/
public function setCropX($cropX)
{
$this->cropX = $cropX;
$this->cropX = (int) \round($cropX);

return $this;
}
Expand All @@ -79,7 +79,7 @@ public function getCropX()
*/
public function setCropY($cropY)
{
$this->cropY = $cropY;
$this->cropY = (int) \round($cropY);

return $this;
}
Expand All @@ -103,7 +103,7 @@ public function getCropY()
*/
public function setCropWidth($cropWidth)
{
$this->cropWidth = $cropWidth;
$this->cropWidth = (int) \round($cropWidth);

return $this;
}
Expand All @@ -127,7 +127,7 @@ public function getCropWidth()
*/
public function setCropHeight($cropHeight)
{
$this->cropHeight = $cropHeight;
$this->cropHeight = (int) \round($cropHeight);

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public function save($mediaId, $formatKey, array $data)
if (!isset($formatOptions)) {
$formatOptions = new FormatOptions();
$formatOptions->setFileVersion($fileVersion);
$fileVersion->addFormatOptions($formatOptions);
$formatOptions->setFormatKey($formatKey);
$fileVersion->addFormatOptions($formatOptions);
}

$formatOptions = $this->setDataOnEntity($formatOptions, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ public function testSave()
42,
'sulu-100x100',
[
'cropX' => 10,
'cropY' => 11,
'cropHeight' => 12,
'cropWidth' => 13,
'cropX' => 10.05,
'cropY' => 11.15,
'cropHeight' => 12.12,
'cropWidth' => 13.42,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private function getExportResultData($documents)
'audience_targeting_groups',
'target_group_selection',
false,
$extensionData['excerpt']['audience_targeting_groups']
\json_encode($extensionData['excerpt']['audience_targeting_groups'])
),
],
];
Expand Down
5 changes: 3 additions & 2 deletions src/Sulu/Component/Webspace/Manager/WebspaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,10 @@ protected function matchUrl($url, $portalUrl)
*/
private function createResourceLocatorUrl($portalUrl, $resourceLocator, $scheme = null)
{
$currentRequest = $this->requestStack->getCurrentRequest();

if (!$scheme) {
$scheme = $this->defaultScheme;
$scheme = $currentRequest ? $currentRequest->getScheme() : $this->defaultScheme;
}

if (false !== \strpos($portalUrl, '/')) {
Expand All @@ -479,7 +481,6 @@ private function createResourceLocatorUrl($portalUrl, $resourceLocator, $scheme
$url = \rtrim(\sprintf('%s://%s', $scheme, $portalUrl), '/') . $resourceLocator;

// add port if url points to host of current request and current request uses a custom port
$currentRequest = $this->requestStack->getCurrentRequest();
if ($currentRequest) {
$host = $currentRequest->getHost();
$port = $currentRequest->getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,24 @@ public function testFindUrlsByResourceLocatorWithSchemeNull()
$this->assertEquals(['http://sulu.lo/test'], $result);
}

public function testFindUrlsByResourceLocatorWithSchemeFromRequest()
{
$request = $this->prophesize(Request::class);
$request->getHost()->willReturn('massiveart.lo');
$request->getPort()->willReturn(8080);
$request->getScheme()->willReturn('https');
$this->requestStack->getCurrentRequest()->willReturn($request->reveal());

$result = $this->webspaceManager->findUrlsByResourceLocator('/test', 'dev', 'en_us', 'massiveart');

$this->assertCount(2, $result);
$this->assertContains('https://massiveart.lo:8080/en-us/w/test', $result);
$this->assertContains('https://massiveart.lo:8080/en-us/s/test', $result);

$result = $this->webspaceManager->findUrlsByResourceLocator('/test', 'dev', 'de_at', 'sulu_io');
$this->assertEquals(['https://sulu.lo/test'], $result);
}

public function testFindUrlsByResourceLocatorRoot()
{
$result = $this->webspaceManager->findUrlsByResourceLocator('/', 'dev', 'en_us', 'massiveart');
Expand Down

0 comments on commit 0df2f39

Please sign in to comment.