1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sepia\Test; |
4
|
|
|
|
5
|
|
|
use Sepia\PoParser\Parser; |
6
|
|
|
use Sepia\PoParser\PoReader\StringHandler; |
7
|
|
|
|
8
|
|
|
class PoFeaturesTest extends AbstractFixtureTest |
9
|
|
|
{ |
10
|
|
|
public function tearDown() |
11
|
|
|
{ |
12
|
|
|
parent::tearDown(); |
13
|
|
|
|
14
|
|
|
if (file_exists($this->resourcesPath.'temp.po')) { |
15
|
|
|
unlink($this->resourcesPath.'temp.po'); |
16
|
|
|
} |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testRead() |
20
|
|
|
{ |
21
|
|
|
try { |
22
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'healthy.po'); |
23
|
|
|
$result = $catalog->getEntries(); |
24
|
|
|
} catch (\Exception $e) { |
25
|
|
|
$result = array(); |
26
|
|
|
$this->fail($e->getMessage()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$this->assertCount(3, $result); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
// Read file without headers. |
33
|
|
|
// It should not skip first entry |
34
|
|
|
try { |
35
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'noheader.po'); |
36
|
|
|
$result = $catalog->getEntries(); |
37
|
|
|
} catch (\Exception $e) { |
38
|
|
|
$result = array(); |
39
|
|
|
$this->fail($e->getMessage()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->assertCount(2, $result, 'Did not read properly po file without headers.'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Tests reading the headers. |
48
|
|
|
* |
49
|
|
|
*/ |
50
|
|
|
public function testHeaders() |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'healthy.po'); |
54
|
|
|
$headers = $catalog->getHeaders(); |
55
|
|
|
|
56
|
|
|
$this->assertCount(18, $headers); |
57
|
|
|
$this->assertEquals("Project-Id-Version: ", $headers[0]); |
58
|
|
|
$this->assertEquals("Report-Msgid-Bugs-To: ", $headers[1]); |
59
|
|
|
$this->assertEquals("POT-Creation-Date: 2013-09-25 15:55+0100", $headers[2]); |
60
|
|
|
$this->assertEquals("PO-Revision-Date: ", $headers[3]); |
61
|
|
|
$this->assertEquals("Last-Translator: Raúl Ferràs <[email protected]>", $headers[4]); |
62
|
|
|
$this->assertEquals("Language-Team: ", $headers[5]); |
63
|
|
|
$this->assertEquals("MIME-Version: 1.0", $headers[6]); |
64
|
|
|
$this->assertEquals("Content-Type: text/plain; charset=UTF-8", $headers[7]); |
65
|
|
|
$this->assertEquals("Content-Transfer-Encoding: 8bit", $headers[8]); |
66
|
|
|
$this->assertEquals("Plural-Forms: nplurals=2; plural=n != 1;", $headers[9]); |
67
|
|
|
$this->assertEquals("X-Poedit-SourceCharset: UTF-8", $headers[10]); |
68
|
|
|
$this->assertEquals("X-Poedit-KeywordsList: __;_e;_n;_t", $headers[11]); |
69
|
|
|
$this->assertEquals("X-Textdomain-Support: yes", $headers[12]); |
70
|
|
|
$this->assertEquals("X-Poedit-Basepath: .", $headers[13]); |
71
|
|
|
$this->assertEquals("X-Generator: Poedit 1.5.7", $headers[14]); |
72
|
|
|
$this->assertEquals("X-Poedit-SearchPath-0: .", $headers[15]); |
73
|
|
|
$this->assertEquals("X-Poedit-SearchPath-1: ../..", $headers[16]); |
74
|
|
|
$this->assertEquals("X-Poedit-SearchPath-2: ../../../modules", $headers[17]); |
75
|
|
|
} catch (\Exception $e) { |
76
|
|
|
$this->fail($e->getMessage()); |
77
|
|
|
// $this->assertTrue( false, $e->getMessage() ); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testMultilineId() |
83
|
|
|
{ |
84
|
|
|
try { |
85
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'multilines.po'); |
86
|
|
|
$result = $catalog->getEntries(); |
87
|
|
|
$headers = $catalog->getHeaders(); |
88
|
|
|
|
89
|
|
|
$this->assertCount(18, $headers); |
90
|
|
|
$this->assertCount(9, $result); |
91
|
|
|
} catch (\Exception $e) { |
92
|
|
|
$this->fail($e->getMessage()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* |
99
|
|
|
* |
100
|
|
|
*/ |
101
|
|
|
public function testPlurals() |
102
|
|
|
{ |
103
|
|
|
try { |
104
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'plurals.po'); |
105
|
|
|
$headers = $catalog->getHeaders(); |
106
|
|
|
$result = $catalog->getEntries(); |
107
|
|
|
|
108
|
|
|
$this->assertCount(7, $headers); |
109
|
|
|
$this->assertCount(15, $result); |
110
|
|
|
} catch (\Exception $e) { |
111
|
|
|
$this->fail($e->getMessage()); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testPluralsMultiline() |
116
|
|
|
{ |
117
|
|
|
try { |
118
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'pluralsMultiline.po'); |
119
|
|
|
$this->assertCount(2, $catalog->getEntries()); |
120
|
|
|
$entries = $catalog->getEntries(); |
121
|
|
|
foreach ($entries as $entry) { |
122
|
|
|
$this->assertNotEmpty($entry->getMsgStrPlurals()); |
123
|
|
|
} |
124
|
|
|
} catch (\Exception $e) { |
125
|
|
|
$this->fail($e->getMessage()); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Test Writing file |
132
|
|
|
*/ |
133
|
|
|
public function testWrite() |
134
|
|
|
{ |
135
|
|
|
$this->markTestSkipped(); |
136
|
|
|
// Read & write a simple file |
137
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'healthy.po'); |
138
|
|
|
$catalog->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
139
|
|
|
|
140
|
|
|
$this->assertFileEquals($this->resourcesPath.'healthy.po', $this->resourcesPath.'temp.po'); |
141
|
|
|
|
142
|
|
|
// Read & write a file with no headers |
143
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'noheader.po'); |
144
|
|
|
$catalog->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
145
|
|
|
|
146
|
|
|
$this->assertFileEquals($this->resourcesPath.'noheader.po', $this->resourcesPath.'temp.po'); |
147
|
|
|
|
148
|
|
|
// Read & write a po file with multilines |
149
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'multilines.po'); |
150
|
|
|
$catalog->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
151
|
|
|
|
152
|
|
|
$this->assertFileEquals($this->resourcesPath.'multilines.po', $this->resourcesPath.'temp.po'); |
153
|
|
|
|
154
|
|
|
// Read & write a po file with contexts |
155
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'context.po'); |
156
|
|
|
$catalog->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
157
|
|
|
|
158
|
|
|
$this->assertFileEquals($this->resourcesPath.'context.po', $this->resourcesPath.'temp.po'); |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
// Read & write a po file with previous unstranslated strings |
162
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'previous_unstranslated.po'); |
163
|
|
|
$catalog->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
164
|
|
|
|
165
|
|
|
$this->assertFileEquals($this->resourcesPath.'previous_unstranslated.po', $this->resourcesPath.'temp.po'); |
166
|
|
|
|
167
|
|
|
// Read & write a po file with multiple flags |
168
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'multiflags.po'); |
169
|
|
|
$catalog->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
170
|
|
|
|
171
|
|
|
$this->assertFileEquals($this->resourcesPath.'multiflags.po', $this->resourcesPath.'temp.po'); |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
unlink($this->resourcesPath.'temp.po'); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Test update entry, update plural forms |
179
|
|
|
*/ |
180
|
|
|
public function testUpdatePlurals() |
181
|
|
|
{ |
182
|
|
|
$this->markTestSkipped(); |
183
|
|
|
$msgid = '%s post not updated, somebody is editing it.'; |
184
|
|
|
$msgstr = array( |
185
|
|
|
"%s entrada no actualizada, alguien la está editando...", |
186
|
|
|
"%s entradas no actualizadas, alguien las está editando...", |
187
|
|
|
); |
188
|
|
|
|
189
|
|
|
$parser = Parser::parseFile($this->resourcesPath.'plurals.po'); |
190
|
|
|
|
191
|
|
|
$parser->setEntry( |
|
|
|
|
192
|
|
|
$msgid, |
193
|
|
|
array( |
194
|
|
|
'msgid' => $msgid, |
195
|
|
|
'msgstr' => $msgstr, |
196
|
|
|
) |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
$parser->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
200
|
|
|
|
201
|
|
|
$parser = Parser::parseFile($this->resourcesPath.'temp.po'); |
202
|
|
|
$newPlurals = $parser->getEntries(); |
203
|
|
|
$this->assertEquals($newPlurals[$msgid]['msgstr'], $msgstr); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Test update with fuzzy flag. |
209
|
|
|
* |
210
|
|
|
* @todo |
211
|
|
|
*/ |
212
|
|
|
public function testUpdateWithFuzzy() |
213
|
|
|
{ |
214
|
|
|
$this->markTestSkipped(); |
215
|
|
|
$msgid = '%1$s-%2$s'; |
216
|
|
|
|
217
|
|
|
$parser = Parser::parseFile($this->resourcesPath.'context.po'); |
218
|
|
|
$entries = $parser->getEntries(); |
219
|
|
|
|
220
|
|
|
$entries[$msgid]['msgstr'] = array('translate'); |
221
|
|
|
$parser->setEntry($msgid, $entries[$msgid]); |
|
|
|
|
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Test for success update headers |
226
|
|
|
*/ |
227
|
|
|
public function testUpdateHeaders() |
228
|
|
|
{ |
229
|
|
|
$this->markTestSkipped(); |
230
|
|
|
$parser = Parser::parseFile($this->resourcesPath.'context.po'); |
231
|
|
|
|
232
|
|
|
$newHeaders = array( |
233
|
|
|
'"Project-Id-Version: \n"', |
234
|
|
|
'"Report-Msgid-Bugs-To: \n"', |
235
|
|
|
'"POT-Creation-Date: \n"', |
236
|
|
|
'"PO-Revision-Date: \n"', |
237
|
|
|
'"Last-Translator: none\n"', |
238
|
|
|
'"Language-Team: \n"', |
239
|
|
|
'"MIME-Version: 1.0\n"', |
240
|
|
|
'"Content-Type: text/plain; charset=UTF-8\n"', |
241
|
|
|
'"Content-Transfer-Encoding: 8bit\n"', |
242
|
|
|
'"Plural-Forms: nplurals=2; plural=n != 1;\n"', |
243
|
|
|
); |
244
|
|
|
|
245
|
|
|
$result = $parser->setHeaders($newHeaders); |
|
|
|
|
246
|
|
|
$this->assertTrue($result); |
247
|
|
|
$parser->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
248
|
|
|
|
249
|
|
|
$newPoFile = Parser::parseFile($this->resourcesPath.'temp.po'); |
250
|
|
|
$readHeaders = $newPoFile->getHeaders(); |
251
|
|
|
$this->assertEquals($newHeaders, $readHeaders); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Test for fail update headers |
256
|
|
|
*/ |
257
|
|
|
public function testUpdateHeadersWrong() |
258
|
|
|
{ |
259
|
|
|
$this->markTestSkipped(); |
260
|
|
|
$pofile = new Parser(new StringHandler('')); |
261
|
|
|
$result = $pofile->setHeaders('header'); |
|
|
|
|
262
|
|
|
$this->assertFalse($result); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Test for po files with no blank lines between entries |
267
|
|
|
*/ |
268
|
|
|
public function testNoBlankLines() |
269
|
|
|
{ |
270
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'noblankline.po'); |
271
|
|
|
|
272
|
|
|
$entry = $catalog->getEntry('one'); |
273
|
|
|
$this->assertNotNull($entry); |
274
|
|
|
$this->assertEquals('one', $entry->getMsgId()); |
275
|
|
|
$this->assertEquals('uno', $entry->getMsgstr()); |
276
|
|
|
|
277
|
|
|
$entry = $catalog->getEntry('two'); |
278
|
|
|
$this->assertNotNull($entry); |
279
|
|
|
$this->assertEquals('two', $entry->getMsgId()); |
280
|
|
|
$this->assertEquals('dos', $entry->getMsgstr()); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Test for entries with multiple flags |
286
|
|
|
*/ |
287
|
|
|
public function testFlags() |
288
|
|
|
{ |
289
|
|
|
$this->markTestSkipped(); |
290
|
|
|
// Read po file with 'php-format' flag. Add 'fuzzy' flag. |
291
|
|
|
// Compare the result with the version that has 'php-format' and 'fuzzy' flags |
292
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'flags-phpformat.po'); |
293
|
|
|
$entries = $catalog->getEntries(); |
294
|
|
|
|
295
|
|
|
foreach ($entries as $msgid => $entry) { |
296
|
|
|
$entry['flags'][] = 'fuzzy'; |
297
|
|
|
$catalog->setEntry($msgid, $entry); |
|
|
|
|
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
$catalog->writeFile($this->resourcesPath.'temp.po'); |
|
|
|
|
301
|
|
|
$this->assertFileEquals($this->resourcesPath.'flags-phpformat-fuzzy.po', $this->resourcesPath.'temp.po'); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Test for reading previous unstranslated strings |
307
|
|
|
*/ |
308
|
|
|
public function testPreviousUnstranslated() |
309
|
|
|
{ |
310
|
|
|
$catalog = Parser::parseFile($this->resourcesPath.'previous_unstranslated.po'); |
311
|
|
|
|
312
|
|
|
$entry = $catalog->getEntry('this is a string'); |
313
|
|
|
$this->assertNotNull($entry); |
314
|
|
|
$this->assertEquals('this is a string', $entry->getMsgId()); |
315
|
|
|
$this->assertEquals('this is a translation', $entry->getMsgStr()); |
316
|
|
|
|
317
|
|
|
$prev = $entry->getPreviousEntry(); |
318
|
|
|
$this->assertNotNull($prev); |
319
|
|
|
$this->assertEquals('this is a previous string', $prev->getMsgId()); |
320
|
|
|
$this->assertEquals('this is a previous translation string', $prev->getMsgStr()); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.