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 testFlags() |
11
|
|
|
{ |
12
|
|
|
$catalog = $this->parseFile('multiflags.po'); |
13
|
|
|
|
14
|
|
|
$this->assertCount(1, $catalog->getEntries()); |
15
|
|
|
$entry = $catalog->getEntry('Attachment', 'Background Attachment'); |
16
|
|
|
|
17
|
|
|
$this->assertNotNull($entry); |
18
|
|
|
$this->assertCount(2, $entry->getFlags()); |
19
|
|
|
$this->assertEquals(array('php-format', 'fuzzy'), $entry->getFlags()); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testTranslatorComment() |
23
|
|
|
{ |
24
|
|
|
$catalog = $this->parseFile('healthy.po'); |
25
|
|
|
$entry = $catalog->getEntry('string.2'); |
26
|
|
|
|
27
|
|
|
$this->assertNotNull($entry); |
28
|
|
|
$this->assertEquals(array('Translator comment'), $entry->getTranslatorComments()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testDeveloperComment() |
32
|
|
|
{ |
33
|
|
|
$catalog = $this->parseFile('healthy.po'); |
34
|
|
|
$entry = $catalog->getEntry('string.2'); |
35
|
|
|
|
36
|
|
|
$this->assertNotNull($entry); |
37
|
|
|
$this->assertEquals(array('Code comment'), $entry->getDeveloperComments()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testEntriesWithContext() |
41
|
|
|
{ |
42
|
|
|
$catalog = $this->parseFile('context.po'); |
43
|
|
|
|
44
|
|
|
$withContext = $catalog->getEntry('1', 'start of week'); |
45
|
|
|
$withoutContext = $catalog->getEntry('1'); |
46
|
|
|
|
47
|
|
|
$this->assertNotNull($withContext); |
48
|
|
|
$this->assertNotNull($withoutContext); |
49
|
|
|
$this->assertNotEquals($withContext, $withoutContext); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testPreviousUntranslated() |
53
|
|
|
{ |
54
|
|
|
$catalog = $this->parseFile('previous_unstranslated.po'); |
55
|
|
|
|
56
|
|
|
$this->assertCount(1, $catalog->getEntries()); |
57
|
|
|
|
58
|
|
|
$entry = new Entry('this is a string', 'this is a translation'); |
59
|
|
|
$entry->setPreviousEntry(new Entry('this is a previous string', 'this is a previous translation string')); |
60
|
|
|
$this->assertEquals( |
61
|
|
|
$entry, |
62
|
|
|
$catalog->getEntry('this is a string') |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testPreviousUntranslatedMultiline() |
67
|
|
|
{ |
68
|
|
|
$catalog = $this->parseFile('previous_unstranslated.po'); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testPlurals() |
72
|
|
|
{ |
73
|
|
|
$catalog = $this->parseFile('plurals.po'); |
74
|
|
|
|
75
|
|
|
$entry = $catalog->getEntry('%s post not updated, somebody is editing it.'); |
76
|
|
|
$this->assertNotNull($entry); |
77
|
|
|
$this->assertNotEmpty($entry->getMsgStrPlurals()); |
78
|
|
|
$this->assertEquals( |
79
|
|
|
array( |
80
|
|
|
'%s entrada no actualizada, alguien la está editando.', |
81
|
|
|
'%s entradas no actualizadas, alguien las está editando.', |
82
|
|
|
), |
83
|
|
|
$entry->getMsgStrPlurals() |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testPluralsMultiline() |
88
|
|
|
{ |
89
|
|
|
$catalog = $this->parseFile('pluralsMultiline.po'); |
90
|
|
|
$entry = $catalog->getEntry('%s post not updated,somebody is editing it.'); |
91
|
|
|
|
92
|
|
|
$this->assertNotNull($entry); |
93
|
|
|
$this->assertNotEmpty($entry->getMsgStrPlurals()); |
94
|
|
|
$this->assertEquals( |
95
|
|
|
array( |
96
|
|
|
'%s entrada no actualizada,alguien la está editando.', |
97
|
|
|
'%s entradas no actualizadas,alguien las está editando.', |
98
|
|
|
), |
99
|
|
|
$entry->getMsgStrPlurals() |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testMultilineEntries() |
105
|
|
|
{ |
106
|
|
|
$catalog = $this->parseFile('multilines.po'); |
107
|
|
|
|
108
|
|
|
$longMsgId = '%user% acaba de responder tu comentario.<br>Consulta que te ha dicho %link%aquí</a>.'; |
109
|
|
|
|
110
|
|
|
$entryExpected = new Entry( |
111
|
|
|
$longMsgId, |
112
|
|
|
'%user% acaba de respondre el teu comentari.<br>Consulta que t\'ha dit %link%aquí</a>.' |
113
|
|
|
); |
114
|
|
|
$entryExpected->setReference( |
115
|
|
|
array('../../classes/controller/ccccc.php:361') |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
$entry = $catalog->getEntry($longMsgId); |
119
|
|
|
$this->assertNotNull($entry); |
120
|
|
|
$this->assertEquals($entryExpected, $entry); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testNoHeader() |
124
|
|
|
{ |
125
|
|
|
$catalog = $this->parseFile('noheader.po'); |
126
|
|
|
|
127
|
|
|
$this->assertCount(2, $catalog->getEntries()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function testHeaders() |
131
|
|
|
{ |
132
|
|
|
try { |
133
|
|
|
$catalog = $this->parseFile('healthy.po'); |
134
|
|
|
$headers = $catalog->getHeaders(); |
135
|
|
|
|
136
|
|
|
$this->assertCount(18, $headers); |
137
|
|
|
$this->assertEquals('Project-Id-Version: ', $headers[0]); |
138
|
|
|
$this->assertEquals('Report-Msgid-Bugs-To: ', $headers[1]); |
139
|
|
|
$this->assertEquals('POT-Creation-Date: 2013-09-25 15:55+0100', $headers[2]); |
140
|
|
|
$this->assertEquals('PO-Revision-Date: ', $headers[3]); |
141
|
|
|
$this->assertEquals('Last-Translator: Raúl Ferràs <[email protected]>', $headers[4]); |
142
|
|
|
$this->assertEquals('Language-Team: ', $headers[5]); |
143
|
|
|
$this->assertEquals('MIME-Version: 1.0', $headers[6]); |
144
|
|
|
$this->assertEquals('Content-Type: text/plain; charset=UTF-8', $headers[7]); |
145
|
|
|
$this->assertEquals('Content-Transfer-Encoding: 8bit', $headers[8]); |
146
|
|
|
$this->assertEquals('Plural-Forms: nplurals=2; plural=n != 1;', $headers[9]); |
147
|
|
|
$this->assertEquals('X-Poedit-SourceCharset: UTF-8', $headers[10]); |
148
|
|
|
$this->assertEquals('X-Poedit-KeywordsList: __;_e;_n;_t', $headers[11]); |
149
|
|
|
$this->assertEquals('X-Textdomain-Support: yes', $headers[12]); |
150
|
|
|
$this->assertEquals('X-Poedit-Basepath: .', $headers[13]); |
151
|
|
|
$this->assertEquals('X-Generator: Poedit 1.5.7', $headers[14]); |
152
|
|
|
$this->assertEquals('X-Poedit-SearchPath-0: .', $headers[15]); |
153
|
|
|
$this->assertEquals('X-Poedit-SearchPath-1: ../..', $headers[16]); |
154
|
|
|
$this->assertEquals('X-Poedit-SearchPath-2: ../../../modules', $headers[17]); |
155
|
|
|
} catch (\Exception $e) { |
156
|
|
|
$this->fail($e->getMessage()); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function testNoBlankLinesSeparatingEntries() |
161
|
|
|
{ |
162
|
|
|
$catalog = $this->parseFile('noblankline.po'); |
163
|
|
|
|
164
|
|
|
$this->assertCount(2, $catalog->getEntries()); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.