Skip to content

Commit cb49631

Browse files
committed
Add unit tests
1 parent 16a5f6c commit cb49631

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

tests/phpunit/testdata/plugins/test-plugin-i18n-usage-errors/load.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@
3434

3535
esc_html__( 'Hello World!', 'textdomain' ); // Restricted textdomain. Severity should be 7.
3636
esc_html__( 'Hello World!', 'woocommerce' ); // Severity should be default 5.
37+
38+
// Non singular string literals.
39+
echo esc_html__( $test, 'test-plugin-i18n-usage-errors' );
40+
echo _n( $single, $plural, $number, 'test-plugin-i18n-usage-errors' );
41+
echo _n_noop( $single, $plural, 'test-plugin-i18n-usage-errors' );
42+
echo _x( $text, $context, 'test-plugin-i18n-usage-errors' );
43+
44+
// Interpolated variables.
45+
echo esc_html__( "${text}", 'test-plugin-i18n-usage-errors' );
46+
echo _n( "${single}", "${plural}", $number, 'test-plugin-i18n-usage-errors' );
47+
echo _n_noop( "${single}", "${plural}", 'test-plugin-i18n-usage-errors' );
48+
echo _x( "${text}", "${context}", 'test-plugin-i18n-usage-errors' );

tests/phpunit/tests/Checker/Checks/I18n_Usage_Check_Tests.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,36 @@ public function test_run_with_errors() {
3939
// Mismatched textdomain but not restricted and with severity 5.
4040
$this->assertCount( 1, wp_list_filter( $errors['load.php'][36][29], array( 'code' => 'WordPress.WP.I18n.TextDomainMismatch' ) ) );
4141
$this->assertSame( 5, $errors['load.php'][36][29][0]['severity'] );
42+
43+
// Non singular string literal errors.
44+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][40][10], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralSingle' ) ) );
45+
$this->assertSame( 7, $errors['load.php'][40][10][0]['severity'] );
46+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][40][19], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralPlural' ) ) );
47+
$this->assertSame( 7, $errors['load.php'][40][19][0]['severity'] );
48+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][41][15], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralSingular' ) ) );
49+
$this->assertSame( 7, $errors['load.php'][41][15][0]['severity'] );
50+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][41][24], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralPlural' ) ) );
51+
$this->assertSame( 7, $errors['load.php'][41][24][0]['severity'] );
52+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][42][10], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralText' ) ) );
53+
$this->assertSame( 7, $errors['load.php'][42][10][0]['severity'] );
54+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][42][17], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralContext' ) ) );
55+
$this->assertSame( 7, $errors['load.php'][42][17][0]['severity'] );
56+
57+
// Interpolated variable errors.
58+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][45][18], array( 'code' => 'WordPress.WP.I18n.InterpolatedVariableText' ) ) );
59+
$this->assertSame( 7, $errors['load.php'][45][18][0]['severity'] );
60+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][46][10], array( 'code' => 'WordPress.WP.I18n.InterpolatedVariableSingle' ) ) );
61+
$this->assertSame( 7, $errors['load.php'][46][10][0]['severity'] );
62+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][46][23], array( 'code' => 'WordPress.WP.I18n.InterpolatedVariablePlural' ) ) );
63+
$this->assertSame( 7, $errors['load.php'][46][23][0]['severity'] );
64+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][47][15], array( 'code' => 'WordPress.WP.I18n.InterpolatedVariableSingular' ) ) );
65+
$this->assertSame( 7, $errors['load.php'][47][15][0]['severity'] );
66+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][47][28], array( 'code' => 'WordPress.WP.I18n.InterpolatedVariablePlural' ) ) );
67+
$this->assertSame( 7, $errors['load.php'][47][28][0]['severity'] );
68+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][48][10], array( 'code' => 'WordPress.WP.I18n.InterpolatedVariableText' ) ) );
69+
$this->assertSame( 7, $errors['load.php'][48][10][0]['severity'] );
70+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][48][21], array( 'code' => 'WordPress.WP.I18n.InterpolatedVariableContext' ) ) );
71+
$this->assertSame( 7, $errors['load.php'][48][21][0]['severity'] );
4272
}
4373

4474
public function test_run_without_errors() {

0 commit comments

Comments
 (0)