[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/t/ -> test_format_android.php (source)

   1  <?php
   2  require_once ('init.php');
   3  
   4  class GP_Test_Format_Android extends GP_UnitTestCase {
   5      function GP_Test_Format_Android() {
   6          $this->android = new GP_Format_Android;
   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 &amp;', 'аз & ти не сме &amp;'),
  16          );        
  17      }
  18      
  19  	function test_export() {
  20          $entries_for_export = array();
  21          foreach( $this->entries as $sample ) {
  22              list( $context, $original, $translation ) = $sample;
  23              $entries_for_export[] = (object)array(
  24                  'context' => $context,
  25                  'singular' => $original,
  26                  'translations' => array($translation),
  27              );
  28          }
  29          $this->assertEquals( file_get_contents( 'data/translation.android.xml' ), $this->android->print_exported_file( 'p', 'l', 't', $entries_for_export ) );
  30      }
  31      
  32      
  33  	function test_read_originals() {
  34          $translations = $this->android->read_originals_from_file( 'data/originals.android.xml' );
  35                  
  36          foreach( $this->entries as $sample ) {
  37              list( $context, $original, $translation ) = $sample;
  38              $translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context) );
  39              $entry = $translations->translate_entry( $translatable_entry );
  40              $this->assertEquals( $original, $entry->singular );
  41              $this->assertEquals( $context, $entry->context );
  42          }
  43      }
  44      
  45  	function test_read_translations() {
  46          $stubbed_originals = array();
  47          foreach( $this->entries as $sample ) {
  48              list( $context, $original, $translation ) = $sample;
  49              $stubbed_originals[] = new GP_Original( array( 'singular' => $original, 'context' => $context ) );
  50          }
  51          GP::$original = $this->getMock( 'GP_Original', array('by_project_id') );
  52          GP::$original->expects( $this->once() )
  53                      ->method( 'by_project_id' )
  54                      ->with( $this->equalTo(2) )
  55                      ->will( $this->returnValue($stubbed_originals) );
  56          $translations = $this->android->read_translations_from_file( 'data/translation.android.xml', (object)array( 'id' => 2 ) );
  57          foreach( $this->entries as $sample ) {
  58              list( $context, $original, $translation ) = $sample;
  59              $this->assertEquals( $translation, $translations->translate( $original, $context ) );
  60          }
  61      }
  62      
  63  }


Generated: Thu May 24 03:59:35 2012 Hosted by follow the white rabbit.