Completed
Pull Request — master (#68)
by Raúl
02:32 queued 01:17
created

ReadPoTest::testFlags()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
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 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('previousStringMultiline.po');
69
70
        $entry = $catalog->getEntry('this is a string');
71
        $this->assertNotNull($entry);
72
73
        $previous = $entry->getPreviousEntry();
74
        $this->assertNotNull($previous);
75
        $this->assertEquals('this is a previous string', $previous->getMsgId());
76
        $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());
77
    }
78
79
    public function testPlurals()
80
    {
81
        $catalog = $this->parseFile('plurals.po');
82
83
        $entry = $catalog->getEntry('%s post not updated, somebody is editing it.');
84
        $this->assertNotNull($entry);
85
        $this->assertNotEmpty($entry->getMsgStrPlurals());
86
        $this->assertEquals(
87
            array(
88
                '%s entrada no actualizada, alguien la está editando.',
89
                '%s entradas no actualizadas, alguien las está editando.',
90
            ),
91
            $entry->getMsgStrPlurals()
92
        );
93
    }
94
95
    public function testPluralsMultiline()
96
    {
97
        $catalog = $this->parseFile('pluralsMultiline.po');
98
        $entry = $catalog->getEntry('%s post not updated,somebody is editing it.');
99
100
        $this->assertNotNull($entry);
101
        $this->assertNotEmpty($entry->getMsgStrPlurals());
102
        $this->assertEquals(
103
            array(
104
                '%s entrada no actualizada,alguien la está editando.',
105
                '%s entradas no actualizadas,alguien las está editando.',
106
            ),
107
            $entry->getMsgStrPlurals()
108
        );
109
    }
110
111
112
    public function testMultilineEntries()
113
    {
114
        $catalog = $this->parseFile('multilines.po');
115
116
        $longMsgId = '%user% acaba de responder tu comentario.<br>Consulta que te ha dicho %link%aquí</a>.';
117
118
        $entryExpected = new Entry(
119
            $longMsgId,
120
            '%user% acaba de respondre el teu comentari.<br>Consulta que t\'ha dit %link%aquí</a>.'
121
        );
122
        $entryExpected->setReference(
123
            array('../../classes/controller/ccccc.php:361')
124
        );
125
126
        $entry = $catalog->getEntry($longMsgId);
127
        $this->assertNotNull($entry);
128
        $this->assertEquals($entryExpected, $entry);
129
    }
130
131
    public function testNoHeader()
132
    {
133
        $catalog = $this->parseFile('noheader.po');
134
135
        $this->assertCount(2, $catalog->getEntries());
136
    }
137
138
    public function testHeaders()
139
    {
140
        try {
141
            $catalog = $this->parseFile('healthy.po');
142
            $headers = $catalog->getHeaders();
143
144
            $this->assertCount(18, $headers);
145
            $this->assertEquals('Project-Id-Version: ', $headers[0]);
146
            $this->assertEquals('Report-Msgid-Bugs-To: ', $headers[1]);
147
            $this->assertEquals('POT-Creation-Date: 2013-09-25 15:55+0100', $headers[2]);
148
            $this->assertEquals('PO-Revision-Date: ', $headers[3]);
149
            $this->assertEquals('Last-Translator: Raúl Ferràs <[email protected]>', $headers[4]);
150
            $this->assertEquals('Language-Team: ', $headers[5]);
151
            $this->assertEquals('MIME-Version: 1.0', $headers[6]);
152
            $this->assertEquals('Content-Type: text/plain; charset=UTF-8', $headers[7]);
153
            $this->assertEquals('Content-Transfer-Encoding: 8bit', $headers[8]);
154
            $this->assertEquals('Plural-Forms: nplurals=2; plural=n != 1;', $headers[9]);
155
            $this->assertEquals('X-Poedit-SourceCharset: UTF-8', $headers[10]);
156
            $this->assertEquals('X-Poedit-KeywordsList: __;_e;_n;_t', $headers[11]);
157
            $this->assertEquals('X-Textdomain-Support: yes', $headers[12]);
158
            $this->assertEquals('X-Poedit-Basepath: .', $headers[13]);
159
            $this->assertEquals('X-Generator: Poedit 1.5.7', $headers[14]);
160
            $this->assertEquals('X-Poedit-SearchPath-0: .', $headers[15]);
161
            $this->assertEquals('X-Poedit-SearchPath-1: ../..', $headers[16]);
162
            $this->assertEquals('X-Poedit-SearchPath-2: ../../../modules', $headers[17]);
163
        } catch (\Exception $e) {
164
            $this->fail($e->getMessage());
165
        }
166
    }
167
168
    public function testNoBlankLinesSeparatingEntries()
169
    {
170
        $catalog = $this->parseFile('noblankline.po');
171
172
        $this->assertCount(2, $catalog->getEntries());
173
    }
174
}
175