[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/tests/phpunit/testcases/tests_formats/ -> test_format_resx.php (source)

   1  <?php
   2  
   3  class GP_Test_Format_ResX extends GP_UnitTestCase {
   4      function setUp() {
   5          parent::setUp();
   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 &amp;', 'аз & ти не сме &amp;', ''),
  16              array('with_comment', 'baba', 'баба', 'Me, myself & Irene'),
  17          );
  18      }
  19  
  20  	function test_export() {
  21          $set = $this->factory->translation_set->create_with_project_and_locale();
  22          $project = $set->project;
  23          $locale = $this->factory->locale->create();
  24          $entries_for_export = array();
  25  
  26          foreach( $this->entries as $sample ) {
  27              list( $context, $original, $translation, $comment ) = $sample;
  28              $entries_for_export[] = (object)array(
  29                  'context' => $context,
  30                  'singular' => $original,
  31                  'translations' => array($translation),
  32                  'extracted_comments' => $comment,
  33              );
  34          }
  35  
  36          $file_contents = file_get_contents( GP_DIR_TESTDATA . '/translation.resx.xml' );
  37          $file_contents = str_replace( '[GP VERSION]', GP_VERSION, $file_contents );
  38  
  39          $this->assertEquals( $file_contents, $this->resx->print_exported_file( $project, $locale, $set, $entries_for_export ) );
  40      }
  41  
  42  
  43  	function test_read_originals() {
  44          $translations = $this->resx->read_originals_from_file( GP_DIR_TESTDATA . '/originals.resx.xml' );
  45          $this->assertEquals( count($this->entries ), count( $translations->entries ), 'number of read originals is different from the expected' );
  46          foreach( $this->entries as $sample ) {
  47              list( $context, $original, $translation, $comment ) = $sample;
  48              $translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context, 'extracted_comments' => $comment ) );
  49              $entry = $translations->translate_entry( $translatable_entry );
  50              $this->assertEquals( $original, $entry->singular );
  51              $this->assertEquals( $context, $entry->context );
  52              $this->assertEquals( $comment, $entry->extracted_comments );
  53          }
  54      }
  55  
  56  	function test_read_translations() {
  57          $stubbed_originals = array();
  58          foreach( $this->entries as $sample ) {
  59              list( $context, $original, $translation ) = $sample;
  60              $stubbed_originals[] = new GP_Original( array( 'singular' => $original, 'context' => $context ) );
  61          }
  62          GP::$original = $this->getMockBuilder( 'GP_Original' )->setMethods( array('by_project_id') )->getMock();
  63          GP::$original->expects( $this->once() )
  64                      ->method( 'by_project_id' )
  65                      ->with( $this->equalTo(2) )
  66                      ->will( $this->returnValue($stubbed_originals) );
  67          $translations = $this->resx->read_translations_from_file( GP_DIR_TESTDATA . '/translation.resx.xml', (object)array( 'id' => 2 ) );
  68          foreach( $this->entries as $sample ) {
  69              list( $context, $original, $translation ) = $sample;
  70              $this->assertEquals( $translation, $translations->translate( $original, $context ) );
  71          }
  72      }
  73  }


Generated: Fri Mar 29 01:01:13 2024 Cross-referenced by PHPXref 0.7.1