[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/tests/phpunit/testcases/ -> test_warnings.php (source)

   1  <?php
   2  
   3  class GP_Test_Translation_Warnings extends GP_UnitTestCase {
   4  	function setUp() {
   5          parent::setUp();
   6          $this->is_baba = function( $o, $t, $l ) {
   7              return $t == "баба"? true : "error";
   8              };
   9          $this->is_equal = function( $o, $t, $l ) {
  10              return $t == $o? true : "error";
  11              };
  12          $this->w = new GP_Translation_Warnings;
  13          $this->with_equal = new GP_Translation_Warnings;
  14          $this->with_equal->add( 'is_equal', $this->is_equal );
  15          $this->standard_plural_locale = $this->factory->locale->create();
  16      }
  17  
  18  	function test_add() {
  19          $this->w->add( 'is_baba', $this->is_baba );
  20          $this->assertEquals( true, $this->w->has( 'is_baba' ) );
  21          $this->assertEquals( false, $this->w->has( 'is_dyado' ) );
  22      }
  23  
  24  	function test_remove() {
  25          $this->w->add( 'is_baba', $this->is_baba );
  26          $this->assertEquals( true, $this->w->has( 'is_baba' ) );
  27          $this->w->remove( 'is_baba' );
  28          $this->assertEquals( false, $this->w->has( 'is_baba' ) );
  29      }
  30  
  31  	function test_check() {
  32          $this->w->add( 'is_baba', $this->is_baba );
  33          $this->assertEquals( array(
  34              1 => array('is_baba' => 'error')),
  35              $this->w->check( 'baba', null, array('баба', 'баби'), $this->standard_plural_locale ) );
  36          $this->assertEquals( null,
  37              $this->w->check( 'baba', null, array('баба', 'баба', 'баба'), $this->standard_plural_locale ) );
  38      }
  39  
  40      /**
  41       * For the plural form, corresponding to the number 1 check only against the singular, not also against the plural
  42       */
  43  	function test_check_singular_plural_correspondence() {
  44          $this->assertEquals( null,
  45              $this->with_equal->check( 'baba', 'babas', array('baba', 'babas'), $this->standard_plural_locale ) );
  46          $this->assertEquals( array(1 => array('is_equal' => 'error')),
  47              $this->with_equal->check( 'baba', 'babas', array('baba', 'baba'), $this->standard_plural_locale ) );
  48          $this->assertEquals( array(0 => array('is_equal' => 'error')),
  49              $this->with_equal->check( 'baba', 'babas', array('babas', 'babas'), $this->standard_plural_locale ) );
  50      }
  51  
  52      /**
  53       * If a locale has no plural forms, we should check only against the plural original, since
  54       * it probably contains the placeholders
  55       */
  56  	function test_check_no_plural_forms_locales() {
  57          $no_plural_locale = new GP_Locale;
  58          $no_plural_locale->nplurals = 1;
  59          $no_plural_locale->plural_expression = '0';
  60          $this->assertEquals( null,
  61              $this->with_equal->check( 'baba', 'babas', array('babas'), $no_plural_locale ) );
  62          $this->assertEquals( array(0 => array('is_equal' => 'error')),
  63              $this->with_equal->check( 'baba', 'babas', array('baba'), $no_plural_locale ) );
  64          $this->assertEquals( array(0 => array('is_equal' => 'error')),
  65              $this->with_equal->check( 'baba', 'babas', array('xxx'), $no_plural_locale ) );
  66  
  67      }
  68  }


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