@@ -29,6 +29,7 @@ protected function tearDown()
2929 }
3030
3131 /**
32+ * @covers Geekwright\Po\PoEntry::__construct
3233 * @covers Geekwright\Po\PoEntry::add
3334 * @covers Geekwright\Po\PoEntry::set
3435 * @covers Geekwright\Po\PoEntry::get
@@ -49,6 +50,11 @@ public function testAddGetSet()
4950 $ expected = array ($ value , $ value2 );
5051 $ actual = $ entry ->get (PoTokens::TRANSLATOR_COMMENTS );
5152 $ this ->assertEquals ($ expected , $ actual );
53+
54+ $ entry ->add (PoTokens::REFERENCE , 'ref ' );
55+ $ actual = $ entry ->get (PoTokens::REFERENCE );
56+ $ expected = array ('ref ' );
57+ $ this ->assertEquals ($ expected , $ actual );
5258 }
5359
5460 /**
@@ -57,11 +63,11 @@ public function testAddGetSet()
5763 */
5864 public function testAddQuoted ()
5965 {
60- $ this ->object ->set (PoTokens:: MESSAGE , null );
61- $ this ->object ->addQuoted (PoTokens:: MESSAGE , '"" ' );
62- $ this ->object ->addQuoted (PoTokens:: MESSAGE , '"First\n" ' );
63- $ this ->object ->addQuoted (PoTokens:: MESSAGE , '"Second\n" ' );
64- $ actual = $ this ->object ->getAsString (PoTokens:: MESSAGE );
66+ $ this ->object ->set (PoTokens::MESSAGE , null );
67+ $ this ->object ->addQuoted (PoTokens::MESSAGE , '"" ' );
68+ $ this ->object ->addQuoted (PoTokens::MESSAGE , '"First\n" ' );
69+ $ this ->object ->addQuoted (PoTokens::MESSAGE , '"Second\n" ' );
70+ $ actual = $ this ->object ->getAsString (PoTokens::MESSAGE );
6571 $ this ->assertEquals ("First \nSecond \n" , $ actual );
6672 }
6773
@@ -71,27 +77,60 @@ public function testAddQuoted()
7177 */
7278 public function testAddQuotedAtPosition ()
7379 {
74- $ this ->object ->set (PoTokens:: TRANSLATED , null );
75- $ this ->object ->addQuotedAtPosition (PoTokens:: TRANSLATED , 1 , '"" ' );
76- $ this ->object ->addQuotedAtPosition (PoTokens:: TRANSLATED , 1 , '"First\n" ' );
77- $ this ->object ->addQuotedAtPosition (PoTokens:: TRANSLATED , 1 , '"Second\n" ' );
78- $ actual = $ this ->object ->getAsStringArray (PoTokens:: TRANSLATED );
80+ $ this ->object ->set (PoTokens::TRANSLATED , null );
81+ $ this ->object ->addQuotedAtPosition (PoTokens::TRANSLATED , 1 , '"" ' );
82+ $ this ->object ->addQuotedAtPosition (PoTokens::TRANSLATED , 1 , '"First\n" ' );
83+ $ this ->object ->addQuotedAtPosition (PoTokens::TRANSLATED , 1 , '"Second\n" ' );
84+ $ actual = $ this ->object ->getAsStringArray (PoTokens::TRANSLATED );
7985 $ this ->assertEquals (array (1 =>"First \nSecond \n" ), $ actual );
86+
87+ $ this ->object ->set (PoTokens::TRANSLATED , null );
88+ $ this ->object ->set (PoTokens::TRANSLATED , array ("First \n" ));
89+ $ this ->object ->addQuotedAtPosition (PoTokens::TRANSLATED , 0 , '"Second\n" ' );
90+ $ actual = $ this ->object ->getAsStringArray (PoTokens::TRANSLATED );
91+ $ this ->assertEquals (array (0 =>"First \nSecond \n" ), $ actual );
8092 }
8193
8294 /**
8395 * @covers Geekwright\Po\PoEntry::dumpEntry
96+ * @covers Geekwright\Po\PoEntry::dumpEntryComments
97+ * @covers Geekwright\Po\PoEntry::formatQuotedString
8498 */
8599 public function testDumpEntry ()
86100 {
87101 $ entry = new PoEntry ;
88- $ entry ->set (PoTokens:: MESSAGE , 'Hello. ' );
89- $ entry ->set (PoTokens:: TRANSLATED , 'Bonjour! ' );
90- $ entry ->set (PoTokens:: TRANSLATOR_COMMENTS , 'Just saying hello ' );
102+ $ entry ->set (PoTokens::MESSAGE , 'Hello. ' );
103+ $ entry ->set (PoTokens::TRANSLATED , 'Bonjour! ' );
104+ $ entry ->set (PoTokens::TRANSLATOR_COMMENTS , 'Just saying ' );
105+ $ entry ->add (PoTokens::TRANSLATOR_COMMENTS , 'hello ' );
106+ $ entry ->set (PoTokens::REFERENCE , 'ref ' );
107+
108+ $ actual = $ entry ->dumpEntry ();
109+
110+ $ expected = "# Just saying \n# hello \n#: ref \nmsgid \"Hello. \"\nmsgstr \"Bonjour! \"\n\n" ;
111+ $ this ->assertEquals ($ expected , $ actual );
112+
113+ $ entry = new PoEntry ;
114+ $ entry ->set (PoTokens::MESSAGE , '' );
115+ $ entry ->add (PoTokens::MESSAGE , 'Hello. ' );
116+ $ entry ->set (PoTokens::TRANSLATED , '' );
117+ $ entry ->add (PoTokens::TRANSLATED , 'Bonjour! ' );
118+ $ entry ->add (PoTokens::CONTEXT , 'context ' );
119+
120+ $ actual = $ entry ->dumpEntry ();
121+
122+ $ expected = "msgctxt \"context \"\nmsgid \"\"\n\"Hello. \"\nmsgstr \"\"\n\"Bonjour! \"\n\n" ;
123+ $ this ->assertEquals ($ expected , $ actual );
124+
125+ $ entry = new PoEntry ;
126+ $ entry ->add (PoTokens::MESSAGE , 'One ' );
127+ $ entry ->add (PoTokens::PLURAL , 'Several ' );
128+ $ entry ->addQuotedAtPosition (PoTokens::TRANSLATED , 0 , 'Onewa ' );
129+ $ entry ->addQuotedAtPosition (PoTokens::TRANSLATED , 1 , 'Everalsa ' );
91130
92131 $ actual = $ entry ->dumpEntry ();
93132
94- $ expected = "# Just saying hello \n msgid \"Hello. \"\nmsgstr \"Bonjour! \"\n\n" ;
133+ $ expected = "msgid \" One \"\n msgid_plural \" Several \"\n msgstr[0] \"Onewa \"\nmsgstr[1] \"Everalsa \"\n\n" ;
95134 $ this ->assertEquals ($ expected , $ actual );
96135 }
97136
@@ -101,19 +140,28 @@ public function testDumpEntry()
101140 */
102141 public function testHasFlag ()
103142 {
104- $ this ->object ->set (PoTokens:: FLAG , null );
105- $ this ->object ->set (PoTokens:: FLAG , 'fuzzy ' );
143+ $ this ->object ->set (PoTokens::FLAG , null );
144+ $ this ->assertFalse ($ this ->object ->hasFlag ('fuzzy ' ));
145+ $ this ->object ->set (PoTokens::FLAG , 'fuzzy ' );
106146
107147 $ this ->assertTrue ($ this ->object ->hasFlag ('fuzzy ' ));
108148 $ this ->assertFalse ($ this ->object ->hasFlag ('futzy ' ));
109149
110- $ this ->object ->set (PoTokens:: FLAG , null );
111- $ this ->object ->set (PoTokens:: FLAG , ' php-format , fuzzy, OdD-StUfF ' );
150+ $ this ->object ->set (PoTokens::FLAG , null );
151+ $ this ->assertFalse ($ this ->object ->hasFlag ('fuzzy ' ));
152+ $ this ->object ->addFlag ('fuzzy ' );
153+ $ this ->assertTrue ($ this ->object ->hasFlag ('fuzzy ' ));
154+ $ this ->assertFalse ($ this ->object ->hasFlag ('futzy ' ));
155+ $ this ->object ->addFlag ('futzy ' );
156+ $ this ->assertTrue ($ this ->object ->hasFlag ('futzy ' ));
157+
158+ $ this ->object ->set (PoTokens::FLAG , null );
159+ $ this ->object ->set (PoTokens::FLAG , ' php-format , fuzzy, OdD-StUfF ' );
112160 $ this ->assertTrue ($ this ->object ->hasFlag ('php-format ' ));
113161 $ this ->assertTrue ($ this ->object ->hasFlag ('fuzzy ' ));
114162 $ this ->assertTrue ($ this ->object ->hasFlag ('odd-stuff ' ));
115163 $ this ->assertFalse ($ this ->object ->hasFlag ('futzy ' ));
116- $ this ->object ->add (PoTokens:: FLAG , 'separate ' );
164+ $ this ->object ->add (PoTokens::FLAG , 'separate ' );
117165 $ this ->assertTrue ($ this ->object ->hasFlag ('separate ' ));
118166 $ this ->object ->addFlag ('futzy ' );
119167 $ this ->assertTrue ($ this ->object ->hasFlag ('fuzzy ' ));
0 commit comments