[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

   1  <?php
   2  
   3  class GP_Test_Format_Jed1x extends GP_UnitTestCase {
   4      /**
   5       * @var GP_Translation_Set
   6       */
   7      protected $translation_set;
   8  
   9      /**
  10       * @var GP_Locale
  11       */
  12      protected $locale;
  13  
  14      /**
  15       * @var string
  16       */
  17      protected $format = 'jed1x';
  18  
  19  	public function setUp() {
  20          parent::setUp();
  21  
  22          $this->translation_set = $this->factory->translation_set->create_with_project_and_locale( array(), array( 'name' => 'foo_project' ) );
  23  
  24          $this->locale = new GP_Locale( array(
  25              'slug'                => $this->translation_set->locale,
  26              'nplurals'            => 2,
  27              'plural_expression'   => 'n != 1',
  28              'lang_code_iso_639_1' => $this->translation_set->locale,
  29          ) );
  30      }
  31  
  32  	public function test_format_name() {
  33          $this->assertSame( 'Jed 1.x (.json)', GP::$formats[ $this->format ]->name );
  34      }
  35  
  36  	public function test_format_extension() {
  37          $this->assertSame( 'jed.json', GP::$formats[ $this->format ]->extension );
  38      }
  39  
  40  	public function test_print_exported_file_can_be_decoded() {
  41          $entries = array(
  42              new Translation_Entry( array( 'singular' => 'foo', 'translations' => array( 'foox' ) ) ),
  43          );
  44  
  45          $json = GP::$formats[ $this->format ]->print_exported_file( $this->translation_set->project, $this->locale, $this->translation_set, $entries );
  46  
  47          $this->assertNotNull( json_decode( $json, true ) );
  48      }
  49  
  50  	public function test_print_exported_file_has_valid_format() {
  51          $entries = array(
  52              new Translation_Entry( array( 'singular' => 'foo', 'translations' => array( 'bar' ) ) ),
  53          );
  54  
  55          $json = GP::$formats[ $this->format ]->print_exported_file( $this->translation_set->project, $this->locale, $this->translation_set, $entries );
  56  
  57          $actual = json_decode( $json, true );
  58  
  59          $this->assertEquals( array(
  60              'translation-revision-date' => '+0000',
  61              'generator'                 => 'GlotPress/' . GP_VERSION,
  62              'domain'                    => 'messages',
  63              'locale_data'               => array(
  64                  'messages' => array(
  65                      ''    => array(
  66                          'domain'       => 'messages',
  67                          'plural-forms' => 'nplurals=2; plural=n != 1;',
  68                          'lang'         => $this->translation_set->locale,
  69                      ),
  70                      'foo' => array( 'bar' ),
  71                  ),
  72              ),
  73          ), $actual );
  74      }
  75  
  76      public function test_read_originals_from_file_non_existent_file() {
  77          $this->assertFalse( GP::$formats[ $this->format ]->read_originals_from_file( GP_DIR_TESTDATA . '/foo.json' ) );
  78      }
  79  
  80  	public function test_read_originals_from_file_invalid_file() {
  81          $this->assertFalse( GP::$formats[ $this->format ]->read_originals_from_file( GP_DIR_TESTDATA . '/invalid.json' ) );
  82      }
  83  
  84  	public function test_read_originals_from_file_missing_domain() {
  85          $this->assertFalse( GP::$formats[ $this->format ]->read_originals_from_file( GP_DIR_TESTDATA . '/translation-jed1x-missing-domain.json' ) );
  86      }
  87  
  88      public function test_read_originals_from_file_missing_locale_data() {
  89          $this->assertFalse( GP::$formats[ $this->format ]->read_originals_from_file( GP_DIR_TESTDATA . '/translation-jed1x-missing-locale-data.json' ) );
  90      }
  91  
  92  	public function test_read_originals_from_file() {
  93          $expected = $this->data_example_originals();
  94  
  95          /* @var Translations $actual */
  96          $actual = GP::$formats[ $this->format ]->read_originals_from_file( GP_DIR_TESTDATA . '/originals-jed1x.json' );
  97          $this->assertSame( 5, count( $actual->entries ) );
  98          $this->assertEquals( $expected, $actual );
  99      }
 100  
 101      public function test_read_translations_from_file_non_existent_file() {
 102          $this->assertFalse( GP::$formats[ $this->format ]->read_translations_from_file( GP_DIR_TESTDATA . '/foo.json' ) );
 103      }
 104  
 105      public function test_read_translations_from_file_missing_domain() {
 106          $this->assertFalse( GP::$formats[ $this->format ]->read_translations_from_file( GP_DIR_TESTDATA . '/translation-jed1x-missing-domain.json' ) );
 107      }
 108  
 109      public function test_read_translations_from_file_missing_locale_data() {
 110          $this->assertFalse( GP::$formats[ $this->format ]->read_translations_from_file( GP_DIR_TESTDATA . '/translation-jed1x-missing-locale-data.json' ) );
 111      }
 112  
 113  	public function test_read_translations_from_file() {
 114          $expected = $this->data_example_translations();
 115  
 116          /* @var Translations $actual */
 117          $actual = GP::$formats[ $this->format ]->read_translations_from_file( GP_DIR_TESTDATA . '/translation-jed1x.json' );
 118  
 119          $this->assertCount( 5, $actual->entries );
 120          $this->assertEquals( $expected, $actual );
 121      }
 122  
 123      /**
 124       * Returns the expected data for the parsed example-untranslated.json file.
 125       */
 126  	public function data_example_originals() {
 127          $translations = new Translations();
 128          $translations->add_entry( new Translation_Entry( array(
 129              'singular' => 'This file is too big. Files must be less than %d KB in size.',
 130          ) ) );
 131          $translations->add_entry( new Translation_Entry( array(
 132              'singular' => '%d Theme Update',
 133          ) ) );
 134          $translations->add_entry( new Translation_Entry( array(
 135              'singular' => 'Medium',
 136              'context'  => 'password strength',
 137          ) ) );
 138          $translations->add_entry( new Translation_Entry( array(
 139              'singular' => 'Category',
 140              'context'  => 'taxonomy singular name',
 141          ) ) );
 142          $translations->add_entry( new Translation_Entry( array(
 143              'singular' => 'Pages',
 144              'context'  => 'post type general name',
 145          ) ) );
 146  
 147          return $translations;
 148      }
 149  
 150      /**
 151       * Returns the expected data for the parsed example-untranslated.json file.
 152       */
 153  	public function data_example_translations() {
 154          $translations = new Translations();
 155          $translations->add_entry( new Translation_Entry( array(
 156              'singular'     => 'This file is too big. Files must be less than %d KB in size.',
 157              'translations' => array(
 158                  'Diese Datei ist zu gross. Dateien müssen kleiner als %d KB sein.',
 159              )
 160          ) ) );
 161          $translations->add_entry( new Translation_Entry( array(
 162              'singular'     => '%d Theme Update',
 163              'translations' => array(
 164                  '%d Theme-Aktualisierung',
 165                  '%d Theme-Aktualisierungen',
 166              ),
 167          ) ) );
 168          $translations->add_entry( new Translation_Entry( array(
 169              'singular'     => 'Medium',
 170              'context'      => 'password strength',
 171              'translations' => array(
 172                  'Medium',
 173              )
 174          ) ) );
 175          $translations->add_entry( new Translation_Entry( array(
 176              'singular'     => 'Category',
 177              'context'      => 'taxonomy singular name',
 178              'translations' => array(
 179                  'Kategorie',
 180              )
 181          ) ) );
 182          $translations->add_entry( new Translation_Entry( array(
 183              'singular'     => 'Pages',
 184              'context'      => 'post type general name',
 185              'translations' => array(
 186                  'Seiten',
 187              )
 188          ) ) );
 189  
 190          return $translations;
 191      }
 192  }


Generated: Sun Dec 22 01:01:04 2024 Cross-referenced by PHPXref 0.7.1