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
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\Templating\Tests\Twig\Extension; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content as APIContent; |
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location as APILocation; |
14
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator; |
15
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGeneratorInterface; |
16
|
|
|
use eZ\Publish\Core\MVC\Symfony\Routing\RouteReference; |
17
|
|
|
use eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\RoutingExtension; |
18
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
19
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Location; |
20
|
|
|
use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
21
|
|
|
use stdClass; |
22
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
23
|
|
|
use Symfony\Component\HttpFoundation\Request; |
24
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
25
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
26
|
|
|
use Twig\Test\IntegrationTestCase; |
27
|
|
|
|
28
|
|
|
final class RoutingExtensionTest extends IntegrationTestCase |
29
|
|
|
{ |
30
|
|
|
protected function getExtensions(): array |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
new RoutingExtension( |
34
|
|
|
$this->getRouteReferenceGenerator(), |
35
|
|
|
$this->getUrlGenerator() |
36
|
|
|
), |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function getFixturesDir(): string |
41
|
|
|
{ |
42
|
|
|
return __DIR__ . '/_fixtures/routing_functions'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getExampleContent(int $id): APIContent |
46
|
|
|
{ |
47
|
|
|
return new Content([ |
48
|
|
|
'versionInfo' => new VersionInfo([ |
49
|
|
|
'contentInfo' => $this->getExampleContentInfo($id), |
50
|
|
|
]), |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function getExampleContentInfo(int $id): ContentInfo |
55
|
|
|
{ |
56
|
|
|
return new ContentInfo([ |
57
|
|
|
'id' => $id, |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function getExampleLocation(int $id): APILocation |
62
|
|
|
{ |
63
|
|
|
return new Location(['id' => $id]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function getExampleRouteReference($name, array $parameters = []): RouteReference |
67
|
|
|
{ |
68
|
|
|
return new RouteReference($name, $parameters); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getExampleUnsupportedObject(): object |
72
|
|
|
{ |
73
|
|
|
$object = new stdClass(); |
74
|
|
|
$object->foo = 'foo'; |
75
|
|
|
$object->bar = 'bar'; |
76
|
|
|
|
77
|
|
|
return $object; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function getRouteReferenceGenerator(): RouteReferenceGeneratorInterface |
81
|
|
|
{ |
82
|
|
|
$generator = new RouteReferenceGenerator( |
83
|
|
|
$this->createMock(EventDispatcherInterface::class) |
84
|
|
|
); |
85
|
|
|
$request = new Request(); |
86
|
|
|
$requestStack = new RequestStack(); |
87
|
|
|
$requestStack->push($request); |
88
|
|
|
$generator->setRequestStack($requestStack); |
89
|
|
|
|
90
|
|
|
return $generator; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function getUrlGenerator(): UrlGeneratorInterface |
94
|
|
|
{ |
95
|
|
|
$generator = $this->createMock(UrlGeneratorInterface::class); |
96
|
|
|
$generator |
|
|
|
|
97
|
|
|
->method('generate') |
98
|
|
|
->willReturnCallback(static function ($name, $parameters, $referenceType): string { |
99
|
|
|
return json_encode([ |
100
|
|
|
'$name' => $name, |
101
|
|
|
'$parameters' => $parameters, |
102
|
|
|
'$referenceType' => $referenceType, |
103
|
|
|
]); |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
return $generator; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.