|
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\Templating; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Sonata\AdminBundle\Templating\TemplateRegistry; |
|
16
|
|
|
|
|
17
|
|
|
class TemplateRegistryTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var TemplateRegistry |
|
21
|
|
|
*/ |
|
22
|
|
|
private $templateRegistry; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->templateRegistry = new TemplateRegistry(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetTemplates() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->assertSame([], $this->templateRegistry->getTemplates()); |
|
32
|
|
|
|
|
33
|
|
|
$templates = [ |
|
34
|
|
|
'list' => '@FooAdmin/CRUD/list.html.twig', |
|
35
|
|
|
'show' => '@FooAdmin/CRUD/show.html.twig', |
|
36
|
|
|
'edit' => '@FooAdmin/CRUD/edit.html.twig', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
$this->templateRegistry->setTemplates($templates); |
|
40
|
|
|
$this->assertSame($templates, $this->templateRegistry->getTemplates()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testGetTemplate1() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->assertNull($this->templateRegistry->getTemplate('edit')); |
|
46
|
|
|
|
|
47
|
|
|
$this->templateRegistry->setTemplate('edit', '@FooAdmin/CRUD/edit.html.twig'); |
|
48
|
|
|
$this->templateRegistry->setTemplate('show', '@FooAdmin/CRUD/show.html.twig'); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame('@FooAdmin/CRUD/edit.html.twig', $this->templateRegistry->getTemplate('edit')); |
|
51
|
|
|
$this->assertSame('@FooAdmin/CRUD/show.html.twig', $this->templateRegistry->getTemplate('show')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testGetTemplate2() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertNull($this->templateRegistry->getTemplate('edit')); |
|
57
|
|
|
|
|
58
|
|
|
$templates = [ |
|
59
|
|
|
'list' => '@FooAdmin/CRUD/list.html.twig', |
|
60
|
|
|
'show' => '@FooAdmin/CRUD/show.html.twig', |
|
61
|
|
|
'edit' => '@FooAdmin/CRUD/edit.html.twig', |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
$this->templateRegistry->setTemplates($templates); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertSame('@FooAdmin/CRUD/edit.html.twig', $this->templateRegistry->getTemplate('edit')); |
|
67
|
|
|
$this->assertSame('@FooAdmin/CRUD/show.html.twig', $this->templateRegistry->getTemplate('show')); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|