Completed
Push — 150-JMSTranslationBundle-route... ( e8ef1a...dfc3b3 )
by
unknown
126:53 queued 61:56
created

FrameworkExtensionTest::testGetName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\Tests\Twig;
4
5
use SumoCoders\FrameworkCoreBundle\Twig\FrameworkExtension;
6
7
class FrameworkExtensionTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var FrameworkExtension
11
     */
12
    protected $frameworkExtension;
13
14
    /**
15
     * @inherit
16
     */
17
    protected function setUp()
18
    {
19
        $this->frameworkExtension = new FrameworkExtension(
20
            $this->getContainer()
21
        );
22
    }
23
24
    /**
25
     * @return \PHPUnit_Framework_MockObject_MockObject
26
     */
27
    protected function getContainer()
28
    {
29
        $container = $this->getMock('\Symfony\Component\DependencyInjection\ContainerInterface');
30
        $container->method('getParameter')
31
            ->will(
32
                $this->returnValue(
33
                    array(
34
                        'existing' => null,
35
                    )
36
                )
37
            );
38
39
        return $container;
40
    }
41
42
    /**
43
     * @inherit
44
     */
45
    protected function tearDown()
46
    {
47
        $this->frameworkExtension = null;
48
    }
49
50
    /**
51
     * Test FrameworkExtension->getFunctions()
52
     */
53
    public function testGetFunctions()
54
    {
55
        $var = $this->frameworkExtension->getFunctions();
56
        $this->assertInternalType('array', $var);
57
58
        $containsBundleExists = false;
59
        foreach ($var as $function) {
60
            /** @var \Twig_SimpleFunction $function */
61
            if ($function->getName() == 'bundleExists') {
62
                $containsBundleExists = true;
63
            }
64
        }
65
        $this->assertTrue($containsBundleExists, 'bundleExists-function not found');
66
    }
67
68
    public function testBundleExists()
69
    {
70
        $this->assertTrue($this->frameworkExtension->bundleExists('existing'), 'existing bundle not found');
71
        $this->assertFalse($this->frameworkExtension->bundleExists('non-existing'), 'non-existing bundle found');
72
    }
73
74
    public function testConvertToTranslationTrim()
75
    {
76
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation(' foo'));
77
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo '));
78
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation(' foo '));
79
    }
80
81 View Code Duplication
    public function testConvertToTranslationToLowerCase()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo'));
84
        $this->assertEquals('FOO', $this->frameworkExtension->convertToTranslation('FOO'));
85
        $this->assertEquals('FoO', $this->frameworkExtension->convertToTranslation('FoO'));
86
        $this->assertEquals('fOo', $this->frameworkExtension->convertToTranslation('fOo'));
87
    }
88
89
    public function testConvertToTranslationReplaceFakeSpaces()
90
    {
91
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f_o_o'));
92
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f-o-o'));
93
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f o o'));
94
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f_o_o_'));
95
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('_f_o_o'));
96
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('_f_o_o_'));
97
    }
98
99
    public function testTranslationWithNumbersAtTheEnd()
100
    {
101
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo1'));
102
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo123'));
103
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo 123'));
104
    }
105
106 View Code Duplication
    public function testTranslationWithSumoCodersInTheString()
107
    {
108
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('SumoCoders.foo'));
109
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('sumocoders.foo'));
110
        $this->assertEquals('foo.sumocoders', $this->frameworkExtension->convertToTranslation('foo.sumocoders'));
111
        $this->assertEquals('foo.bar', $this->frameworkExtension->convertToTranslation('SumoCoders.foo.bar'));
112
    }
113
114
    public function testTranslationWithBundleInTheString()
115
    {
116
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('fooBundle'));
117
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo.frameworkBundle'));
118
        $this->assertEquals('Foo.bar', $this->frameworkExtension->convertToTranslation('FooBundle.bar'));
119
        $this->assertEquals('Foo.bar', $this->frameworkExtension->convertToTranslation('Foo.barBundle'));
120
    }
121
122
    public function testTranslationWithDotsInTheString()
123
    {
124
        $this->assertEquals('foo.bar', $this->frameworkExtension->convertToTranslation('foo.......bar'));
125
    }
126
127
    public function testTranslationsWithNumbersAsSingleItems()
128
    {
129
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f_1_o_o'));
130
    }
131
132
    public function testIfFrameworkIsRemoved()
133
    {
134
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('framework_foo'));
135
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('framework_foo_framework'));
136
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo_framework'));
137
    }
138
139
    public function testIfBundleIsCleaned()
140
    {
141
        $this->assertEquals(
142
            'Core.foo',
143
            $this->frameworkExtension->convertToTranslation('SumoCoders_FrameworkCoreBundle_foo')
144
        );
145
        $this->assertEquals(
146
            'Namespace.NameOfThe.foo',
147
            $this->frameworkExtension->convertToTranslation('Namespace_NameOfTheBundle_foo')
148
        );
149
    }
150
}
151