forked from GlotPress/GlotPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_builtin_errors.php
121 lines (111 loc) · 5.46 KB
/
test_builtin_errors.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
class GP_Test_Builtin_Translation_Errors extends GP_UnitTestCase {
function setUp(): void {
parent::setUp();
$this->w = new GP_Builtin_Translation_Errors();
$this->l = $this->factory->locale->create();
$project = $this->factory->project->create();
$this->original = $this->factory->original->create( array( 'project_id' => $project->id ) );
$this->original->comment = 'Test comment';
}
function _assertError( $assert, $error, $original, $translation, $gp_original = null, $locale = null ) {
if ( is_null( $locale ) ) {
$locale = $this->l;
}
$method = "error_$error";
$this->$assert( true, $this->w->$method( $original, $translation, $gp_original, $locale ) );
}
function assertHasErrors( $error, $original, $translation, $gp_original, $locale = null ) {
$this->_assertError( 'assertNotSame', $error, $original, $translation, $gp_original, $locale );
}
function assertNoErrors( $error, $original, $translation, $gp_original = null, $locale = null ) {
$this->_assertError( 'assertSame', $error, $original, $translation, $gp_original, $locale );
}
function assertHasErrorsAndContainsOutput( $error, $original, $translation, $gp_original, $output_expected, $locale = null ) {
$this->assertHasErrors( $error, $original, $translation, $gp_original, $locale );
if ( is_null( $locale ) ) {
$locale = $this->l;
}
$method = "error_$error";
$this->assertStringContainsString( $output_expected, $this->w->$method( $original, $translation, $gp_original, $locale ) );
}
function assertContainsOutput( $singular, $plural, $translations, $comment, $output_expected, $locale = null ) {
if ( is_null( $locale ) ) {
$locale = $this->l;
}
$this->assertEquals( $output_expected, $this->tw->check( $singular, $plural, $translations, $comment, $locale ) );
}
function test_error_unexpected_sprintf_token() {
$this->assertNoErrors( 'unexpected_sprintf_token', '100 percent', '100%' );
$this->assertNoErrors( 'unexpected_sprintf_token', '<a href="%a">100 percent</a>', '<a href="%a">100%</a>' );
$this->assertNoErrors( 'unexpected_sprintf_token', '<a href="%s">100 percent</a>', '<a href="%s">100%%</a>' );
$this->assertNoErrors( 'unexpected_sprintf_token', '<a href="%1$s">100 percent</a>', '<a href="%1$s">100%%</a>' );
$this->assertNoErrors( 'unexpected_sprintf_token', '%1$.2f baba', '%1$.2f баба' );
$this->assertNoErrors( 'unexpected_sprintf_token', '%1$.2f baba', '%1$.3f баба' );
$this->assertNoErrors( 'unexpected_sprintf_token', '%2$.2fMB baba', '%2$.2fMB баба' );
$this->assertNoErrors( 'unexpected_sprintf_token', '%2$.3fMB baba', '%2$.2fMB баба' );
$this->assertNoErrors( 'unexpected_sprintf_token', 'Data: %1$.2fMB | Index: %2$.2fMB | Free: %3$.2fMB | Engine: %4$s', 'Data: %1$.2fMB | Index: %2$.2fMB | Free: %3$.2fMB | Engine: %4$s' );
$this->assertNoErrors( 'unexpected_sprintf_token', 'This is 100 percent bug free!', 'This is 100% bug free!' );
$this->assertNoErrors( 'unexpected_sprintf_token', '<a href="%f">95 percent</a>', '<a href="%F">95 percent</a>' );
$this->assertNoErrors( 'unexpected_sprintf_token', '<a href="%S">95 percent</a>', '<a href="%s">95 percent</a>' );
$this->assertNoErrors( 'unexpected_sprintf_token', '%2$.2f baba', '%2$.2F баба' );
$this->assertNoErrors( 'unexpected_sprintf_token', '%2$.2F baba', '%2$.2f баба' );
$this->assertNoErrors(
'unexpected_sprintf_token',
'The %s contains %d items',
'El %s contiene %d elementos'
);
$this->assertNoErrors(
'unexpected_sprintf_token',
'The %2$s contains %1$d items. That\'s a nice %2$s full of %1$d items.',
'El %2$s contiene %1$d elementos. Es un bonito %2$s lleno de %1$d elementos.'
);
$this->assertNoErrors(
'unexpected_sprintf_token',
'The application password %friendly_name%.',
'La contraseña de aplicación %friendly_name%.'
);
$this->assertHasErrorsAndContainsOutput(
'unexpected_sprintf_token',
'<a href="%d">100 percent</a>',
'<a href="%d">100%</a>',
null,
'The translation contains the following unexpected placeholders: 00%<'
);
$this->assertHasErrorsAndContainsOutput(
'unexpected_sprintf_token',
'95 percent of <a href="%f">100 percent</a>',
'95% of <a href="%f">100%%</a>',
null,
'The translation contains the following unexpected placeholders: 95% (unescaped %, use %% instead)'
);
$this->assertHasErrorsAndContainsOutput(
'unexpected_sprintf_token',
'<a href="%f">95 percent</a> of 100 percent',
'<a href="%f">95%%</a> of 100%',
null,
'The translation contains the following unexpected placeholders: 00% (unescaped %, use %% instead)'
);
$this->assertHasErrorsAndContainsOutput(
'unexpected_sprintf_token',
'<a href="%f">95 percent</a> of 100 percent!',
'<a href="%f">95%%</a> of 100%!',
null,
'The translation contains the following unexpected placeholders: 00%! (unescaped %, use %% instead)'
);
$this->assertHasErrorsAndContainsOutput(
'unexpected_sprintf_token',
'<a href="%f">95 percent</a> of 100 percent',
'<a href="%f">95%</a> of 100%',
null,
'The translation contains the following unexpected placeholders: 95%< (unescaped %, use %% instead), 00% (unescaped %, use %% instead)'
);
$this->assertHasErrorsAndContainsOutput(
'unexpected_sprintf_token',
'This is 100 percent bug free! <a href="%s">See this for proof</a>',
'Yo! We so great! 100% bug free! <a href="%s">Check it!</a>',
null,
'The translation contains the following unexpected placeholders: 00%'
);
}
}