Completed
Push — feature/5.0.1 ( ac6a3e...d50cc3 )
by Raúl
01:16
created

ReadPoTest::testHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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