Completed
Pull Request — master (#5032)
by Grégoire
03:41
created

TemplateRegistryTest::testGetTemplate1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
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