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