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
This commit is contained in:
Peter Wilson 2022-04-20 05:59:45 +00:00
parent 059cab0e71
commit c690f60df4
2 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php
/**
* Tests the is_php_version_compatible function.
*
* @group functions.php
* @covers ::is_php_version_compatible
*/
class Tests_Functions_isPhpVersionCompatible extends WP_UnitTestCase {
/**
* Tests is_php_version_compatible().
*
* @dataProvider data_is_php_version_compatible
*
* @param mixed $test_value
* @param bool $expected
*
* @ticket 54257
*/
public function test_is_php_version_compatible( $test_value, $expected ) {
$this->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,
),
);
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Tests the is_php_version_compatible function.
*
* @group functions.php
* @covers ::is_wp_version_compatible
*/
class Tests_Functions_isWpVersionCompatible extends WP_UnitTestCase {
/**
* Test is_wp_version_compatible().
*
* @dataProvider data_is_wp_version_compatible
*
* @param mixed $test_value
* @param bool $expected
*
* @ticket 54257
*/
public function test_is_wp_version_compatible( $test_value, $expected ) {
$this->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,
),
);
}
}