summaryrefslogtreecommitdiff
path: root/tests/Unit/Renderer/Twig/Extensions/TranslationTest.php
blob: 187056833b60fc13099d5a7a4f8c7ceffa870306 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;

use Engelsystem\Helpers\Translator;
use Engelsystem\Renderer\Twig\Extensions\Translation;
use PHPUnit\Framework\MockObject\MockObject;
use Twig_Extensions_TokenParser_Trans as TranslationTokenParser;

class TranslationTest extends ExtensionTest
{
    /**
     * @covers \Engelsystem\Renderer\Twig\Extensions\Translation::__construct
     * @covers \Engelsystem\Renderer\Twig\Extensions\Translation::getFilters
     */
    public function testGeFilters()
    {
        /** @var Translator|MockObject $translator */
        $translator = $this->createMock(Translator::class);
        /** @var TranslationTokenParser|MockObject $parser */
        $parser = $this->createMock(TranslationTokenParser::class);

        $extension = new Translation($translator, $parser);
        $filters = $extension->getFilters();

        $this->assertExtensionExists('trans', [$translator, 'translate'], $filters);
    }

    /**
     * @covers \Engelsystem\Renderer\Twig\Extensions\Translation::getFunctions
     */
    public function testGetFunctions()
    {
        /** @var Translator|MockObject $translator */
        $translator = $this->createMock(Translator::class);
        /** @var TranslationTokenParser|MockObject $parser */
        $parser = $this->createMock(TranslationTokenParser::class);

        $extension = new Translation($translator, $parser);
        $functions = $extension->getFunctions();

        $this->assertExtensionExists('__', [$translator, 'translate'], $functions);
        $this->assertExtensionExists('_e', [$translator, 'translatePlural'], $functions);
    }

    /**
     * @covers \Engelsystem\Renderer\Twig\Extensions\Translation::getTokenParsers
     */
    public function testGetTokenParsers()
    {
        /** @var Translator|MockObject $translator */
        $translator = $this->createMock(Translator::class);
        /** @var TranslationTokenParser|MockObject $parser */
        $parser = $this->createMock(TranslationTokenParser::class);

        $extension = new Translation($translator, $parser);
        $tokenParsers = $extension->getTokenParsers();

        $this->assertTokenParserExists($parser, $tokenParsers);
    }
}