From c690f60df4fea80e8a484df451e7f36d36b7cd6b Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 20 Apr 2022 05:59:45 +0000 Subject: [PATCH] Build, Test Tools: Test PHP and WP compatibility functions. Introduce tests for `is_php_version_compatible()` and `is_wp_version_compatible()`. Props pbearne, hellofromTonya, mikeschroder, peterwilsoncc, toro_unit. Fixes #54257. git-svn-id: https://develop.svn.wordpress.org/trunk@53227 602fd350-edb4-49c9-b593-d223f7449a82 --- .../functions/isPhpVersionCompatible.php | 53 +++++++++++++++++++ .../tests/functions/isWpVersionCompatible.php | 53 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tests/phpunit/tests/functions/isPhpVersionCompatible.php create mode 100644 tests/phpunit/tests/functions/isWpVersionCompatible.php diff --git a/tests/phpunit/tests/functions/isPhpVersionCompatible.php b/tests/phpunit/tests/functions/isPhpVersionCompatible.php new file mode 100644 index 0000000000..abbd03e08d --- /dev/null +++ b/tests/phpunit/tests/functions/isPhpVersionCompatible.php @@ -0,0 +1,53 @@ +assertSame( is_php_version_compatible( $test_value ), $expected ); + } + + /** + * Provides test scenarios for test_php_version_compatible. + * + * @return array + */ + function data_is_php_version_compatible() { + $php_version = phpversion(); + + $more = explode( '.', $php_version ); + $less = $more; + + -- $less[ count( $less ) - 1 ]; + ++ $more[ count( $less ) - 1 ]; + + return array( + 'greater' => array( + 'test_value' => implode( '.', $more ), + 'expected' => false, + ), + 'same' => array( + 'test_value' => $php_version, + 'expected' => true, + ), + 'less' => array( + 'test_value' => implode( '.', $less ), + 'expected' => true, + ), + ); + } +} diff --git a/tests/phpunit/tests/functions/isWpVersionCompatible.php b/tests/phpunit/tests/functions/isWpVersionCompatible.php new file mode 100644 index 0000000000..dfec2a37cb --- /dev/null +++ b/tests/phpunit/tests/functions/isWpVersionCompatible.php @@ -0,0 +1,53 @@ +assertSame( is_wp_version_compatible( $test_value ), $expected ); + } + + /** + * Provides test scenarios test_is_wp_version_compatible. + * + * @return array + */ + function data_is_wp_version_compatible() { + $wp_version = get_bloginfo( 'version' ); + + $more = explode( '.', $wp_version ); + $less = $more; + + -- $less[0]; + ++ $more[0]; + + return array( + 'greater' => array( + 'test_value' => implode( '.', $more ), + 'expected' => false, + ), + 'same' => array( + 'test_value' => $wp_version, + 'expected' => true, + ), + 'less' => array( + 'test_value' => implode( '.', $less ), + 'expected' => true, + ), + ); + } +}