1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\Fragment; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\Core\MVC\Symfony\Component\Serializer\SerializerTrait; |
10
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
13
|
|
|
use Symfony\Component\HttpKernel\Controller\ControllerReference; |
14
|
|
|
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; |
15
|
|
|
|
16
|
|
|
abstract class FragmentRendererBaseTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
use SerializerTrait; |
19
|
|
|
|
20
|
|
|
public function testRendererControllerReferenceWithCompoundMatcher(): ControllerReference |
21
|
|
|
{ |
22
|
|
|
$reference = new ControllerReference('FooBundle:bar:baz'); |
23
|
|
|
$compoundMatcher = new SiteAccess\Matcher\Compound\LogicalAnd([]); |
24
|
|
|
$subMatchers = [ |
25
|
|
|
'Map\URI' => new SiteAccess\Matcher\Map\URI([]), |
26
|
|
|
'Map\Host' => new SiteAccess\Matcher\Map\Host([]), |
27
|
|
|
]; |
28
|
|
|
$compoundMatcher->setSubMatchers($subMatchers); |
29
|
|
|
$siteAccess = new SiteAccess( |
30
|
|
|
'test', |
31
|
|
|
'test', |
32
|
|
|
$compoundMatcher |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$request = $this->getRequest($siteAccess); |
36
|
|
|
$options = ['foo' => 'bar']; |
37
|
|
|
$expectedReturn = '/_fragment?foo=bar'; |
38
|
|
|
$this->innerRenderer |
|
|
|
|
39
|
|
|
->expects($this->once()) |
40
|
|
|
->method('render') |
41
|
|
|
->with($reference, $request, $options) |
42
|
|
|
->will($this->returnValue($expectedReturn)); |
43
|
|
|
|
44
|
|
|
$renderer = $this->getRenderer(); |
45
|
|
|
$this->assertSame($expectedReturn, $renderer->render($reference, $request, $options)); |
46
|
|
|
$this->assertArrayHasKey('serialized_siteaccess', $reference->attributes); |
47
|
|
|
$serializedSiteAccess = json_encode($siteAccess); |
48
|
|
|
$this->assertSame($serializedSiteAccess, $reference->attributes['serialized_siteaccess']); |
49
|
|
|
$this->assertArrayHasKey('serialized_siteaccess_matcher', $reference->attributes); |
50
|
|
|
$this->assertSame( |
51
|
|
|
$this->getSerializer()->serialize( |
52
|
|
|
$siteAccess->matcher, |
53
|
|
|
'json' |
54
|
|
|
), |
55
|
|
|
$reference->attributes['serialized_siteaccess_matcher'] |
56
|
|
|
); |
57
|
|
|
$this->assertArrayHasKey('serialized_siteaccess_sub_matchers', $reference->attributes); |
58
|
|
|
foreach ($siteAccess->matcher->getSubMatchers() as $subMatcher) { |
|
|
|
|
59
|
|
|
$this->assertSame( |
60
|
|
|
$this->getSerializer()->serialize( |
61
|
|
|
$subMatcher, |
62
|
|
|
'json' |
63
|
|
|
), |
64
|
|
|
$reference->attributes['serialized_siteaccess_sub_matchers'][get_class($subMatcher)] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $reference; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
abstract public function getRequest(SiteAccess $siteAccess): Request; |
72
|
|
|
|
73
|
|
|
abstract public function getRenderer(): FragmentRendererInterface; |
74
|
|
|
} |
75
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: