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
|
|
|
$this->markTestIncomplete('TODO'); |
69
|
|
|
$catalog = $this->parseFile('previous_unstranslated.po'); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testPlurals() |
73
|
|
|
{ |
74
|
|
|
$catalog = $this->parseFile('plurals.po'); |
75
|
|
|
|
76
|
|
|
$entry = $catalog->getEntry('%s post not updated, somebody is editing it.'); |
77
|
|
|
$this->assertNotNull($entry); |
78
|
|
|
$this->assertNotEmpty($entry->getMsgStrPlurals()); |
79
|
|
|
$this->assertEquals( |
80
|
|
|
array( |
81
|
|
|
'%s entrada no actualizada, alguien la está editando.', |
82
|
|
|
'%s entradas no actualizadas, alguien las está editando.', |
83
|
|
|
), |
84
|
|
|
$entry->getMsgStrPlurals() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testPluralsMultiline() |
89
|
|
|
{ |
90
|
|
|
$catalog = $this->parseFile('pluralsMultiline.po'); |
91
|
|
|
$entry = $catalog->getEntry('%s post not updated,somebody is editing it.'); |
92
|
|
|
|
93
|
|
|
$this->assertNotNull($entry); |
94
|
|
|
$this->assertNotEmpty($entry->getMsgStrPlurals()); |
95
|
|
|
$this->assertEquals( |
96
|
|
|
array( |
97
|
|
|
'%s entrada no actualizada,alguien la está editando.', |
98
|
|
|
'%s entradas no actualizadas,alguien las está editando.', |
99
|
|
|
), |
100
|
|
|
$entry->getMsgStrPlurals() |
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 testNoBlankLinesSeparatingEntries() |
131
|
|
|
{ |
132
|
|
|
$catalog = $this->parseFile('noblankline.po'); |
133
|
|
|
|
134
|
|
|
$this->assertCount(2, $catalog->getEntries()); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
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.