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