[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

   1  <?php
   2  
   3  class GP_Test_JSON_Pretty_Print 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  	public function setUp() {
  15          parent::setUp();
  16  
  17          $this->translation_set = $this->factory->translation_set->create_with_project_and_locale( array(), array( 'name' => 'foo_project' ) );
  18  
  19          $this->locale = new GP_Locale( array(
  20              'slug'              => $this->translation_set->locale,
  21              'nplurals'          => 2,
  22              'plural_expression' => 'n != 1',
  23          ) );
  24      }
  25  
  26  	public function test_jed1x_print_exported_file_pretty_print() {
  27          $entries = array(
  28              new Translation_Entry( array( 'singular' => 'foo', 'translations' => array( 'bar' ) ) ),
  29          );
  30  
  31          add_filter( 'gp_json_export_pretty_print', '__return_true' );
  32          $actual = GP::$formats['jed1x']->print_exported_file( $this->translation_set->project, $this->locale, $this->translation_set, $entries );
  33          remove_filter( 'gp_json_export_pretty_print', '__return_true' );
  34  
  35          // The pretty-printed output has 15 lines in total.
  36          $this->assertSame( 16, substr_count( $actual, "\n" ) );
  37      }
  38  
  39  	public function test_print_exported_file_pretty_print() {
  40          $entries = array(
  41              new Translation_Entry( array( 'singular' => 'foo', 'translations' => array( 'bar' ) ) ),
  42              new Translation_Entry( array( 'singular' => 'bar', 'translations' => array( 'baz' ) ) ),
  43          );
  44  
  45          add_filter( 'gp_json_export_pretty_print', '__return_true' );
  46          $actual = GP::$formats['json']->print_exported_file( $this->translation_set->project, $this->locale, $this->translation_set, $entries );
  47          remove_filter( 'gp_json_export_pretty_print', '__return_true' );
  48  
  49          // The pretty-printed output has 8 lines in total.
  50          $this->assertSame( 7, substr_count( $actual, "\n" ) );
  51      }
  52  }


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