Skip to content

Commit 064da4c

Browse files
committed
WP/AlternativeFunctions: add tests for namespaced names
1 parent 5c819af commit 064da4c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,27 @@ file_get_contents(
147147
// Not using plugin_dir_path() for reasons.
148148
$url
149149
); // Warning.
150+
151+
/*
152+
* Safeguard correct handling of all types of namespaced function calls
153+
*/
154+
\curl_init();
155+
MyNamespace\curl_init();
156+
\MyNamespace\curl_init();
157+
namespace\curl_init(); // The sniff should start flagging this once it can resolve relative namespaces.
158+
159+
/*
160+
* Safeguard correct handling of namespaced parameters passed to file_get_contents().
161+
*
162+
* Note: the sniff should flag the examples using a fully qualified namespaced name and partially
163+
* qualified name, but currently does not. This will be addressed via
164+
* https://github.com/WordPress/WordPress-Coding-Standards/issues/2603.
165+
*/
166+
file_get_contents(\wp_upload_dir()['path'] . 'subdir/file.inc');
167+
file_get_contents(MyNamespace\wp_upload_dir()['path'] . 'subdir/file.inc');
168+
file_get_contents(\MyNamespace\wp_upload_dir()['path'] . 'subdir/file.inc');
169+
file_get_contents(namespace\wp_upload_dir()['path'] . 'subdir/file.inc');
170+
file_get_contents(\ABSPATH . 'wp-admin/css/some-file.css');
171+
file_get_contents(MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
172+
file_get_contents(\MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
173+
file_get_contents(namespace\ABSPATH . 'wp-admin/css/some-file.css');

WordPress/Tests/WP/AlternativeFunctionsUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function getWarningList() {
8989
131 => 1,
9090
142 => 1,
9191
146 => 1,
92+
154 => 1,
9293
);
9394
}
9495
}

0 commit comments

Comments
 (0)