[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

   1  <?php
   2  
   3  class GP_Test_Format_Strings extends GP_UnitTestCase {
   4  
   5      function setUp() {
   6          parent::setUp();
   7          $this->strings = new GP_Format_Strings;
   8          $this->entries = array(
   9              array( 'Normal String', 'Normal String', 'Just A Normal String', '' ),
  10              array( 'I\'m with a quote', 'I\'m with a quote', 'I\'m with a quote', '' ),
  11              array( 'double "quotes"', 'double "quotes"', 'I have double "quotes"', '' ),
  12              array( 'питка', 'питка', 'баба ми омеси питка', '' ),
  13              array( 'you < me', 'you < me', 'ти < аз', '' ),
  14              array( 'me > you', 'me > you', "аз > ти", '' ),
  15              array( 'me & you are not &amp;', 'me & you are not &amp;', 'аз & ти не сме &amp;', '' ),
  16              array( 'baba', 'baba', 'баба', 'Me, myself & Irene' ),
  17              array( 'Trash-noun', 'Trash', 'Cestino', 'The place where deleted posts first go' ), // Italian
  18              array( 'Trash-verb', 'Trash', 'Elimina', 'The act of deleting a post into trash' ), // Italian
  19              array( 'multiline', 'multiline', 'multiline', 'This is
  20     a multiline
  21     comment which is
  22     also supposed to work.' ),
  23          );
  24      }
  25  
  26  	function test_export() {
  27          $set = $this->factory->translation_set->create_with_project_and_locale();
  28          $project = $set->project;
  29          $locale = $this->factory->locale->create();
  30          $entries_for_export = array();
  31  
  32          foreach( $this->entries as $sample ) {
  33              list( $context, $original, $translation, $comment ) = $sample;
  34  
  35              $entries_for_export[] = (object)array(
  36                  'context' => $context,
  37                  'singular' => $original,
  38                  'translations' => array($translation),
  39                  'extracted_comments' => $comment,
  40              );
  41          }
  42  
  43          $file_contents = file_get_contents( GP_DIR_TESTDATA . '/translation.strings' );
  44          $file_contents = str_replace( '[GP VERSION]', GP_VERSION, $file_contents );
  45          // Remove the UTF-8 Byte Order Mark which is necessary to ensure a UTF-8 detection of the file.
  46          $file_contents = substr( $file_contents, 3 );
  47  
  48          $exported = $this->strings->print_exported_file( $project, $locale, $set, $entries_for_export );
  49  
  50          $this->assertEquals( $file_contents, $exported );
  51      }
  52  
  53  	function test_read_originals() {
  54          $translations = $this->strings->read_originals_from_file( GP_DIR_TESTDATA . '/originals.strings' );
  55          $this->assertEquals( count( $this->entries ), count( $translations->entries ), 'number of read originals is different from the expected' );
  56  
  57          foreach( $this->entries as $sample ) {
  58              list( $context, $original, $translation, $comment ) = $sample;
  59              $translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context, 'extracted_comments' => $comment ) );
  60              $entry = $translations->translate_entry( $translatable_entry );
  61              $this->assertEquals( $original, $entry->singular );
  62              $this->assertEquals( $context, $entry->context );
  63              $this->assertEquals( $comment, $entry->extracted_comments );
  64          }
  65      }
  66  
  67  	function test_read_originals_from_UTF16LE() {
  68          $translations = $this->strings->read_originals_from_file( GP_DIR_TESTDATA . '/originals.16le.strings' );
  69          $this->assertEquals( count( $this->entries ), count( $translations->entries ), 'number of read originals is different from the expected' );
  70  
  71          foreach( $this->entries as $sample ) {
  72              list( $context, $original, $translation, $comment ) = $sample;
  73              $translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context, 'extracted_comments' => $comment ) );
  74              $entry = $translations->translate_entry( $translatable_entry );
  75              $this->assertEquals( $original, $entry->singular );
  76              $this->assertEquals( $context, $entry->context );
  77              $this->assertEquals( $comment, $entry->extracted_comments );
  78          }
  79      }
  80  
  81  	function test_read_translations() {
  82          $stubbed_originals = array();
  83  
  84          foreach( $this->entries as $sample ) {
  85              list( $context, $original, $translation ) = $sample;
  86              $stubbed_originals[] = new GP_Original( array( 'singular' => $original, 'context' => $context ) );
  87          }
  88  
  89          GP::$original = $this->getMockBuilder( 'GP_Original' )->setMethods( array('by_project_id') )->getMock();
  90          GP::$original->expects( $this->once() )
  91                      ->method( 'by_project_id' )
  92                      ->with( $this->equalTo(2) )
  93                      ->will( $this->returnValue($stubbed_originals) );
  94  
  95          $translations = $this->strings->read_translations_from_file( GP_DIR_TESTDATA . '/translation.strings', (object)array( 'id' => 2 ) );
  96  
  97          foreach( $this->entries as $sample ) {
  98              list( $context, $original, $translation ) = $sample;
  99              $this->assertEquals( $translation, $translations->translate( $original, $context ) );
 100          }
 101      }
 102  
 103  }


Generated: Thu Nov 21 01:01:07 2024 Cross-referenced by PHPXref 0.7.1