Passed
Push — master ( 283335...4a2fc2 )
by Fran
18:22 queued 08:26
created

TemplateTest::testTemplateBasics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 34
rs 9.552
c 0
b 0
f 0
1
<?php
2
3
namespace PSFS\tests\base;
4
5
use PHPUnit\Framework\TestCase;
6
use PSFS\base\config\Config;
7
use PSFS\base\Template;
8
9
/**
10
 * Class TemplateTest
11
 * @package PSFS\tests
12
 */
13
class TemplateTest extends TestCase
14
{
15
16
    /**
17
     * @return void
18
     */
19
    public function testTemplateBasics()
20
    {
21
        $template = Template::getInstance();
22
23
        // Check if the template engine is ok
24
        $engine = $template->getTemplateEngine();
25
        $this->assertNotNull($engine, 'Error at Template creation');
26
        $this->assertInstanceOf('\\Twig\\Environment', $engine);
27
28
        // Check if the template loader is ok
29
        $loader = $template->getLoader();
30
        $this->assertNotNull($loader, 'Error at Template creation');
31
        $this->assertInstanceOf('\\Twig\\Loader\\LoaderInterface', $loader);
32
33
        $domains = Template::getDomains(true);
34
        $this->assertNotNull($domains);
35
36
        $path = Template::extractPath(__DIR__);
37
        $this->assertNotNull($path);
38
        $this->assertFileExists($path);
39
40
        Config::getInstance()->setDebugMode();
41
        $output = $template->dump('index.html.twig');
42
        $this->assertNotNull($output);
43
        $this->assertNotEmpty($output);
44
45
        Config::getInstance()->setDebugMode(false);
46
        $output2 = $template->dump('index.html.twig');
47
        $this->assertNotNull($output2);
48
        $this->assertNotEmpty($output2);
49
        $this->assertNotEquals($output2, $output, 'Production template is the same than development one');
50
        Config::getInstance()->setDebugMode(true);
51
52
        $this->assertEquals('/admin/translations/es', $template->getRoute('admin-translations-locale', false, ['locale' => 'es']), 'Route is not the same that expected');
53
    }
54
55
    /**
56
     * @return void
57
     */
58
    public function testTranslations()
59
    {
60
        $template = Template::getInstance();
61
62
        $template->setPublicZone(true);
63
        $this->assertTrue($template->isPublicZone());
64
        $template->setPublicZone(false);
65
        $this->assertFalse($template->isPublicZone());
66
67
        $translations = $template->regenerateTemplates();
68
        $this->assertNotNull($translations);
69
        $this->assertNotEmpty($translations);
70
    }
71
}
72