| [ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 require_once ('init.php'); 3 4 class GP_Test_Format_ResX extends GP_UnitTestCase { 5 function GP_Test_Format_ResX() { 6 $this->resx = new GP_Format_ResX; 7 $this->entries = array( 8 array('normal_string', 'Normal String', 'Just A Normal String', ''), 9 array('with_a_quote', 'I\'m with a quote', 'I\'m with a quote', ''), 10 array('with_newlines', "new\nlines", "I\nhave\nnew\nlines", ''), 11 array('with_doublequotes', 'double "quotes"', 'I have double "quotes"', ''), 12 array('with_utf8', 'питка', 'баба ми омеси питка', ''), 13 array('with_lt', 'you < me', 'ти < аз', ''), 14 array('with_gt', 'me > you', "аз > ти", ''), 15 array('with_amps', 'me & you are not &', 'аз & ти не сме &', ''), 16 array('with_comment', 'baba', 'баба', 'Me, myself & Irene'), 17 ); 18 } 19 20 function test_export() { 21 $entries_for_export = array(); 22 foreach( $this->entries as $sample ) { 23 list( $context, $original, $translation, $comment ) = $sample; 24 $entries_for_export[] = (object)array( 25 'context' => $context, 26 'singular' => $original, 27 'translations' => array($translation), 28 'extracted_comments' => $comment, 29 ); 30 } 31 $this->assertEquals( file_get_contents( 'data/translation.resx.xml' ), $this->resx->print_exported_file( 'p', 'l', 't', $entries_for_export ) ); 32 } 33 34 35 function test_read_originals() { 36 $translations = $this->resx->read_originals_from_file( 'data/originals.resx.xml' ); 37 $this->assertEquals( count($this->entries ), count( $translations->entries ), 'number of read originals is different from the expected' ); 38 foreach( $this->entries as $sample ) { 39 list( $context, $original, $translation, $comment ) = $sample; 40 $translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context, 'extracted_comments' => $comment ) ); 41 $entry = $translations->translate_entry( $translatable_entry ); 42 $this->assertEquals( $original, $entry->singular ); 43 $this->assertEquals( $context, $entry->context ); 44 $this->assertEquals( $comment, $entry->extracted_comments ); 45 } 46 } 47 48 function test_read_translations() { 49 $stubbed_originals = array(); 50 foreach( $this->entries as $sample ) { 51 list( $context, $original, $translation ) = $sample; 52 $stubbed_originals[] = new GP_Original( array( 'singular' => $original, 'context' => $context ) ); 53 } 54 GP::$original = $this->getMock( 'GP_Original', array('by_project_id') ); 55 GP::$original->expects( $this->once() ) 56 ->method( 'by_project_id' ) 57 ->with( $this->equalTo(2) ) 58 ->will( $this->returnValue($stubbed_originals) ); 59 $translations = $this->resx->read_translations_from_file( 'data/translation.resx.xml', (object)array( 'id' => 2 ) ); 60 foreach( $this->entries as $sample ) { 61 list( $context, $original, $translation ) = $sample; 62 $this->assertEquals( $translation, $translations->translate( $original, $context ) ); 63 } 64 } 65 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat May 18 03:59:52 2013 | Hosted by follow the white rabbit. |