Completed
Pull Request — master (#71)
by
unknown
01:22
created

ReadPoTest::testPreviousStringMultiline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Sepia\Test\UnitTest;
4
5
use Sepia\PoParser\Catalog\Entry;
6
use Sepia\Test\AbstractFixtureTest;
7
8
class ReadPoTest extends AbstractFixtureTest
9
{
10
    public function testBasic()
11
    {
12
        $catalog = $this->parseFile('basic.po');
13
14
        $entry = $catalog->getEntry('string.1');
15
16
        $this->assertNotNull($entry);
17
        $this->assertEquals('string.1', $entry->getMsgId());
18
        $this->assertEquals('translation.1', $entry->getMsgStr());
19
20
        $entry = $catalog->getEntry('string.2');
21
        $this->assertNotNull($entry);
22
        $this->assertEquals('string.2', $entry->getMsgId());
23
        $this->assertEquals('translation \"quoted\"', $entry->getMsgStr());
24
    }
25
26
    public function testBasicMultiline()
27
    {
28
        $catalog = $this->parseFile('basicMultiline.po');
29
30
        $entry = $catalog->getEntry('string.1');
31
32
        $this->assertNotNull($entry);
33
        $this->assertEquals('string.1', $entry->getMsgId());
34
        $this->assertEquals('translation line 1 translation line 2', $entry->getMsgStr());
35
    }
36
37
    public function testBasicCollection()
38
    {
39
        $catalog = $this->parseFile('basicCollection.po');
40
41
        $this->assertCount(2, $catalog->getEntries());
42
43
        $entry = $catalog->getEntry('string.1');
44
        $this->assertNotNull($entry);
45
        $this->assertEquals('string.1', $entry->getMsgId());
46
        $this->assertEquals('translation.1', $entry->getMsgStr());
47
48
        $entry = $catalog->getEntry('string.2');
49
        $this->assertNotNull($entry);
50
        $this->assertEquals('string.2', $entry->getMsgId());
51
        $this->assertEquals('translation.2', $entry->getMsgStr());
52
    }
53
54
    public function testEntriesWithContext()
55
    {
56
        $catalog = $this->parseFile('context.po');
57
58
        $withContext = $catalog->getEntry('string.1', 'register');
59
        $this->assertNotNull($withContext);
60
        $this->assertEquals('register', $withContext->getMsgCtxt());
61
62
        $withoutContext = $catalog->getEntry('string.1');
63
        $this->assertNotNull($withoutContext);
64
        $this->assertEmpty($withoutContext->getMsgCtxt());
65
        $this->assertNotEquals($withContext, $withoutContext);
66
    }
67
68
    public function testPlurals()
69
    {
70
        $catalog = $this->parseFile('plurals.po');
71
72
        $entry = $catalog->getEntry('%s post not updated, somebody is editing it.');
73
        $this->assertNotNull($entry);
74
        $this->assertNotEmpty($entry->getMsgStrPlurals());
75
        $this->assertEquals(
76
            array(
77
                '%s entrada no actualizada, alguien la está editando.',
78
                '%s entradas no actualizadas, alguien las está editando.',
79
            ),
80
            $entry->getMsgStrPlurals()
81
        );
82
    }
83
84
    public function testPluralsMultiline()
85
    {
86
        $catalog = $this->parseFile('pluralsMultiline.po');
87
        $entry = $catalog->getEntry('%s post not updated,somebody is editing it.');
88
89
        $this->assertNotNull($entry);
90
        $this->assertNotEmpty($entry->getMsgStrPlurals());
91
        $this->assertEquals(
92
            array(
93
                '%s entrada no actualizada,alguien la está editando.',
94
                '%s entradas no actualizadas,alguien las está editando.',
95
            ),
96
            $entry->getMsgStrPlurals()
97
        );
98
    }
99
    
100
    public function testFlags()
101
    {
102
        $catalog = $this->parseFile('multiflags.po');
103
104
        $this->assertCount(1, $catalog->getEntries());
105
        $entry = $catalog->getEntry('Attachment', 'Background Attachment');
106
107
        $this->assertNotNull($entry);
108
        $this->assertCount(2, $entry->getFlags());
109
        $this->assertEquals(array('php-format', 'fuzzy'), $entry->getFlags());
110
    }
111
112
    public function testTranslatorComment()
113
    {
114
        $catalog = $this->parseFile('translatorComments.po');
115
        $entry = $catalog->getEntry('string.1');
116
117
        $this->assertNotNull($entry);
118
        $this->assertEquals(
119
            array('translator comment', 'second translator comment'),
120
            $entry->getTranslatorComments()
121
        );
122
    }
123
124
    public function testDeveloperComment()
125
    {
126
        $catalog = $this->parseFile('codeComments.po');
127
        $entry = $catalog->getEntry('string.1');
128
129
        $this->assertNotNull($entry);
130
        $this->assertEquals(array('code comment', 'code translator comment'), $entry->getDeveloperComments());
131
    }
132
133
    public function testReferences()
134
    {
135
        $catalog = $this->parseFile('basicReference.po');
136
137
        $entry = $catalog->getEntry('string.1');
138
        $this->assertNotNull($entry);
139
        $this->assertEquals(array('src/views/forms.php:44'), $entry->getReference());
140
    }
141
142
    public function testPreviousString()
143
    {
144
        $catalog = $this->parseFile('previousString.po');
145
146
        $this->assertCount(1, $catalog->getEntries());
147
148
        $entry = new Entry('this is a string', 'this is a translation');
149
        $entry->setPreviousEntry(new Entry('this is a previous string', 'this is a previous translation string'));
150
        $this->assertEquals(
151
            $entry,
152
            $catalog->getEntry('this is a string')
153
        );
154
    }
155
156
    public function testPreviousStringMultiline()
157
    {
158
        $catalog = $this->parseFile('previousStringMultiline.po');
159
160
        $entry = $catalog->getEntry('this is a string');
161
        $this->assertNotNull($entry);
162
163
        $previous = $entry->getPreviousEntry();
164
        $this->assertNotNull($previous);
165
        $this->assertEquals('this is a previous string', $previous->getMsgId());
166
        $this->assertEquals('Doloribus nulla odit et aut est. Rerum molestiae pariatur suscipit unde in quidem alias alias. Ut ea omnis placeat rerum quae asperiores. Et recusandae praesentium ea.', $previous->getMsgStr());
167
    }
168
169
    public function testHeaders()
170
    {
171
        $catalog = $this->parseFile('basicHeader.po');
172
        $this->assertCount(1, $catalog->getEntries());
173
    }
174
175
    public function testOnlyCustomHeaders()
176
    {
177
        $catalog = $this->parseFile('basicCustomHeaders.po');
178
        $this->assertCount(1, $catalog->getEntries());
179
        $this->assertGreaterThanOrEqual(1, count($catalog->getHeaders()));
180
    }
181
182
    public function testHeadersMultiline()
183
    {
184
        $catalog = $this->parseFile('basicHeadersMultiline.po');
185
        $this->assertCount(1, $catalog->getEntries());
186
        $this->assertCount(3,$catalog->getHeaders());
187
    }
188
189
    public function testFileWithOnlyHeaders()
190
    {
191
        $catalog = $this->parseFile('basicOnlyHeader.po');
192
        $this->assertCount(0, $catalog->getEntries());
193
        $this->assertGreaterThanOrEqual(1, count($catalog->getHeaders()));
194
    }
195
196
    public function testNoBlankLinesSeparatingEntries()
197
    {
198
        $catalog = $this->parseFile('noblankline.po');
199
200
        $this->assertCount(2, $catalog->getEntries());
201
    }
202
}
203