1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Tests\Twig\Extension; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\AdminBundle\Templating\TemplateRegistryInterface; |
18
|
|
|
use Sonata\AdminBundle\Twig\Extension\TemplateRegistryExtension; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
20
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
21
|
|
|
use Twig\TwigFunction; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class TemplateRegistryExtensionTest. |
25
|
|
|
*/ |
26
|
|
|
class TemplateRegistryExtensionTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var TemplateRegistryExtension |
30
|
|
|
*/ |
31
|
|
|
private $extension; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var TemplateRegistryInterface |
35
|
|
|
*/ |
36
|
|
|
private $templateRegistry; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ContainerInterface |
40
|
|
|
*/ |
41
|
|
|
private $container; |
42
|
|
|
|
43
|
|
|
protected function setUp(): void |
44
|
|
|
{ |
45
|
|
|
$this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class); |
46
|
|
|
$this->container = $this->prophesize(ContainerInterface::class); |
47
|
|
|
|
48
|
|
|
$this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig'); |
49
|
|
|
|
50
|
|
|
$this->extension = new TemplateRegistryExtension( |
51
|
|
|
$this->templateRegistry->reveal(), |
52
|
|
|
$this->container->reveal() |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getFunctionsTest(): void |
57
|
|
|
{ |
58
|
|
|
$expected = [ |
59
|
|
|
new TwigFunction('get_admin_template', [$this->extension, 'getAdminTemplate']), |
60
|
|
|
new TwigFunction('get_global_template', [$this->extension, 'getGlobalTemplate']), |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
$this->assertSame($expected, $this->extension->getFunctions()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetAdminTemplate(): void |
67
|
|
|
{ |
68
|
|
|
$this->container->get('admin.post.template_registry')->willReturn($this->templateRegistry->reveal()); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$this->assertSame( |
71
|
|
|
'@SonataAdmin/CRUD/edit.html.twig', |
72
|
|
|
$this->extension->getAdminTemplate('edit', 'admin.post') |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testGetAdminTemplateFailure(): void |
77
|
|
|
{ |
78
|
|
|
$this->container->get('admin.post.template_registry')->willReturn(null); |
79
|
|
|
|
80
|
|
|
$this->expectException(ServiceNotFoundException::class); |
81
|
|
|
|
82
|
|
|
$this->expectExceptionMessage('You have requested a non-existent service "admin.post.template_registry"'); |
83
|
|
|
|
84
|
|
|
$this->assertSame( |
85
|
|
|
'@SonataAdmin/CRUD/edit.html.twig', |
86
|
|
|
$this->extension->getAdminTemplate('edit', 'admin.post') |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testGetGlobalTemplate(): void |
91
|
|
|
{ |
92
|
|
|
$this->assertSame( |
93
|
|
|
'@SonataAdmin/CRUD/edit.html.twig', |
94
|
|
|
$this->extension->getGlobalTemplate('edit') |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.