[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

   1  <?php
   2  
   3  class GP_Test_Format_Properties extends GP_UnitTestCase {
   4  
   5      function setUp() {
   6          parent::setUp();
   7          $this->properties = new GP_Format_Properties;
   8          $this->entries = array(
   9              array('normal_string', 'Normal String', 'Just A Normal String', ''),
  10              array('normal_string_with_colan', 'Normal String', 'Just A Normal String', ''),
  11              array('with_a_quote', 'I\'m with a quote', 'I\'m with a quote', ''),
  12              array('with_newlines', 'new\nlines', 'new\nlines', ''),
  13              array('with_doublequotes', 'double "quotes"', 'I have double "quotes"', ''),
  14              array('with_utf8', 'питка', 'баба ми омеси питка', ''),
  15              array('with_lt', 'you < me', 'ти < аз', ''),
  16              array('with_gt', 'me > you', 'аз > ти', ''),
  17              array('with_amps', 'me & you are not &amp;', 'аз & ти не сме &amp;', ''),
  18              array('with_comment', 'baba', 'баба', 'Me, myself & Irene'),
  19          );
  20      }
  21  
  22  	function test_export() {
  23          $set = $this->factory->translation_set->create_with_project_and_locale();
  24          $project = $set->project;
  25          $locale = $this->factory->locale->create();
  26          $entries_for_export = array();
  27  
  28          foreach( $this->entries as $sample ) {
  29              list( $context, $original, $translation, $comment ) = $sample;
  30  
  31              $entries_for_export[] = (object)array(
  32                  'context' => $context,
  33                  'singular' => $original,
  34                  'translations' => array($translation),
  35                  'extracted_comments' => $comment,
  36              );
  37          }
  38  
  39          $file_contents = file_get_contents( GP_DIR_TESTDATA . '/translation.properties' );
  40          $file_contents = str_replace( '[GP VERSION]', GP_VERSION, $file_contents );
  41          
  42          $exported = $this->properties->print_exported_file( $project, $locale, $set, $entries_for_export );
  43  
  44          $this->assertEquals( $file_contents, $exported );
  45      }
  46  
  47  	function test_read_originals() {
  48          $translations = $this->properties->read_originals_from_file( GP_DIR_TESTDATA . '/originals.properties' );
  49          
  50          // We're adding one extra to the count for the entries because the file contains a multi-line entry that we want to test reading but don't test writing later.
  51          $this->assertEquals( count( $this->entries ) + 1, count( $translations->entries ), 'number of read originals is different from the expected' );
  52  
  53          foreach( $this->entries as $sample ) {
  54              list( $context, $original, $translation, $comment ) = $sample;
  55              $translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context, 'extracted_comments' => $comment ) );
  56              $entry = $translations->translate_entry( $translatable_entry );
  57              $this->assertEquals( $original, $entry->singular );
  58              $this->assertEquals( $context, $entry->context );
  59              $this->assertEquals( $comment, $entry->extracted_comments );
  60          }
  61      }
  62  
  63  	function test_read_translations() {
  64          $stubbed_originals = array();
  65  
  66          foreach( $this->entries as $sample ) {
  67              list( $context, $original, $translation ) = $sample;
  68              $stubbed_originals[] = new GP_Original( array( 'singular' => $original, 'context' => $context ) );
  69          }
  70  
  71          GP::$original = $this->getMockBuilder( 'GP_Original' )->setMethods( array('by_project_id') )->getMock();
  72          GP::$original->expects( $this->once() )
  73                      ->method( 'by_project_id' )
  74                      ->with( $this->equalTo(2) )
  75                      ->will( $this->returnValue($stubbed_originals) );
  76  
  77          $translations = $this->properties->read_translations_from_file( GP_DIR_TESTDATA . '/translation.properties', (object)array( 'id' => 2 ) );
  78  
  79          foreach( $this->entries as $sample ) {
  80              list( $context, $original, $translation ) = $sample;
  81              $this->assertEquals( $translation, $translations->translate( $original, $context ) );
  82          }
  83      }
  84  
  85  }


Generated: Tue Oct 8 01:01:03 2024 Cross-referenced by PHPXref 0.7.1