From 2648a5f984b8abf06872151898e3a61d3458a628 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Mon, 8 Nov 2021 13:29:25 +0000 Subject: [PATCH] General: Add phpunit tests for `wp_is_numeric_array()`. Adds new test class `Tests_Functions_WpIsNumericArray` for `wp_is_numeric_array()`. Props pbearne, hareesh-pillai, hellofromTonya. Fixes #53971. git-svn-id: https://develop.svn.wordpress.org/trunk@52037 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/functions/wpIsNumericArray.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpIsNumericArray.php diff --git a/tests/phpunit/tests/functions/wpIsNumericArray.php b/tests/phpunit/tests/functions/wpIsNumericArray.php new file mode 100644 index 0000000000..b825138678 --- /dev/null +++ b/tests/phpunit/tests/functions/wpIsNumericArray.php @@ -0,0 +1,71 @@ +assertSame( $expected, wp_is_numeric_array( $input ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_wp_is_numeric_array() { + return array( + 'no index' => array( + 'test_array' => array( 'www', 'eee' ), + 'expected' => true, + ), + 'text index' => array( + 'test_array' => array( 'www' => 'eee' ), + 'expected' => false, + ), + 'numeric index' => array( + 'test_array' => array( 99 => 'eee' ), + 'expected' => true, + ), + '- numeric index' => array( + 'test_array' => array( -11 => 'eee' ), + 'expected' => true, + ), + 'numeric string index' => array( + 'test_array' => array( '11' => 'eee' ), + 'expected' => true, + ), + 'nested number index' => array( + 'test_array' => array( + 'next' => array( + 11 => 'vvv', + ), + ), + 'expected' => false, + ), + 'nested string index' => array( + 'test_array' => array( + '11' => array( + 'eee' => 'vvv', + ), + ), + 'expected' => true, + ), + 'not an array' => array( + 'test_array' => null, + 'expected' => false, + ), + ); + } +}