Ticket #22989: 22989-UT.diff
File 22989-UT.diff, 11.2 KB (added by , 12 years ago) |
---|
-
tests/pomo/test_mo.php
4 4 5 5 function test_mo_simple() { 6 6 $mo = new MO(); 7 $mo->import_from_file('data/pomo/simple.mo'); 8 $this->assertEquals(array('Project-Id-Version' => 'WordPress 2.6-bleeding', 'Report-Msgid-Bugs-To' => 'wp-polyglots@lists.automattic.com'), $mo->headers); 9 $this->assertEquals(2, count($mo->entries)); 10 $this->assertEquals(array('dyado'), $mo->entries['baba']->translations); 11 $this->assertEquals(array('yes'), $mo->entries["kuku\nruku"]->translations); 7 $mo->import_from_file( DIR_TESTDATA . '/pomo/simple.mo' ); 8 $this->assertEquals( array( 9 'Project-Id-Version' => 'WordPress 2.6-bleeding', 10 'Report-Msgid-Bugs-To' => 'wp-polyglots@lists.automattic.com' ), 11 $mo->headers 12 ); 13 $this->assertEquals( 2, count( $mo->entries ) ); 14 $this->assertEquals( array( 'dyado' ), $mo->entries['baba']->translations ); 15 $this->assertEquals( array( 'yes' ), $mo->entries["kuku\nruku"]->translations ); 12 16 } 13 17 14 18 function test_mo_plural() { 15 19 $mo = new MO(); 16 $mo->import_from_file('data/pomo/plural.mo'); 17 $this->assertEquals(1, count($mo->entries)); 18 $this->assertEquals(array("oney dragoney", "twoey dragoney", "manyey dragoney", "manyeyey dragoney", "manyeyeyey dragoney"), $mo->entries["one dragon"]->translations); 20 $mo->import_from_file( DIR_TESTDATA . '/pomo/plural.mo' ); 21 $this->assertEquals( 1, count( $mo->entries ) ); 22 $this->assertEquals( array( 23 "oney dragoney", 24 "twoey dragoney", 25 "manyey dragoney", 26 "manyeyey dragoney", 27 "manyeyeyey dragoney" 28 ), 29 $mo->entries["one dragon"]->translations 30 ); 19 31 20 $this->assertEquals( 'oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1));21 $this->assertEquals( 'twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', 2));22 $this->assertEquals( 'twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', -8));32 $this->assertEquals( 'oney dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 1 ) ); 33 $this->assertEquals( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', 2 ) ); 34 $this->assertEquals( 'twoey dragoney', $mo->translate_plural( 'one dragon', '%d dragons', -8 ) ); 23 35 24 36 25 $mo->set_header( 'Plural-Forms', 'nplurals=5; plural=0');37 $mo->set_header( 'Plural-Forms', 'nplurals=5; plural=0' ); 26 38 $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1)); 27 39 $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 2)); 28 40 $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', -8)); 29 41 30 $mo->set_header( 'Plural-Forms', 'nplurals=5; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;');42 $mo->set_header( 'Plural-Forms', 'nplurals=5; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;' ); 31 43 $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1)); 32 44 $this->assertEquals('manyey dragoney', $mo->translate_plural('one dragon', '%d dragons', 11)); 33 45 $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', 3)); 34 46 35 $mo->set_header( 'Plural-Forms', 'nplurals=2; plural=n !=1;');47 $mo->set_header( 'Plural-Forms', 'nplurals=2; plural=n !=1;' ); 36 48 $this->assertEquals('oney dragoney', $mo->translate_plural('one dragon', '%d dragons', 1)); 37 49 $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', 2)); 38 50 $this->assertEquals('twoey dragoney', $mo->translate_plural('one dragon', '%d dragons', -8)); … … 40 52 41 53 function test_mo_context() { 42 54 $mo = new MO(); 43 $mo->import_from_file( 'data/pomo/context.mo');55 $mo->import_from_file( DIR_TESTDATA . '/pomo/context.mo' ); 44 56 $this->assertEquals(2, count($mo->entries)); 45 57 $plural_entry = new Translation_Entry(array('singular' => 'one dragon', 'plural' => '%d dragons', 'translations' => array("oney dragoney", "twoey dragoney","manyey dragoney"), 'context' => 'dragonland')); 46 58 $this->assertEquals($plural_entry, $mo->entries[$plural_entry->key()]); … … 54 66 55 67 function test_translations_merge() { 56 68 $host = new Translations(); 57 $host->add_entry( new Translation_Entry(array('singular' => 'pink',)));58 $host->add_entry( new Translation_Entry(array('singular' => 'green',)));69 $host->add_entry( new Translation_Entry( array( 'singular' => 'pink', ) ) ); 70 $host->add_entry( new Translation_Entry( array( 'singular' => 'green', ) ) ); 59 71 $guest = new Translations(); 60 $guest->add_entry(new Translation_Entry(array('singular' => 'green',))); 61 $guest->add_entry(new Translation_Entry(array('singular' => 'red',))); 62 $host->merge_with($guest); 63 $this->assertEquals(3, count($host->entries)); 64 $this->assertEquals(array(), array_diff(array('pink', 'green', 'red'), array_keys($host->entries))); 72 $guest->add_entry( new Translation_Entry( array( 'singular' => 'green', ) ) ); 73 $guest->add_entry( new Translation_Entry( array( 'singular' => 'red', ) ) ); 74 $host->merge_with( $guest ); 75 $this->assertEquals( 3, count( $host->entries ) ); 76 $this->assertEquals( 77 array(), 78 array_diff( 79 array( 'pink', 'green', 'red' ), 80 array_keys($host->entries) 81 ) 82 ); 65 83 } 66 84 67 85 function test_export_mo_file() { 68 86 $entries = array(); 69 $entries[] = new Translation_Entry(array('singular' => 'pink', 70 'translations' => array('розов'))); 71 $no_translation_entry = new Translation_Entry(array('singular' => 'grey')); 72 $entries[] = new Translation_Entry(array('singular' => 'green', 'plural' => 'greens', 73 'translations' => array('зелен', 'зелени'))); 74 $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'color', 75 'translations' => array('червен'))); 76 $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'bull', 77 'translations' => array('бик'))); 78 $entries[] = new Translation_Entry(array('singular' => 'maroon', 'plural' => 'maroons', 'context' => 'context', 79 'translations' => array('пурпурен', 'пурпурни'))); 87 $entries[] = new Translation_Entry( array( 88 'singular' => 'pink', 89 'translations' => array('розов') ) ); 90 $no_translation_entry = new Translation_Entry( array( 'singular' => 'grey' )); 91 $entries[] = new Translation_Entry( array( 92 'singular' => 'green', 'plural' => 'greens', 93 'translations' => array('зелен', 'зелени') ) ); 94 $entries[] = new Translation_Entry( array( 95 'singular' => 'red', 'context' => 'color', 96 'translations' => array('червен') ) ); 97 $entries[] = new Translation_Entry( array( 98 'singular' => 'red', 'context' => 'bull', 99 'translations' => array('бик') ) ); 100 $entries[] = new Translation_Entry( array( 101 'singular' => 'maroon', 'plural' => 'maroons', 'context' => 'context', 102 'translations' => array( 'пурпурен', 'пурпурни' ) ) ); 80 103 81 104 $mo = new MO(); 82 $mo->set_header( 'Project-Id-Version', 'Baba Project 1.0');83 foreach( $entries as $entry) {84 $mo->add_entry( $entry);105 $mo->set_header( 'Project-Id-Version', 'Baba Project 1.0' ); 106 foreach( $entries as $entry ) { 107 $mo->add_entry( $entry ); 85 108 } 86 $mo->add_entry( $no_translation_entry);109 $mo->add_entry( $no_translation_entry ); 87 110 88 111 $temp_fn = $this->temp_filename(); 89 $mo->export_to_file( $temp_fn);112 $mo->export_to_file( $temp_fn ); 90 113 91 114 $again = new MO(); 92 $again->import_from_file( $temp_fn);115 $again->import_from_file( $temp_fn ); 93 116 94 $this->assertEquals( count($entries), count($again->entries));95 foreach( $entries as $entry) {96 $this->assertEquals( $entry, $again->entries[$entry->key()]);117 $this->assertEquals( count( $entries ), count( $again->entries ) ); 118 foreach( $entries as $entry ) { 119 $this->assertEquals( $entry, $again->entries[$entry->key()] ); 97 120 } 98 121 } 99 122 … … 106 129 $mo->export_to_file( $temp_fn ); 107 130 108 131 $again = new MO(); 109 $again->import_from_file( $temp_fn);132 $again->import_from_file( $temp_fn ); 110 133 111 134 $this->assertEquals( 0, count( $again->entries ) ); 112 135 } 113 136 114 137 function test_nplurals_with_backslashn() { 115 138 $mo = new MO(); 116 $mo->import_from_file( 'data/pomo/bad_nplurals.mo');117 $this->assertEquals( '%d foro', $mo->translate_plural('%d forum', '%d forums', 1));118 $this->assertEquals( '%d foros', $mo->translate_plural('%d forum', '%d forums', 2));119 $this->assertEquals( '%d foros', $mo->translate_plural('%d forum', '%d forums', -1));139 $mo->import_from_file( DIR_TESTDATA . '/pomo/bad_nplurals.mo' ); 140 $this->assertEquals( '%d foro', $mo->translate_plural( '%d forum', '%d forums', 1 ) ); 141 $this->assertEquals( '%d foros', $mo->translate_plural( '%d forum', '%d forums', 2 ) ); 142 $this->assertEquals( '%d foros', $mo->translate_plural( '%d forum', '%d forums', -1 ) ); 120 143 } 121 144 122 145 function disabled_test_performance() { 123 $start = microtime( true);146 $start = microtime( true ); 124 147 $mo = new MO(); 125 $mo->import_from_file( 'data/pomo/de_DE-2.8.mo');148 $mo->import_from_file( DIR_TESTDATA . '/pomo/de_DE-2.8.mo' ); 126 149 // echo "\nPerformance: ".(microtime(true) - $start)."\n"; 127 150 } 128 151 129 152 function test_overloaded_mb_functions() { 130 153 // skipIf() method skips the whole test case, not only this method 131 154 // that's why we are skipping it the stupid way 132 if ( (ini_get("mbstring.func_overload") & 2) != 0) {155 if ( ( ini_get( "mbstring.func_overload" ) & 2 ) != 0 ) { 133 156 $mo = new MO(); 134 $mo->import_from_file( 'data/pomo/overload.mo');135 $this->assertEquals( array('Табло'), $mo->entries['Dashboard']->translations);157 $mo->import_from_file( DIR_TESTDATA . '/pomo/overload.mo' ); 158 $this->assertEquals( array( 'Табло' ), $mo->entries['Dashboard']->translations ); 136 159 } 137 160 } 138 161 139 162 function test_load_pot_file() { 140 163 $mo = new MO(); 141 $this->assertEquals( false, $mo->import_from_file( 'data/pomo/mo.pot') );164 $this->assertEquals( false, $mo->import_from_file( DIR_TESTDATA . '/pomo/mo.pot' ) ); 142 165 } 143 166 } -
tests/pomo/test_po.php
174 174 175 175 function test_import_from_file() { 176 176 $po = new PO(); 177 $res = $po->import_from_file( 'data/pomo/simple.po');177 $res = $po->import_from_file( DIR_TESTDATA . '/pomo/simple.po' ); 178 178 $this->assertEquals(true, $res); 179 179 180 180 $this->assertEquals(array('Project-Id-Version' => 'WordPress 2.6-bleeding', 'Plural-Forms' => 'nplurals=2; plural=n != 1;'), $po->headers); … … 204 204 205 205 function test_import_from_entry_file_should_give_false() { 206 206 $po = new PO(); 207 $this->assertFalse( $po->import_from_file( 'data/pomo/empty.po' ) );207 $this->assertFalse( $po->import_from_file( DIR_TESTDATA . '/pomo/empty.po' ) ); 208 208 } 209 209 210 210 function test_import_from_file_with_windows_line_endings_should_work_as_with_unix_line_endings() { 211 211 $po = new PO(); 212 $this->assertTrue( $po->import_from_file( 'data/pomo/windows-line-endings.po' ) );212 $this->assertTrue( $po->import_from_file( DIR_TESTDATA . '/pomo/windows-line-endings.po' ) ); 213 213 $this->assertEquals( 1, count( $po->entries ) ); 214 214 } 215 215 216 216 //TODO: add tests for bad files 217 217 } 218 ?>