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
|
|
|
|
21
|
|
|
public function testBasicMultiline() |
22
|
|
|
{ |
23
|
|
|
$catalog = $this->parseFile('basicMultiline.po'); |
24
|
|
|
|
25
|
|
|
$entry = $catalog->getEntry('string.1'); |
26
|
|
|
|
27
|
|
|
$this->assertNotNull($entry); |
28
|
|
|
$this->assertEquals('string.1', $entry->getMsgId()); |
29
|
|
|
$this->assertEquals('translation line 1 translation line 2', $entry->getMsgStr()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testBasicCollection() |
33
|
|
|
{ |
34
|
|
|
$catalog = $this->parseFile('basicCollection.po'); |
35
|
|
|
|
36
|
|
|
$this->assertCount(2, $catalog->getEntries()); |
37
|
|
|
|
38
|
|
|
$entry = $catalog->getEntry('string.1'); |
39
|
|
|
$this->assertNotNull($entry); |
40
|
|
|
$this->assertEquals('string.1', $entry->getMsgId()); |
41
|
|
|
$this->assertEquals('translation.1', $entry->getMsgStr()); |
42
|
|
|
|
43
|
|
|
$entry = $catalog->getEntry('string.2'); |
44
|
|
|
$this->assertNotNull($entry); |
45
|
|
|
$this->assertEquals('string.2', $entry->getMsgId()); |
46
|
|
|
$this->assertEquals('translation.2', $entry->getMsgStr()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testEntriesWithContext() |
50
|
|
|
{ |
51
|
|
|
$catalog = $this->parseFile('context.po'); |
52
|
|
|
|
53
|
|
|
$withContext = $catalog->getEntry('string.1', 'register'); |
54
|
|
|
$this->assertNotNull($withContext); |
55
|
|
|
$this->assertEquals('register', $withContext->getMsgCtxt()); |
56
|
|
|
|
57
|
|
|
$withoutContext = $catalog->getEntry('string.1'); |
58
|
|
|
$this->assertNotNull($withoutContext); |
59
|
|
|
$this->assertEmpty($withoutContext->getMsgCtxt()); |
60
|
|
|
$this->assertNotEquals($withContext, $withoutContext); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testPlurals() |
64
|
|
|
{ |
65
|
|
|
$catalog = $this->parseFile('plurals.po'); |
66
|
|
|
|
67
|
|
|
$entry = $catalog->getEntry('%s post not updated, somebody is editing it.'); |
68
|
|
|
$this->assertNotNull($entry); |
69
|
|
|
$this->assertNotEmpty($entry->getMsgStrPlurals()); |
70
|
|
|
$this->assertEquals( |
71
|
|
|
array( |
72
|
|
|
'%s entrada no actualizada, alguien la está editando.', |
73
|
|
|
'%s entradas no actualizadas, alguien las está editando.', |
74
|
|
|
), |
75
|
|
|
$entry->getMsgStrPlurals() |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testFlags() |
80
|
|
|
{ |
81
|
|
|
$catalog = $this->parseFile('multiflags.po'); |
82
|
|
|
|
83
|
|
|
$this->assertCount(1, $catalog->getEntries()); |
84
|
|
|
$entry = $catalog->getEntry('Attachment', 'Background Attachment'); |
85
|
|
|
|
86
|
|
|
$this->assertNotNull($entry); |
87
|
|
|
$this->assertCount(2, $entry->getFlags()); |
88
|
|
|
$this->assertEquals(array('php-format', 'fuzzy'), $entry->getFlags()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testTranslatorComment() |
92
|
|
|
{ |
93
|
|
|
$catalog = $this->parseFile('healthy.po'); |
94
|
|
|
$entry = $catalog->getEntry('string.2'); |
95
|
|
|
|
96
|
|
|
$this->assertNotNull($entry); |
97
|
|
|
$this->assertEquals(array('Translator comment'), $entry->getTranslatorComments()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testTranslatorWithNoPreSpace() |
101
|
|
|
{ |
102
|
|
|
$catalog = $this->parseFile('commentWithNoSpace.po'); |
103
|
|
|
$entry = $catalog->getEntry('test'); |
104
|
|
|
|
105
|
|
|
$this->assertNotNull($entry); |
106
|
|
|
$this->assertEquals(array('index.ctp:101'), $entry->getTranslatorComments()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testDeveloperComment() |
110
|
|
|
{ |
111
|
|
|
$catalog = $this->parseFile('healthy.po'); |
112
|
|
|
$entry = $catalog->getEntry('string.2'); |
113
|
|
|
|
114
|
|
|
$this->assertNotNull($entry); |
115
|
|
|
$this->assertEquals(array('Code comment'), $entry->getDeveloperComments()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testPreviousUntranslated() |
120
|
|
|
{ |
121
|
|
|
$catalog = $this->parseFile('previous_unstranslated.po'); |
122
|
|
|
|
123
|
|
|
$this->assertCount(1, $catalog->getEntries()); |
124
|
|
|
|
125
|
|
|
$entry = new Entry('this is a string', 'this is a translation'); |
126
|
|
|
$entry->setPreviousEntry(new Entry('this is a previous string', 'this is a previous translation string')); |
127
|
|
|
$this->assertEquals( |
128
|
|
|
$entry, |
129
|
|
|
$catalog->getEntry('this is a string') |
130
|
|
|
); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testPreviousUntranslatedMultiline() |
134
|
|
|
{ |
135
|
|
|
$catalog = $this->parseFile('previousStringMultiline.po'); |
136
|
|
|
|
137
|
|
|
$entry = $catalog->getEntry('this is a string'); |
138
|
|
|
$this->assertNotNull($entry); |
139
|
|
|
|
140
|
|
|
$previous = $entry->getPreviousEntry(); |
141
|
|
|
$this->assertNotNull($previous); |
142
|
|
|
$this->assertEquals('this is a previous string', $previous->getMsgId()); |
143
|
|
|
$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()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function testPluralsMultiline() |
147
|
|
|
{ |
148
|
|
|
$catalog = $this->parseFile('pluralsMultiline.po'); |
149
|
|
|
$entry = $catalog->getEntry('%s post not updated,somebody is editing it.'); |
150
|
|
|
|
151
|
|
|
$this->assertNotNull($entry); |
152
|
|
|
$this->assertNotEmpty($entry->getMsgStrPlurals()); |
153
|
|
|
$this->assertEquals( |
154
|
|
|
array( |
155
|
|
|
'%s entrada no actualizada,alguien la está editando.', |
156
|
|
|
'%s entradas no actualizadas,alguien las está editando.', |
157
|
|
|
), |
158
|
|
|
$entry->getMsgStrPlurals() |
159
|
|
|
); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function testMultilineEntries() |
164
|
|
|
{ |
165
|
|
|
$catalog = $this->parseFile('multilines.po'); |
166
|
|
|
|
167
|
|
|
$longMsgId = '%user% acaba de responder tu comentario.<br>Consulta que te ha dicho %link%aquí</a>.'; |
168
|
|
|
|
169
|
|
|
$entryExpected = new Entry( |
170
|
|
|
$longMsgId, |
171
|
|
|
'%user% acaba de respondre el teu comentari.<br>Consulta que t\'ha dit %link%aquí</a>.' |
172
|
|
|
); |
173
|
|
|
$entryExpected->setReference( |
174
|
|
|
array('../../classes/controller/ccccc.php:361') |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
$entry = $catalog->getEntry($longMsgId); |
178
|
|
|
$this->assertNotNull($entry); |
179
|
|
|
$this->assertEquals($entryExpected, $entry); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function testNoHeader() |
183
|
|
|
{ |
184
|
|
|
$catalog = $this->parseFile('noheader.po'); |
185
|
|
|
|
186
|
|
|
$this->assertCount(2, $catalog->getEntries()); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function testHeaders() |
190
|
|
|
{ |
191
|
|
|
try { |
192
|
|
|
$catalog = $this->parseFile('healthy.po'); |
193
|
|
|
$headers = $catalog->getHeaders(); |
194
|
|
|
|
195
|
|
|
$this->assertCount(18, $headers); |
196
|
|
|
$this->assertEquals('Project-Id-Version: ', $headers[0]); |
197
|
|
|
$this->assertEquals('Report-Msgid-Bugs-To: ', $headers[1]); |
198
|
|
|
$this->assertEquals('POT-Creation-Date: 2013-09-25 15:55+0100', $headers[2]); |
199
|
|
|
$this->assertEquals('PO-Revision-Date: ', $headers[3]); |
200
|
|
|
$this->assertEquals('Last-Translator: Raúl Ferràs <[email protected]>', $headers[4]); |
201
|
|
|
$this->assertEquals('Language-Team: ', $headers[5]); |
202
|
|
|
$this->assertEquals('MIME-Version: 1.0', $headers[6]); |
203
|
|
|
$this->assertEquals('Content-Type: text/plain; charset=UTF-8', $headers[7]); |
204
|
|
|
$this->assertEquals('Content-Transfer-Encoding: 8bit', $headers[8]); |
205
|
|
|
$this->assertEquals('Plural-Forms: nplurals=2; plural=n != 1;', $headers[9]); |
206
|
|
|
$this->assertEquals('X-Poedit-SourceCharset: UTF-8', $headers[10]); |
207
|
|
|
$this->assertEquals('X-Poedit-KeywordsList: __;_e;_n;_t', $headers[11]); |
208
|
|
|
$this->assertEquals('X-Textdomain-Support: yes', $headers[12]); |
209
|
|
|
$this->assertEquals('X-Poedit-Basepath: .', $headers[13]); |
210
|
|
|
$this->assertEquals('X-Generator: Poedit 1.5.7', $headers[14]); |
211
|
|
|
$this->assertEquals('X-Poedit-SearchPath-0: .', $headers[15]); |
212
|
|
|
$this->assertEquals('X-Poedit-SearchPath-1: ../..', $headers[16]); |
213
|
|
|
$this->assertEquals('X-Poedit-SearchPath-2: ../../../modules', $headers[17]); |
214
|
|
|
} catch (\Exception $e) { |
215
|
|
|
$this->fail($e->getMessage()); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function testNoBlankLinesSeparatingEntries() |
220
|
|
|
{ |
221
|
|
|
$catalog = $this->parseFile('noblankline.po'); |
222
|
|
|
|
223
|
|
|
$this->assertCount(2, $catalog->getEntries()); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|