Completed
Push — master ( dcf43c...59d132 )
by Tijs
06:54
created

testTranslationWithNumbersAtTheEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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
    /**
75
     * Test FrameworkExtension->getName()
76
     */
77
    public function testGetName()
78
    {
79
        $this->assertEquals('framework_extension', $this->frameworkExtension->getName());
80
    }
81
82
    public function testConvertToTranslationTrim()
83
    {
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 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...
90
    {
91
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo'));
92
        $this->assertEquals('FOO', $this->frameworkExtension->convertToTranslation('FOO'));
93
        $this->assertEquals('FoO', $this->frameworkExtension->convertToTranslation('FoO'));
94
        $this->assertEquals('fOo', $this->frameworkExtension->convertToTranslation('fOo'));
95
    }
96
97
    public function testConvertToTranslationReplaceFakeSpaces()
98
    {
99
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f_o_o'));
100
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f-o-o'));
101
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f o o'));
102
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f_o_o_'));
103
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('_f_o_o'));
104
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('_f_o_o_'));
105
    }
106
107
    public function testTranslationWithNumbersAtTheEnd()
108
    {
109
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo1'));
110
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo123'));
111
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo 123'));
112
    }
113
114 View Code Duplication
    public function testTranslationWithSumoCodersInTheString()
115
    {
116
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('SumoCoders.foo'));
117
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('sumocoders.foo'));
118
        $this->assertEquals('foo.sumocoders', $this->frameworkExtension->convertToTranslation('foo.sumocoders'));
119
        $this->assertEquals('foo.bar', $this->frameworkExtension->convertToTranslation('SumoCoders.foo.bar'));
120
    }
121
122
    public function testTranslationWithBundleInTheString()
123
    {
124
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('fooBundle'));
125
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo.frameworkBundle'));
126
        $this->assertEquals('Foo.bar', $this->frameworkExtension->convertToTranslation('FooBundle.bar'));
127
        $this->assertEquals('Foo.bar', $this->frameworkExtension->convertToTranslation('Foo.barBundle'));
128
    }
129
130
    public function testTranslationWithDotsInTheString()
131
    {
132
        $this->assertEquals('foo.bar', $this->frameworkExtension->convertToTranslation('foo.......bar'));
133
    }
134
135
    public function testTranslationsWithNumbersAsSingleItems()
136
    {
137
        $this->assertEquals('f.o.o', $this->frameworkExtension->convertToTranslation('f_1_o_o'));
138
    }
139
140
    public function testIfFrameworkIsRemoved()
141
    {
142
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('framework_foo'));
143
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('framework_foo_framework'));
144
        $this->assertEquals('foo', $this->frameworkExtension->convertToTranslation('foo_framework'));
145
    }
146
147
    public function testIfBundleIsCleaned()
148
    {
149
        $this->assertEquals(
150
            'Core.foo',
151
            $this->frameworkExtension->convertToTranslation('SumoCoders_FrameworkCoreBundle_foo')
152
        );
153
        $this->assertEquals(
154
            'Namespace.NameOfThe.foo',
155
            $this->frameworkExtension->convertToTranslation('Namespace_NameOfTheBundle_foo')
156
        );
157
    }
158
}
159