Completed
Pull Request — master (#69)
by Raúl
02:30 queued 01:17
created

ReadPoTest   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 228
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 17
lcom 1
cbo 2
dl 0
loc 228
rs 10
c 6
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testBasic() 0 15 1
A testBasicMultiline() 0 10 1
A testBasicCollection() 0 16 1
A testEntriesWithContext() 0 13 1
A testPlurals() 0 15 1
A testPluralsMultiline() 0 15 1
A testFlags() 0 11 1
A testTranslatorComment() 0 11 1
A testTranslatorWithNoPreSpace() 0 8 1
A testDeveloperComment() 0 8 1
A testPreviousUntranslated() 0 13 1
A testPreviousUntranslatedMultiline() 0 12 1
A testMultilineEntries() 0 18 1
A testNoHeader() 0 6 1
B testHeaders() 0 29 2
A testNoBlankLinesSeparatingEntries() 0 6 1
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 testTranslatorWithNoPreSpace()
125
    {
126
        $catalog = $this->parseFile('commentWithNoSpace.po');
127
        $entry = $catalog->getEntry('test');
128
129
        $this->assertNotNull($entry);
130
        $this->assertEquals(array('index.ctp:101'), $entry->getTranslatorComments());
131
    }
132
133
    public function testDeveloperComment()
134
    {
135
        $catalog = $this->parseFile('codeComments.po');
136
        $entry = $catalog->getEntry('string.1');
137
138
        $this->assertNotNull($entry);
139
        $this->assertEquals(array('code comment', 'code translator comment'), $entry->getDeveloperComments());
140
    }
141
142
143
    public function testPreviousUntranslated()
144
    {
145
        $catalog = $this->parseFile('previous_unstranslated.po');
146
147
        $this->assertCount(1, $catalog->getEntries());
148
149
        $entry = new Entry('this is a string', 'this is a translation');
150
        $entry->setPreviousEntry(new Entry('this is a previous string', 'this is a previous translation string'));
151
        $this->assertEquals(
152
            $entry,
153
            $catalog->getEntry('this is a string')
154
        );
155
    }
156
157
    public function testPreviousUntranslatedMultiline()
158
    {
159
        $catalog = $this->parseFile('previousStringMultiline.po');
160
161
        $entry = $catalog->getEntry('this is a string');
162
        $this->assertNotNull($entry);
163
164
        $previous = $entry->getPreviousEntry();
165
        $this->assertNotNull($previous);
166
        $this->assertEquals('this is a previous string', $previous->getMsgId());
167
        $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());
168
    }
169
170
171
172
173
    public function testMultilineEntries()
174
    {
175
        $catalog = $this->parseFile('multilines.po');
176
177
        $longMsgId = '%user% acaba de responder tu comentario.<br>Consulta que te ha dicho %link%aquí</a>.';
178
179
        $entryExpected = new Entry(
180
            $longMsgId,
181
            '%user% acaba de respondre el teu comentari.<br>Consulta que t\'ha dit %link%aquí</a>.'
182
        );
183
        $entryExpected->setReference(
184
            array('../../classes/controller/ccccc.php:361')
185
        );
186
187
        $entry = $catalog->getEntry($longMsgId);
188
        $this->assertNotNull($entry);
189
        $this->assertEquals($entryExpected, $entry);
190
    }
191
192
    public function testNoHeader()
193
    {
194
        $catalog = $this->parseFile('noheader.po');
195
196
        $this->assertCount(2, $catalog->getEntries());
197
    }
198
199
    public function testHeaders()
200
    {
201
        try {
202
            $catalog = $this->parseFile('healthy.po');
203
            $headers = $catalog->getHeaders();
204
205
            $this->assertCount(18, $headers);
206
            $this->assertEquals('Project-Id-Version: ', $headers[0]);
207
            $this->assertEquals('Report-Msgid-Bugs-To: ', $headers[1]);
208
            $this->assertEquals('POT-Creation-Date: 2013-09-25 15:55+0100', $headers[2]);
209
            $this->assertEquals('PO-Revision-Date: ', $headers[3]);
210
            $this->assertEquals('Last-Translator: Raúl Ferràs <[email protected]>', $headers[4]);
211
            $this->assertEquals('Language-Team: ', $headers[5]);
212
            $this->assertEquals('MIME-Version: 1.0', $headers[6]);
213
            $this->assertEquals('Content-Type: text/plain; charset=UTF-8', $headers[7]);
214
            $this->assertEquals('Content-Transfer-Encoding: 8bit', $headers[8]);
215
            $this->assertEquals('Plural-Forms: nplurals=2; plural=n != 1;', $headers[9]);
216
            $this->assertEquals('X-Poedit-SourceCharset: UTF-8', $headers[10]);
217
            $this->assertEquals('X-Poedit-KeywordsList: __;_e;_n;_t', $headers[11]);
218
            $this->assertEquals('X-Textdomain-Support: yes', $headers[12]);
219
            $this->assertEquals('X-Poedit-Basepath: .', $headers[13]);
220
            $this->assertEquals('X-Generator: Poedit 1.5.7', $headers[14]);
221
            $this->assertEquals('X-Poedit-SearchPath-0: .', $headers[15]);
222
            $this->assertEquals('X-Poedit-SearchPath-1: ../..', $headers[16]);
223
            $this->assertEquals('X-Poedit-SearchPath-2: ../../../modules', $headers[17]);
224
        } catch (\Exception $e) {
225
            $this->fail($e->getMessage());
226
        }
227
    }
228
229
    public function testNoBlankLinesSeparatingEntries()
230
    {
231
        $catalog = $this->parseFile('noblankline.po');
232
233
        $this->assertCount(2, $catalog->getEntries());
234
    }
235
}
236