Skip to content

Commit 7be3c70

Browse files
committed
Add unit tests
1 parent 16a5f6c commit 7be3c70

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@
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' );

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ 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+
// print_r( $errors );
44+
45+
// Non singular string literal errors.
46+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][40][10], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralSingle' ) ) );
47+
$this->assertSame( 7, $errors['load.php'][40][10][0]['severity'] );
48+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][40][19], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralPlural' ) ) );
49+
$this->assertSame( 7, $errors['load.php'][40][19][0]['severity'] );
50+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][41][15], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralSingular' ) ) );
51+
$this->assertSame( 7, $errors['load.php'][41][15][0]['severity'] );
52+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][41][24], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralPlural' ) ) );
53+
$this->assertSame( 7, $errors['load.php'][41][24][0]['severity'] );
54+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][42][10], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralText' ) ) );
55+
$this->assertSame( 7, $errors['load.php'][42][10][0]['severity'] );
56+
$this->assertCount( 1, wp_list_filter( $errors['load.php'][42][17], array( 'code' => 'WordPress.WP.I18n.NonSingularStringLiteralContext' ) ) );
57+
$this->assertSame( 7, $errors['load.php'][42][17][0]['severity'] );
4258
}
4359

4460
public function test_run_without_errors() {

0 commit comments

Comments
 (0)