| [ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 require_once ('init.php'); 3 4 class GP_Test_Format_RRC extends GP_UnitTestCase { 5 function GP_Test_Format_RRC() { 6 $this->rrc = new GP_Format_RRC; 7 $this->entries = array( 8 array('WITH_LATIN1', 'for', 'für'), 9 array('WITH_UNICODE_ESCAPES', 'baba', 'баба'), 10 array('WITH_SLASHES', "twinkle\ntwinkle", "Twinkle,\nTwinkle,litle\tstar!"), 11 array('MULTIPLE[0]', 'Off', 'Off'), 12 array('MULTIPLE[1]', '1', '1'), 13 array('MULTIPLE[2]', '2', '2'), 14 array('MULTIPLE[3]', 'brun', "brun!\nbrun!"), 15 array('UNTRANSLATED', 'English string', ''), 16 array('MULTIPLE_UNTRANSLATED[0]', 'English string#0', 'Partly'), 17 array('MULTIPLE_UNTRANSLATED[1]', 'English string#1', ''), 18 ); 19 } 20 21 function test_export() { 22 $entries_for_export = array(); 23 foreach( $this->entries as $sample ) { 24 list( $context, $original, $translation ) = $sample; 25 $entries_for_export[] = (object)array( 26 'context' => $context, 27 'singular' => $original, 28 'translations' => $translation? array($translation) : array(), 29 ); 30 } 31 $this->assertDiscardWhitespace( 32 file_get_contents( 'data/translation-exported.rrc' ), 33 $this->rrc->print_exported_file( 'project', 'locale', 'translation_set', $entries_for_export ) 34 ); 35 } 36 37 function test_read_originals() { 38 $translations = $this->rrc->read_originals_from_file( 'data/originals.rrc' ); 39 40 foreach( $this->entries as $sample ) { 41 list( $context, $original, $translation ) = $sample; 42 $translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context) ); 43 $entry = $translations->translate_entry( $translatable_entry ); 44 $this->assertEquals( $original, $entry->singular ); 45 $this->assertEquals( $context, $entry->context ); 46 } 47 } 48 49 function test_read_translations() { 50 $stubbed_originals = array(); 51 foreach( $this->entries as $sample ) { 52 list( $context, $original, $translation ) = $sample; 53 $stubbed_originals[] = new GP_Original( array( 'singular' => $original, 'context' => $context ) ); 54 } 55 GP::$original = $this->getMock( 'GP_Original', array('by_project_id') ); 56 GP::$original->expects( $this->once() ) 57 ->method( 'by_project_id' ) 58 ->with( $this->equalTo(2) ) 59 ->will( $this->returnValue($stubbed_originals) ); 60 $translations = $this->rrc->read_translations_from_file( 'data/translation.rrc', (object)array( 'id' => 2 ) ); 61 foreach( $this->entries as $sample ) { 62 list( $context, $original, $translation ) = $sample; 63 $this->assertEquals( $translation, $translations->translate( $original, $context ) ); 64 } 65 } 66 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 24 03:59:35 2012 | Hosted by follow the white rabbit. |