diff --git a/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.inc b/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.inc index c451ccc91b..d81c7b3eb9 100644 --- a/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.inc +++ b/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.inc @@ -4,8 +4,17 @@ esc_html( 'text' ); esc_html( $var ); esc_html( 'text', 'domain' ); // Warning. -esc_html( $foo, $bar ); // Warning. -esc_attr( +\ESC_HTML( $foo, $bar ); // Warning. +esc_ATTR( 'text', // Some comment. MY_DOMAIN // More comment. ); // Warning. + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\esc_attr( 'text', 'domain' ); +MyNamespace\esc_html( 'text', 'domain' ); +\MyNamespace\esc_attr( 'text', 'domain' ); +namespace\esc_html( 'text', 'domain' ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\esc_attr( 'text', 'domain' ); diff --git a/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.php b/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.php index 4218e90dc9..eee562f2d6 100644 --- a/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/EscapedNotTranslatedUnitTest.php @@ -36,9 +36,10 @@ public function getErrorList() { */ public function getWarningList() { return array( - 6 => 1, - 7 => 1, - 8 => 1, + 6 => 1, + 7 => 1, + 8 => 1, + 16 => 1, ); } } diff --git a/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc index 07634e769a..fb3beead42 100644 --- a/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc +++ b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc @@ -20,7 +20,7 @@ current_time( // Error. ); current_time( 'timestamp', $gmt ); // Warning. -current_time( 'timestamp', false ); // Warning. +\Current_Time( 'timestamp', false ); // Warning. current_time( 'U', 0 ); // Warning. current_time( 'U' ); // Warning. @@ -30,3 +30,12 @@ current_time( gmt: true, type: 'mysql', ); // OK. current_time( type: 'Y-m-d' ); // OK. current_time( gmt: true, type: 'timestamp' ); // Error. current_time( gmt: 0, type : 'U' ); // Warning. + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\current_time( 'timestamp', true ); +MyNamespace\current_time( 'timestamp', true ); +\MyNamespace\current_time( 'timestamp', true ); +namespace\current_time( 'timestamp', true ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\current_time( 'timestamp', true ); diff --git a/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc.fixed b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc.fixed index 5b2fa7e28a..be53fb3148 100644 --- a/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc.fixed +++ b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.inc.fixed @@ -17,7 +17,7 @@ current_time( // Error. ); current_time( 'timestamp', $gmt ); // Warning. -current_time( 'timestamp', false ); // Warning. +\Current_Time( 'timestamp', false ); // Warning. current_time( 'U', 0 ); // Warning. current_time( 'U' ); // Warning. @@ -27,3 +27,12 @@ current_time( gmt: true, type: 'mysql', ); // OK. current_time( type: 'Y-m-d' ); // OK. time(); // Error. current_time( gmt: 0, type : 'U' ); // Warning. + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\time(); +MyNamespace\current_time( 'timestamp', true ); +\MyNamespace\current_time( 'timestamp', true ); +namespace\current_time( 'timestamp', true ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\current_time( 'timestamp', true ); diff --git a/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.php b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.php index c667af8234..4525e58d79 100644 --- a/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.php +++ b/WordPress/Tests/DateTime/CurrentTimeTimestampUnitTest.php @@ -31,6 +31,7 @@ public function getErrorList() { 11 => 1, 17 => 1, 31 => 1, + 37 => 1, ); } diff --git a/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.1.inc b/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.1.inc index 5c0ed5729a..bf6450c790 100644 --- a/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.1.inc @@ -5,7 +5,7 @@ register_post_type( 'my_own_post_type', array() ); // OK. register_post_type( 'my-own-post-type-too-long', array() ); // Bad. register_post_type( 'author', array() ); // Bad. Reserved slug name. register_post_type( 'My-Own-Post-Type', array() ); // Bad. Invalid chars: uppercase. -register_post_type( 'my/own/post/type', array() ); // Bad. Invalid chars: "/". +register_POST_TYPE( 'my/own/post/type', array() ); // Bad. Invalid chars: "/". register_post_type( <<get_post_type_id() ); // Non string literal. Warning register_post_type( null, array() ); // Non string literal. Warning with severity: 3 register_post_type( 1000, array() ); // Non string literal. Warning with severity: 3 -register_post_type( 'wp_', array() ); // Bad. Reserved prefix. +\REGISTER_post_TYPE( 'wp_', array() ); // Bad. Reserved prefix. register_post_type( 'wp_post_type', array() ); // Bad. Reserved prefix. register_post_type( '', array() ); // Bad. Empty post type slug. @@ -68,3 +68,12 @@ register_post_type( // Post type name. $name,// Non string literal. Warning with severity: 3 ); + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\register_post_type( 'my-own-post-type-too-long', array() ); // Bad. +MyNamespace\register_post_type( 'my-own-post-type-too-long', array() ); // Ok. +\MyNamespace\register_post_type( 'my-own-post-type-too-long', array() ); // Ok. +namespace\register_post_type( 'my-own-post-type-too-long', array() ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\register_post_type( 'my-own-post-type-too-long', array() ); // Ok. diff --git a/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.php b/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.php index 821b73ef24..cb2d41c998 100644 --- a/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidPostTypeSlugUnitTest.php @@ -57,6 +57,7 @@ public function getErrorList( $testFile = '' ) { 52 => 1, 62 => 1, 64 => 1, + 75 => 1, ); case 'ValidPostTypeSlugUnitTest.2.inc': diff --git a/WordPress/Tests/PHP/IniSetUnitTest.inc b/WordPress/Tests/PHP/IniSetUnitTest.inc index c5ef7295d1..96a310cb19 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.inc +++ b/WordPress/Tests/PHP/IniSetUnitTest.inc @@ -14,8 +14,8 @@ ini_set('short_open_tag', 'On'); // Ok. ini_set('short_open_tag', 'on'); // Ok. ini_set('bcmath.scale', 0); // Error. -ini_set( 'bcmath.scale' ,0 ); // Error. -ini_set('display_errors', 0); // Error. +\ini_SET( 'bcmath.scale' ,0 ); // Error. +INI_set('display_errors', 0); // Error. ini_set('error_reporting', 0); // Error. ini_set('filter.default', 'full_special_chars'); // Error. ini_set('filter.default_flags', 0); // Error. @@ -58,3 +58,12 @@ ini_set( // Set the number of decimals. 0 ); // Error. + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\ini_set( 'bcmath.scale', 0 ); // Error. +MyNamespace\ini_alter( 'bcmath.scale', 0 ); // Ok. +\MyNamespace\ini_set( 'bcmath.scale', 0 ); // Ok. +namespace\ini_alter( 'bcmath.scale', 0 ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\ini_set( 'bcmath.scale', 0 ); // Ok. diff --git a/WordPress/Tests/PHP/IniSetUnitTest.php b/WordPress/Tests/PHP/IniSetUnitTest.php index fede4955b2..1dd5ca4ab7 100644 --- a/WordPress/Tests/PHP/IniSetUnitTest.php +++ b/WordPress/Tests/PHP/IniSetUnitTest.php @@ -49,6 +49,7 @@ public function getErrorList() { 42 => 1, 51 => 1, 55 => 1, + 65 => 1, ); } diff --git a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.inc b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.inc index 1942b2b07f..06611613af 100644 --- a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.inc +++ b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.inc @@ -4,12 +4,21 @@ preg_quote($keywords, '/'); // OK. preg_quote( $keywords, '`' ); // OK. preg_quote($keywords); // Warning. -$textbody = preg_replace ( "/" . preg_quote($word) . "/", // Warning +$textbody = preg_replace ( "/" . \PREG_quote($word) . "/", // Warning "" . $word . "", $textbody ); // Safeguard support for PHP 8.0+ named parameters. preg_quote(delimiter: '#', str: $keywords); // OK. preg_quote(str: $keywords); // Warning. -preg_quote(str: $keywords, delimitter: '#'); // Warning (typo in param name). +Preg_QUOTE(str: $keywords, delimitter: '#'); // Warning (typo in param name). preg_quote(delimiter: '#'); // OK. Invalid function call, but that's not the concern of this sniff. + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\preg_quote($keywords); // Warning. +MyNamespace\preg_quote($keywords); // Ok. +\MyNamespace\preg_quote($keywords); // Ok. +namespace\preg_quote($keywords); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\preg_quote($keywords); // Ok. diff --git a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php index 63d4e0eb9f..4c6a254fae 100644 --- a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php +++ b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php @@ -40,6 +40,7 @@ public function getWarningList() { 7 => 1, 13 => 1, 14 => 1, + 20 => 1, ); } } diff --git a/WordPress/Tests/PHP/StrictInArrayUnitTest.inc b/WordPress/Tests/PHP/StrictInArrayUnitTest.inc index fd1e194225..15ce708653 100644 --- a/WordPress/Tests/PHP/StrictInArrayUnitTest.inc +++ b/WordPress/Tests/PHP/StrictInArrayUnitTest.inc @@ -3,7 +3,7 @@ in_array( 1, array( '1', 1, true ), true ); // Ok. in_array( 1, array( '1', 1, true ) ); // Warning. -in_array( 1, array( '1', 1, true ), false ); // Warning. +\In_Array( 1, array( '1', 1, true ), false ); // Warning. IN_ARRAY( 1, array( '1', 1, true ), false ); // Warning. Foo::in_array( 1, array( '1', 1, true ) ); // Ok. @@ -55,3 +55,12 @@ array_search( $haystack, true // Use strict typing. ); // Ok. + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\in_array( 1, array( '1', 2 ) ); // Bad. +MyNamespace\array_search( 1, array( '1', 2 ) ); // Ok. +\MyNamespace\array_keys( array( '1', 2 ) ); // Ok. +namespace\in_array( 1, array( '1', 2 ) ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\array_search( 1, array( '1', 2 ) ); // Ok. diff --git a/WordPress/Tests/PHP/StrictInArrayUnitTest.php b/WordPress/Tests/PHP/StrictInArrayUnitTest.php index 41aa9d37c4..d7104d7d9b 100644 --- a/WordPress/Tests/PHP/StrictInArrayUnitTest.php +++ b/WordPress/Tests/PHP/StrictInArrayUnitTest.php @@ -52,6 +52,7 @@ public function getWarningList() { 44 => 1, 48 => 1, 49 => 1, + 62 => 1, ); } } diff --git a/WordPress/Tests/Security/PluginMenuSlugUnitTest.inc b/WordPress/Tests/Security/PluginMenuSlugUnitTest.inc index 2c77ee621e..3f4e34f948 100644 --- a/WordPress/Tests/Security/PluginMenuSlugUnitTest.inc +++ b/WordPress/Tests/Security/PluginMenuSlugUnitTest.inc @@ -2,11 +2,11 @@ add_menu_page( $page_title, $menu_title, $capability, __FILE__, $function, $icon_url, $position ); // Bad. -add_dashboard_page( $page_title, $menu_title, $capability, __file__, $function); // Bad. +\ADD_DASHBOARD_PAGE( $page_title, $menu_title, $capability, __file__, $function); // Bad. add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, 'awesome-submenu-page', $function ); // Ok. -add_submenu_page( __FILE__ . 'parent', $page_title, $menu_title, $capability, __FILE__, $function ); // Bad x 2. +Add_Submenu_Page( __FILE__ . 'parent', $page_title, $menu_title, $capability, __FILE__, $function ); // Bad x 2. // These are all ok: not calling the WP core function. $my_class->add_dashboard_page( $page_title, $menu_title, $capability, __FILE__, $function); // Ok. @@ -20,3 +20,12 @@ add_submenu_page( parent_slug: __FILE__, // Bad. capability: $capability, ); + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\add_menu_page( $page_title, $menu_title, $capability, __FILE__, $function, $icon_url, $position ); // Bad. +MyNamespace\add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, __FILE__, $function ); // Ok. +\MyNamespace\add_dashboard_page( $page_title, $menu_title, $capability, __FILE__, $function ); // Ok. +namespace\add_menu_page( $page_title, $menu_title, $capability, __FILE__, $function, $icon_url, $position ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, __FILE__, $function ); // Ok. diff --git a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php index 6741d048a1..cee8c0e1b6 100644 --- a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php +++ b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php @@ -42,6 +42,7 @@ public function getWarningList() { 5 => 1, 9 => 2, 20 => 1, + 27 => 1, ); } } diff --git a/WordPress/Tests/WP/CapabilitiesUnitTest.1.inc b/WordPress/Tests/WP/CapabilitiesUnitTest.1.inc index ab1fdb9c41..3cd45f9c9c 100644 --- a/WordPress/Tests/WP/CapabilitiesUnitTest.1.inc +++ b/WordPress/Tests/WP/CapabilitiesUnitTest.1.inc @@ -63,8 +63,8 @@ add_menu_page( $pagetitle, 'menu_title', 'foo_bar', 'handle', 'function', 'icon_ * Roles found instead of capabilities. */ add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Error. -add_media_page( 'page_title', 'menu_title', 'editor', 'menu_slug', 'function' ); // Error. -add_pages_page( 'page_title', 'menu_title', 'author', 'menu_slug', 'function' ); // Error. +\aDd_MeDiA_pAgE( 'page_title', 'menu_title', 'editor', 'menu_slug', 'function' ); // Error. +ADD_PAGES_PAGE( 'page_title', 'menu_title', 'author', 'menu_slug', 'function' ); // Error. add_comments_page( 'page_title', 'menu_title', 'contributor', 'menu_slug', 'function' ); // Error. add_theme_page( 'page_title', $menu_title, 'subscriber', 'menu_slug', 'function' ); // Error. add_plugins_page( 'page_title', 'menu_title', 'super_admin', 'menu_slug', 'function' ); // Error. @@ -111,8 +111,12 @@ add_menu_page( $p, $t, /* deliberately empty */, $slug, ); add_menu_page( [] ); // Should bow out because the parameter is not found. $obj->current_user_can( 'foo_bar' ); // Ok. We're not checking for method calls. -My\NamespaceS\add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Ok. We're not checking namespaced functions. -// Parse error, should be handled correctly by bowing out. -// This must be the last test in the file! -add_posts_page( 'page_title', +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Bad. +My\NamespaceS\current_user_can( 'administrator' ); // Ok. +\MyNamespace\add_comments_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Ok. +namespace\author_can( $post, 'administrator' ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Ok. diff --git a/WordPress/Tests/WP/CapabilitiesUnitTest.5.inc b/WordPress/Tests/WP/CapabilitiesUnitTest.5.inc new file mode 100644 index 0000000000..d5f8d0d393 --- /dev/null +++ b/WordPress/Tests/WP/CapabilitiesUnitTest.5.inc @@ -0,0 +1,8 @@ + 1, 85 => 1, 106 => 1, + 118 => 1, ); case 'CapabilitiesUnitTest.3.inc': diff --git a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.inc b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.1.inc similarity index 83% rename from WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.inc rename to WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.1.inc index c2f75c8747..18a26a2b93 100644 --- a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.1.inc @@ -3,8 +3,8 @@ // All will give an ERROR. get_bloginfo( 'home' ); -get_bloginfo( 'siteurl' ); -get_bloginfo( "text_direction" ); +\GeT_bLoGiNfO( 'siteurl' ); +Get_Bloginfo( "text_direction" ); echo bloginfo( 'home' ); echo bloginfo( "siteurl" ); echo bloginfo( 'text_direction' ); @@ -55,5 +55,11 @@ wp_get_typography_font_size_value( $preset, array() ); // OK. wp_get_typography_font_size_value( $preset, true ); // Error. wp_get_typography_font_size_value( $preset, false ); // Error. -// Live coding/parse error. -get_bloginfo( show: /*to do*/, ); +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\get_bloginfo( 'home' ); // Bad. +MyNamespace\register_setting( 'privacy' ); // Ok. +\MyNamespace\unregister_setting( 'misc' ); // Ok. +namespace\get_option('blacklist_keys'); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\add_option('comment_whitelist', $value); // Ok. diff --git a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.2.inc b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.2.inc new file mode 100644 index 0000000000..b5923d40e4 --- /dev/null +++ b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.2.inc @@ -0,0 +1,8 @@ + Key is the line number, value is the number of expected errors. */ - public function getErrorList() { - return array( - 5 => 1, - 6 => 1, - 7 => 1, - 8 => 1, - 9 => 1, - 10 => 1, - 11 => 1, - 12 => 1, - 13 => 1, - 14 => 1, - 15 => 1, - 16 => 1, - 17 => 1, - 18 => 1, - 35 => 1, - 40 => 1, - 43 => 1, - 44 => 1, - 45 => 1, - 46 => 1, - 47 => 1, - 48 => 1, - 49 => 1, - 50 => 1, - 51 => 1, - ); + public function getErrorList( $testFile = '' ) { + switch ( $testFile ) { + case 'DeprecatedParameterValuesUnitTest.1.inc': + return array( + 5 => 1, + 6 => 1, + 7 => 1, + 8 => 1, + 9 => 1, + 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + 16 => 1, + 17 => 1, + 18 => 1, + 35 => 1, + 40 => 1, + 43 => 1, + 44 => 1, + 45 => 1, + 46 => 1, + 47 => 1, + 48 => 1, + 49 => 1, + 50 => 1, + 51 => 1, + 61 => 1, + ); + + default: + return array(); + } } /** * Returns the lines where warnings should occur. * + * @param string $testFile The name of the file being tested. + * * @return array Key is the line number, value is the number of expected warnings. */ - public function getWarningList() { - return array( - 55 => 1, - 56 => 1, - ); + public function getWarningList( $testFile = '' ) { + switch ( $testFile ) { + case 'DeprecatedParameterValuesUnitTest.1.inc': + return array( + 55 => 1, + 56 => 1, + ); + + default: + return array(); + } } } diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc index 1fc0c27b04..9922f8e1e6 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc @@ -43,8 +43,8 @@ _future_post_hook( 10, $post ); _load_remote_block_patterns( $value ); _wp_post_revision_fields( $foo, 'deprecated' ); add_option( '', '', [] ); -add_option( '', '', 1.23 ); -add_option( '', '', 10 ); +\Add_Option( '', '', 1.23 ); +ADD_OPTION( '', '', 10 ); add_option( '', '', false ); add_option( '', '', 'deprecated' ); comments_link( 'deprecated', 'deprecated' ); @@ -99,3 +99,12 @@ global_terms( $foo, 'deprecated' ); // All will give an WARNING as they have been deprecated after WP 6.5. inject_ignored_hooked_blocks_metadata_attributes('', 'deprecated'); wp_render_elements_support_styles('deprecated'); + +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\add_option( '', '', [] ); // Bad. +MyNamespace\get_blog_list( $foo, $bar, 'deprecated' ); // Ok. +\MyNamespace\get_wp_title_rss( 'deprecated' ); // Ok. +namespace\the_author( 'deprecated', 'deprecated' ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\wp_title_rss( 'deprecated' ); // Ok. diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php index 3d516ec983..2f8b60510e 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php @@ -42,6 +42,9 @@ public function getErrorList() { $errors[50] = 2; $errors[76] = 2; + // Fully qualified function call. + $errors[106] = 1; + return $errors; } diff --git a/WordPress/Tests/WP/GetMetaSingleUnitTest.inc b/WordPress/Tests/WP/GetMetaSingleUnitTest.inc index 54ea2fecc0..33aed6468d 100644 --- a/WordPress/Tests/WP/GetMetaSingleUnitTest.inc +++ b/WordPress/Tests/WP/GetMetaSingleUnitTest.inc @@ -31,7 +31,7 @@ $incorrect_but_ok = get_metadata( 'post' ); * These should all be flagged with a warning. */ $warning = \get_post_meta( $post_id, $meta_key ); -implode(', ', get_post_meta( $post_id, $meta_key )); +implode(', ', \GET_POST_META( $post_id, $meta_key )); if (get_post_meta( $post_id, key: $meta_key )) {} $warning = get_post_meta( $post_id, key: $meta_key, sinngle: true ); // Typo in parameter name. echo get_comment_meta( $comment_id, $meta_key ); @@ -46,3 +46,11 @@ $warning = get_metadata( ); $warning = get_metadata_raw( 'post', $post_id, $meta_key ); $warning = get_metadata_default( 'post', $post_id, $meta_key ); + +/* + * Safeguard correct handling of fully qualified and relative namespaced function calls (fully qualified global function + * call and partially qualified namespaced function call are already handled above). + */ +\MyNamespace\get_user_meta( $user_id, $meta_key ); +namespace\get_metadata( 'post', $post_id, $meta_key ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\get_comment_meta( $comment_id, $meta_key ); diff --git a/WordPress/Tests/WP/I18nUnitTest.1.inc b/WordPress/Tests/WP/I18nUnitTest.1.inc index 6256e6d84a..3abf8ec3ba 100644 --- a/WordPress/Tests/WP/I18nUnitTest.1.inc +++ b/WordPress/Tests/WP/I18nUnitTest.1.inc @@ -47,7 +47,7 @@ _n( 'I have %d cat.', 'I have %d cats.', $number, 'my-slug' ); // OK. _n( 'I have %d cat.', 'I have %d cats.', $number, "illegal $string" ); // Bad. _n( 'I have %d cat.', 'I have %d cats.', $number, SOMETHING ); // Bad. -_n_noop( 'I have %d cat.', 'I have %d cats.' ); // Bad, no text domain. +_N_NOOP( 'I have %d cat.', 'I have %d cats.' ); // Bad, no text domain. _n_noop( 'I have %d cat.', 'I have %d cats.', 'my-slug' ); // OK. _n_noop( 'I have %d cat.', 'I have %d cats.', "illegal $string" ); // Bad. _n_noop( 'I have %d cat.', 'I have %d cats.', SOMETHING ); // Bad. @@ -75,7 +75,7 @@ __( 'foo', 'my-slug', 'too-many-args' ); // Bad. _x( 'string', 'context', 'my-slug', 'too-many-args' ); // Bad. _n( 'I have %d cat.', 'I have %d cats.', $number, 'my-slug', 'too-many-args' ); // Bad. _n_noop( 'I have %d cat.', 'I have %d cats.', 'my-slug', 'too-many-args' ); // Bad. -_nx_noop( 'I have %d cat.', 'I have %d cats.', 'Not really.', 'my-slug', 'too-many-args' ); // Bad. +\_Nx_Noop( 'I have %d cat.', 'I have %d cats.', 'Not really.', 'my-slug', 'too-many-args' ); // Bad. // Make sure that multi-line string literals are accepted. _nx( 'I have @@ -317,4 +317,15 @@ esc_html_e( 'foo', '' ); // Bad: text-domain can not be empty. // PHP 8.0+: safeguard handling of newly introduced placeholders. __( 'There are %1$h monkeys in the %H', 'my-slug' ); // Bad: multiple arguments should be numbered. +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\_( 'foo', 'my-slug' ); // Bad. +\translate( 'foo', 'my-slug' ); // Bad. +\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Bad. +MyNamespace\__( 'foo', 'my-slug' ); // Ok. +\MyNamespace\_e( 'foo', 'my-slug' ); // Ok. +namespace\esc_html_e( 'foo', '' ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\translate( 'foo', 'my-slug' ); // Ok. + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment diff --git a/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed b/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed index b23e9b6192..ae6358abbf 100644 --- a/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed +++ b/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed @@ -47,7 +47,7 @@ _n( 'I have %d cat.', 'I have %d cats.', $number, 'my-slug' ); // OK. _n( 'I have %d cat.', 'I have %d cats.', $number, "illegal $string" ); // Bad. _n( 'I have %d cat.', 'I have %d cats.', $number, SOMETHING ); // Bad. -_n_noop( 'I have %d cat.', 'I have %d cats.' ); // Bad, no text domain. +_N_NOOP( 'I have %d cat.', 'I have %d cats.' ); // Bad, no text domain. _n_noop( 'I have %d cat.', 'I have %d cats.', 'my-slug' ); // OK. _n_noop( 'I have %d cat.', 'I have %d cats.', "illegal $string" ); // Bad. _n_noop( 'I have %d cat.', 'I have %d cats.', SOMETHING ); // Bad. @@ -75,7 +75,7 @@ __( 'foo', 'my-slug', 'too-many-args' ); // Bad. _x( 'string', 'context', 'my-slug', 'too-many-args' ); // Bad. _n( 'I have %d cat.', 'I have %d cats.', $number, 'my-slug', 'too-many-args' ); // Bad. _n_noop( 'I have %d cat.', 'I have %d cats.', 'my-slug', 'too-many-args' ); // Bad. -_nx_noop( 'I have %d cat.', 'I have %d cats.', 'Not really.', 'my-slug', 'too-many-args' ); // Bad. +\_Nx_Noop( 'I have %d cat.', 'I have %d cats.', 'Not really.', 'my-slug', 'too-many-args' ); // Bad. // Make sure that multi-line string literals are accepted. _nx( 'I have @@ -317,4 +317,15 @@ esc_html_e( 'foo', '' ); // Bad: text-domain can not be empty. // PHP 8.0+: safeguard handling of newly introduced placeholders. __( 'There are %1$h monkeys in the %H', 'my-slug' ); // Bad: multiple arguments should be numbered. +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\_( 'foo', 'my-slug' ); // Bad. +\translate( 'foo', 'my-slug' ); // Bad. +\translate_with_gettext_context( 'foo', 'bar', 'my-slug' ); // Bad. +MyNamespace\__( 'foo', 'my-slug' ); // Ok. +\MyNamespace\_e( 'foo', 'my-slug' ); // Ok. +namespace\esc_html_e( 'foo', '' ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\translate( 'foo', 'my-slug' ); // Ok. + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment diff --git a/WordPress/Tests/WP/I18nUnitTest.php b/WordPress/Tests/WP/I18nUnitTest.php index 3834eb189f..20e7accaab 100644 --- a/WordPress/Tests/WP/I18nUnitTest.php +++ b/WordPress/Tests/WP/I18nUnitTest.php @@ -148,6 +148,7 @@ public function getErrorList( $testFile = '' ) { 311 => 1, 315 => 1, 318 => 1, + 323 => 1, ); case 'I18nUnitTest.2.inc': @@ -217,6 +218,8 @@ public function getWarningList( $testFile = '' ) { 300 => 1, 301 => 1, 302 => 1, + 324 => 1, + 325 => 1, ); case 'I18nUnitTest.2.inc':