diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc index 3bebe1fdc2..d570897176 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc @@ -23,8 +23,8 @@ prefix_mysql_info(); // Ok. // MYSQL Extension. mysql_affected_rows(); -mysql_connect(); -mysql_close(); +Mysql_CONNECT(); +\MYSQL_close(); mysql_fetch_row(); mysql_info(); mysql_numrows(); @@ -99,6 +99,7 @@ Myfictional(); // OK. * Safeguard correct handling of all types of namespaced function calls. */ \mysql_connect(); -MyNamespace\mysql_connect(); -\MyNamespace\mysql_connect(); -namespace\mysql_connect(); // The sniff should start flagging this once it can resolve relative namespaces. +MyNamespace\mysqli_init(); +\MyNamespace\mysqlnd_qc_clear_cache(); +namespace\maxdb_close(); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\mysqli_fetch(); diff --git a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc index f96842c9e7..e9c010e8a8 100644 --- a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc +++ b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc @@ -5,13 +5,15 @@ date_default_timezone_set( 'Foo/Bar' ); // Bad. $date = new DateTime(); $date->setTimezone( new DateTimeZone( 'America/Toronto' ) ); // Yay! -$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); // Error. +$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), DaTe( __( 'g:i a' ), $now ) ); // Error. $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); // OK. /* * Safeguard correct handling of all types of namespaced function calls. */ \date_default_timezone_set( 'Foo/Bar' ); -MyNamespace\date_default_timezone_set( 'Foo/Bar' ); +\DATE_default_timezone_SET( 'Foo/Bar' ); +MyNamespace\date( 'Y-m-d' ); \MyNamespace\date_default_timezone_set( 'Foo/Bar' ); -namespace\date_default_timezone_set( 'Foo/Bar' ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\date( 'Y-m-d' ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\date_default_timezone_set( 'Foo/Bar' ); diff --git a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php index a2f29c2364..8a37da1c3a 100644 --- a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php @@ -30,6 +30,7 @@ public function getErrorList() { 3 => 1, 8 => 2, 14 => 1, + 15 => 1, ); } diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc index ada6fa9b4a..963e06888a 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc @@ -30,7 +30,7 @@ phpinfo(); // Ok - within excluded group. // Reset group exclusions. // phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] -trigger_error(); // Error. +\TRIGGER_ERROR(); // Error. phpinfo(); // Error. Wrapper_Class::var_dump(); // OK, not the native PHP function. @@ -40,6 +40,7 @@ $wrapper ->var_dump(); // OK, not the native PHP function. * Safeguard correct handling of all types of namespaced function calls. */ \var_dump( $value ); -MyNamespace\var_dump( $value ); -\MyNamespace\var_dump( $value ); -namespace\var_dump( $value ); // The sniff should start flagging this once it can resolve relative namespaces. +MyNamespace\phpinfo(); +\MyNamespace\print_r( $value ); +namespace\error_reporting(); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\debug_backtrace(); diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc index 84b7378b65..d79d88abd6 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc @@ -1,13 +1,13 @@ 1 ) ); // Bad. +exTRAct( array( 'a' => 1 ) ); // Bad. // Similarly named functions or methods however are fine. my_extract(); // Ok. @@ -12,6 +13,8 @@ $my_object->extract(); // Ok. * Safeguard correct handling of all types of namespaced function calls. */ \extract( array( 'a' => 1 ) ); +\EXTRACT( array( 'a' => 1 ) ); MyNamespace\extract( array( 'a' => 1 ) ); \MyNamespace\extract( array( 'a' => 1 ) ); namespace\extract( array( 'a' => 1 ) ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\extract( array( 'a' => 1 ) ); diff --git a/WordPress/Tests/PHP/DontExtractUnitTest.php b/WordPress/Tests/PHP/DontExtractUnitTest.php index f9a1df7494..52d6fdeb65 100644 --- a/WordPress/Tests/PHP/DontExtractUnitTest.php +++ b/WordPress/Tests/PHP/DontExtractUnitTest.php @@ -30,7 +30,9 @@ final class DontExtractUnitTest extends AbstractSniffUnitTest { public function getErrorList() { return array( 3 => 1, - 14 => 1, + 4 => 1, + 15 => 1, + 16 => 1, ); } diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc index b3bb11a71c..7d34f92fe9 100644 --- a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc @@ -13,9 +13,9 @@ $title = preg_split( 'cool', get_the_title() ); // Good. if ( ereg( '[A-Za-z]+', $title, $regs ) ) // Bad, ereg deprecated. Use preg_match instead. die( $regs ); -if ( eregi( '[a-z]+', $title, $regs ) ) {} // Bad, eregi deprecated. Use preg_match instead. +if ( \EREGI( '[a-z]+', $title, $regs ) ) {} // Bad, eregi deprecated. Use preg_match instead. -$title = ereg_replace( 'cool', 'not cool', get_the_title() ); // Bad, ereg_replace has been deprecated. Use preg_replace instead. +$title = ereg_REPLACE( 'cool', 'not cool', get_the_title() ); // Bad, ereg_replace has been deprecated. Use preg_replace instead. $title = eregi_replace( 'cool', 'not cool', get_the_title() ); // Bad, eregi_replace also deprecated. Use preg_replace instead. @@ -29,6 +29,7 @@ sql_regcase( 'Foo - bar.'); // Bad. Deprecated. * Safeguard correct handling of all types of namespaced function calls. */ \split( ':', $date ); -MyNamespace\split( ':', $date ); -\MyNamespace\split( ':', $date ); -namespace\split( ':', $date ); // The sniff should start flagging this once it can resolve relative namespaces. +MyNamespace\ereg( 'pattern', $string ); +\MyNamespace\ereg_replace( 'pattern', 'replacement', $string ); +namespace\spliti( ':', $date ); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\sql_regcase( 'string' ); diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc index 09465fa6c5..bada4800a3 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc @@ -3,11 +3,14 @@ add_action( 'widgets_init', create_function( '', // Error. 'return register_widget( "time_more_on_time_widget" );' ) ); +CREATE_function( '', '' ); // Error. /* * Safeguard correct handling of all types of namespaced function calls. */ \create_function('', 'return;'); +\Create_Function('', 'return;'); MyNamespace\create_function('', 'return;'); \MyNamespace\create_function('', 'return;'); namespace\create_function('', 'return;'); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\create_function('', 'return;'); diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php index 5cfa75ae51..a596706030 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php @@ -28,7 +28,9 @@ final class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest { public function getErrorList() { return array( 3 => 1, - 10 => 1, + 6 => 1, + 11 => 1, + 12 => 1, ); } diff --git a/WordPress/Tests/Security/SafeRedirectUnitTest.inc b/WordPress/Tests/Security/SafeRedirectUnitTest.inc index 3d8d19c02a..28d8a7b0a8 100644 --- a/WordPress/Tests/Security/SafeRedirectUnitTest.inc +++ b/WordPress/Tests/Security/SafeRedirectUnitTest.inc @@ -1,12 +1,15 @@ 1, - 9 => 1, + 3 => 1, + 4 => 1, + 10 => 1, + 11 => 1, ); } } diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.1.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.1.inc index 57a44658ef..291eefdc78 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.1.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.1.inc @@ -444,3 +444,4 @@ wp_add_editor_classic_theme_styles(); /* ============ WP 6.9 ============ */ seems_utf8(); wp_print_auto_sizes_contain_css_fix(); +wp_PRINT_auto_SIZES_contain_CSS_fix(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc index 6c2a7bb8e1..87418bf766 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc @@ -4,6 +4,8 @@ * Safeguard correct handling of all types of namespaced function calls. */ \the_category_ID(); -MyNamespace\the_category_ID(); -\MyNamespace\the_category_ID(); -namespace\the_category_ID(); // The sniff should start flagging this once it can resolve relative namespaces. +\THE_category_id(); +MyNamespace\permalink_link(); +\MyNamespace\get_postdata(); +namespace\create_user(); // The sniff should start flagging this once it can resolve relative namespaces. +namespace\Sub\user_can_edit_post(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index 6931a37a9b..2d75be123c 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -93,6 +93,7 @@ public function getErrorList( $testFile = '' ) { case 'DeprecatedFunctionsUnitTest.2.inc': return array( 6 => 1, + 7 => 1, ); default: @@ -111,7 +112,7 @@ public function getWarningList( $testFile = '' ) { switch ( $testFile ) { case 'DeprecatedFunctionsUnitTest.1.inc': $start_line = 430; - $end_line = 446; + $end_line = 447; $warnings = array_fill( $start_line, ( ( $end_line - $start_line ) + 1 ), 1 ); // Unset the lines related to version comments. diff --git a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.1.inc similarity index 83% rename from WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc rename to WordPress/Tests/WP/DiscouragedFunctionsUnitTest.1.inc index 66a33f4984..067a7907a5 100644 --- a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.1.inc @@ -1,7 +1,7 @@ query_posts(); // OK, not the global function. MyClass::wp_reset_query(); // OK, not the global function. $obj?->query_posts(); // OK, not the global function. -// Ensure the sniff doesn't act on namespaced calls. -MyNamespace\query_posts(); // OK, not the global function. -\MyNamespace\query_posts(); // OK, not the global function. -namespace\query_posts(); // OK, not the global function. -// ... but does act on fully qualified function calls. -\query_posts(); // Warning. + + + + + + // Ensure the sniff doesn't act on functions not listed in the target functions array. query_post(); // OK, not one of the target functions. @@ -64,6 +64,11 @@ wp_reset_query(); // OK, excluded group. // Safeguard that a function used as a PHP 8.1+ first class callable is also flagged. call_user_func( query_posts(...), $param ); // Warning. -// Live coding/parse error. -// This has to be the last test in the file!!! -\query_posts +/* + * Safeguard correct handling of all types of namespaced function calls. + */ +\query_POSTS(); // Warning. +MyNamespace\wp_reset_query(); // OK, not the global function. +\MyNamespace\query_posts(); // OK, not the global function. +namespace\wp_reset_query(); // OK, not the global function. +namespace\Sub\query_posts(); // OK, not the global function. diff --git a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.2.inc b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.2.inc new file mode 100644 index 0000000000..0476780120 --- /dev/null +++ b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.2.inc @@ -0,0 +1,8 @@ + Key is the line number, value is the number of expected warnings. */ - public function getWarningList() { - return array( - 3 => 1, - 4 => 1, - 20 => 1, - 33 => 1, - 34 => 1, - 53 => 1, - 62 => 1, - 65 => 1, - ); + public function getWarningList( $testFile = '' ) { + switch ( $testFile ) { + case 'DiscouragedFunctionsUnitTest.1.inc': + return array( + 3 => 1, + 4 => 1, + 33 => 1, + 34 => 1, + 53 => 1, + 62 => 1, + 65 => 1, + 70 => 1, + ); + + default: + return array(); + } } }