| 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 |  |  |         $entry = $catalog->getEntry('string.2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->assertEquals('string.2', $entry->getMsgId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertEquals('translation \"quoted\"', $entry->getMsgStr()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function testBasicMultiline() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $catalog = $this->parseFile('basicMultiline.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $entry = $catalog->getEntry('string.1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->assertEquals('string.1', $entry->getMsgId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->assertEquals('translation line 1 translation line 2', $entry->getMsgStr()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function testBasicCollection() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $catalog = $this->parseFile('basicCollection.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->assertCount(2, $catalog->getEntries()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $entry = $catalog->getEntry('string.1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->assertEquals('string.1', $entry->getMsgId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->assertEquals('translation.1', $entry->getMsgStr()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $entry = $catalog->getEntry('string.2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->assertEquals('string.2', $entry->getMsgId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertEquals('translation.2', $entry->getMsgStr()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function testEntriesWithContext() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $catalog = $this->parseFile('context.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $withContext = $catalog->getEntry('string.1', 'register'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->assertNotNull($withContext); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->assertEquals('register', $withContext->getMsgCtxt()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $withoutContext = $catalog->getEntry('string.1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->assertNotNull($withoutContext); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->assertEmpty($withoutContext->getMsgCtxt()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->assertNotEquals($withContext, $withoutContext); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     public function testPlurals() | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         $catalog = $this->parseFile('plurals.po'); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         $entry = $catalog->getEntry('%s post not updated, somebody is editing it.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         $this->assertNotNull($entry); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertNotEmpty($entry->getMsgStrPlurals()); | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         $this->assertEquals( | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |             array( | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |                 '%s entrada no actualizada, alguien la está editando.', | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |                 '%s entradas no actualizadas, alguien las está editando.', | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |             ), | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |             $entry->getMsgStrPlurals() | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     public function testPluralsMultiline() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $catalog = $this->parseFile('pluralsMultiline.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $entry = $catalog->getEntry('%s post not updated,somebody is editing it.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $this->assertNotEmpty($entry->getMsgStrPlurals()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 '%s entrada no actualizada,alguien la está editando.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 '%s entradas no actualizadas,alguien las está editando.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $entry->getMsgStrPlurals() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     public function testFlags() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $catalog = $this->parseFile('multiflags.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $this->assertCount(1, $catalog->getEntries()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $entry = $catalog->getEntry('Attachment', 'Background Attachment'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $this->assertCount(2, $entry->getFlags()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $this->assertEquals(array('php-format', 'fuzzy'), $entry->getFlags()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     public function testTranslatorComment() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $catalog = $this->parseFile('translatorComments.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $entry = $catalog->getEntry('string.1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             array('translator comment', 'second translator comment'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             $entry->getTranslatorComments() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     public function testDeveloperComment() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $catalog = $this->parseFile('codeComments.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $entry = $catalog->getEntry('string.1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $this->assertEquals(array('code comment', 'code translator comment'), $entry->getDeveloperComments()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     public function testPreviousString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $catalog = $this->parseFile('previousString.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $this->assertCount(1, $catalog->getEntries()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $entry = new Entry('this is a string', 'this is a translation'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $entry->setPreviousEntry(new Entry('this is a previous string', 'this is a previous translation string')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             $entry, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             $catalog->getEntry('this is a string') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     public function testPreviousStringMultiline() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $catalog = $this->parseFile('previousStringMultiline.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $entry = $catalog->getEntry('this is a string'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $previous = $entry->getPreviousEntry(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         $this->assertNotNull($previous); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $this->assertEquals('this is a previous string', $previous->getMsgId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         $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()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     public function testHeaders() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $catalog = $this->parseFile('basicHeader.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         $this->assertCount(1, $catalog->getEntries()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     public function testOnlyCustomHeaders() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $catalog = $this->parseFile('basicCustomHeaders.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $this->assertCount(1, $catalog->getEntries()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         $this->assertGreaterThanOrEqual(1, count($catalog->getHeaders())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     public function testHeadersMultiline() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         $catalog = $this->parseFile('basicHeadersMultiline.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $this->assertCount(1, $catalog->getEntries()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         $this->assertCount(3,$catalog->getHeaders()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     public function testMultilineEntries() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $catalog = $this->parseFile('multilines.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $longMsgId = '%user% acaba de responder tu comentario.<br>Consulta que te ha dicho %link%aquí</a>.'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         $entryExpected = new Entry( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |             $longMsgId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |             '%user% acaba de respondre el teu comentari.<br>Consulta que t\'ha dit %link%aquí</a>.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         $entryExpected->setReference( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             array('../../classes/controller/ccccc.php:361') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         $entry = $catalog->getEntry($longMsgId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $this->assertNotNull($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         $this->assertEquals($entryExpected, $entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |     public function testNoBlankLinesSeparatingEntries() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         $catalog = $this->parseFile('noblankline.po'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         $this->assertCount(2, $catalog->getEntries()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 206 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 207 |  |  |  |