Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/6.13' into 7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mikadamczyk committed Jun 8, 2020
2 parents 79049c7 + c0efbbe commit 89df781
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 35 deletions.
4 changes: 4 additions & 0 deletions eZ/Bundle/EzPublishCoreBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ services:
tags:
- { name: kernel.event_subscriber }

eZ\Publish\Core\MVC\Symfony\Component\Serializer\CompoundMatcherNormalizer:
tags:
- { name: serializer.normalizer }

ezpublish.url_generator.base:
class: "%ezpublish.url_generator.base.class%"
abstract: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\MVC\Symfony\Component\Serializer;

use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;

class CompoundMatcherNormalizer extends PropertyNormalizer
{
public function normalize($object, $format = null, array $context = [])
{
$data = parent::normalize($object, $format, $context);
$data['config'] = [];
$data['matchersMap'] = [];

return $data;
}

public function supportsNormalization($data, $format = null)
{
return $data instanceof Matcher\Compound;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ trait SerializerTrait
public function getSerializer(): SerializerInterface
{
return new Serializer(
[(new PropertyNormalizer())->setIgnoredAttributes(['request', 'container', 'matcherBuilder'])],
[
new CompoundMatcherNormalizer(),
(new PropertyNormalizer())->setIgnoredAttributes(['request', 'container', 'matcherBuilder']),
],
[new JsonEncoder()]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ class MatcherSerializationTest extends TestCase
use SerializerTrait;

/**
* @param \eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher|null $expected
*
* @dataProvider matcherProvider
*/
public function testDeserialize(Matcher $matcher)
public function testDeserialize(Matcher $matcher, $expected = null)
{
$serializedMatcher = $this->serializeMatcher($matcher);
$unserializedMatcher = $this->deserializeMatcher($serializedMatcher, get_class($matcher));
$expected = $expected ?? $matcher;

$this->assertEquals($matcher, $unserializedMatcher);
$this->assertEquals($expected, $unserializedMatcher);
}

/**
* @param \eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher $matcher
*
* @return string
*/
private function serializeMatcher(Matcher $matcher)
Expand Down Expand Up @@ -55,6 +56,36 @@ private function deserializeMatcher($serializedMatcher, $matcherFQCN)

public function matcherProvider()
{
$subMatchers = [
'Map\URI' => [
'map' => ['key' => 'value'],
],
'Map\Host' => [
'map' => ['key' => 'value'],
],
];
$logicalAnd = new Matcher\Compound\LogicalAnd(
[
[
'match' => 'site_access_name',
],
]
);
$logicalAnd->setSubMatchers($subMatchers);
$expectedLogicalAnd = new Matcher\Compound\LogicalAnd([]);
$expectedLogicalAnd->setSubMatchers($subMatchers);

$logicalOr = new Matcher\Compound\LogicalOr(
[
[
'match' => 'site_access_name',
],
]
);
$logicalOr->setSubMatchers($subMatchers);
$expectedLogicalOr = new Matcher\Compound\LogicalOr([]);
$expectedLogicalOr->setSubMatchers($subMatchers);

return [
'URIText' => [
new Matcher\URIText([
Expand Down Expand Up @@ -106,38 +137,12 @@ public function matcherProvider()
]),
],
'CompoundAnd' => [
new Matcher\Compound\LogicalAnd(
[
[
'matchers' => [
'Map\URI' => [
'map' => ['key' => 'value'],
],
'Map\Host' => [
'map' => ['key' => 'value'],
],
],
'match' => 'site_access_name',
],
]
),
$logicalAnd,
$expectedLogicalAnd,
],
'CompoundOr' => [
new Matcher\Compound\LogicalOr(
[
[
'matchers' => [
'Map\URI' => [
'map' => ['key' => 'value'],
],
'Map\Host' => [
'map' => ['key' => 'value'],
],
],
'match' => 'site_access_name',
],
]
),
$logicalOr,
$expectedLogicalOr,
],
];
}
Expand Down

0 comments on commit 89df781

Please sign in to comment.