Skip to content

Commit fbcdd23

Browse files
committed
WP/I18n: add tests for namespaced names
I'm adding three different tests for fully qualified global function calls to cover all the global functions that are referenced directly in the `I18nSniff::process_matched_token()` method.
1 parent 34f4104 commit fbcdd23

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

WordPress/Tests/WP/I18nUnitTest.1.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,14 @@ esc_html_e( 'foo', '' ); // Bad: text-domain can not be empty.
317317
// PHP 8.0+: safeguard handling of newly introduced placeholders.
318318
__( 'There are %1$h monkeys in the %H', 'my-slug' ); // Bad: multiple arguments should be numbered.
319319

320+
/*
321+
* Safeguard correct handling of all types of namespaced function calls.
322+
*/
323+
\_( 'foo', 'my-slug' ); // Bad.
324+
\translate( 'foo', 'my-slug' ); // Bad.
325+
\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Bad.
326+
MyNamespace\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Ok.
327+
\MyNamespace\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Ok.
328+
namespace\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // The sniff should start flagging this once it can resolve relative namespaces.
329+
320330
// phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment

WordPress/Tests/WP/I18nUnitTest.1.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,14 @@ esc_html_e( 'foo', '' ); // Bad: text-domain can not be empty.
317317
// PHP 8.0+: safeguard handling of newly introduced placeholders.
318318
__( 'There are %1$h monkeys in the %H', 'my-slug' ); // Bad: multiple arguments should be numbered.
319319

320+
/*
321+
* Safeguard correct handling of all types of namespaced function calls.
322+
*/
323+
\_( 'foo', 'my-slug' ); // Bad.
324+
\translate( 'foo', 'my-slug' ); // Bad.
325+
\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Bad.
326+
MyNamespace\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Ok.
327+
\MyNamespace\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Ok.
328+
namespace\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // The sniff should start flagging this once it can resolve relative namespaces.
329+
320330
// phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment

WordPress/Tests/WP/I18nUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function getErrorList( $testFile = '' ) {
148148
311 => 1,
149149
315 => 1,
150150
318 => 1,
151+
323 => 1,
151152
);
152153

153154
case 'I18nUnitTest.2.inc':
@@ -217,6 +218,8 @@ public function getWarningList( $testFile = '' ) {
217218
300 => 1,
218219
301 => 1,
219220
302 => 1,
221+
324 => 1,
222+
325 => 1,
220223
);
221224

222225
case 'I18nUnitTest.2.inc':

0 commit comments

Comments
 (0)