[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/tests/phpunit/testcases/tests_routes/ -> test_route_translation.php (source)

   1  <?php
   2  
   3  class GP_Test_Route_Translation extends GP_UnitTestCase_Route {
   4      public $route_class = 'GP_Route_Translation';
   5  
   6  	function test_discard_warning_edit_function() {
   7          $this->set_admin_user_as_current();
   8  
   9          $set = $this->factory->translation_set->create_with_project_and_locale();
  10          $original = $this->factory->original->create( array( 'project_id' => $set->project->id, 'status' => '+active', 'singular' => 'baba' ) );
  11  
  12          // Create a translation with two warnings.
  13          $warnings = array(
  14              0 => array( 'placeholder' => 'Missing %2$s placeholder in translation.' ),
  15              1 => array( 'should_begin_on_newline' => 'Original and translation should both begin on newline.' ),
  16          );
  17          $translation = $this->factory->translation->create( array(
  18              'translation_set_id' => $set->id,
  19              'original_id'        => $original->id,
  20              'status'             => 'current',
  21              'warnings'           => $warnings,
  22          ) );
  23          $translation->set_as_current();
  24  
  25          $translations = GP::$translation->for_export( $set->project, $set, array( 'status' => 'current' ) );
  26          $this->assertCount( 2, $translations[0]->warnings );
  27  
  28          // Discard first warning.
  29          $_POST['translation_id'] = $translation->id;
  30          $_POST['index'] = 0;
  31          $_POST['key'] = 'placeholder';
  32          $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'discard-warning_0placeholder' );
  33          $this->route->discard_warning( $set->project->path, $set->locale, $set->slug );
  34  
  35          $translations = GP::$translation->for_export( $set->project, $set, array( 'status' => 'current' ) );
  36          $this->assertCount( 1, $translations[0]->warnings );
  37  
  38          // Discard second warning.
  39          $_POST['translation_id'] = $translation->id;
  40          $_POST['index'] = 1;
  41          $_POST['key'] = 'should_begin_on_newline';
  42          $_REQUEST['_gp_route_nonce'] = wp_create_nonce( 'discard-warning_1should_begin_on_newline' );
  43          $this->route->discard_warning( $set->project->path, $set->locale, $set->slug );
  44  
  45          $translations = GP::$translation->for_export( $set->project, $set, array( 'status' => 'current' ) );
  46          $this->assertSame( null, $translations[0]->warnings );
  47      }
  48  }


Generated: Fri Apr 26 01:01:24 2024 Cross-referenced by PHPXref 0.7.1