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