Changeset 53237
- Timestamp:
- 04/21/2022 01:00:24 AM (2 years ago)
- Location:
- trunk/tests/phpunit/tests/functions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions/isPhpVersionCompatible.php
r53227 r53237 2 2 3 3 /** 4 * Tests the is_php_version_compatible function.4 * Tests the is_php_version_compatible() function. 5 5 * 6 6 * @group functions.php 7 7 * @covers ::is_php_version_compatible 8 8 */ 9 class Tests_Functions_ isPhpVersionCompatible extends WP_UnitTestCase {9 class Tests_Functions_IsPhpVersionCompatible extends WP_UnitTestCase { 10 10 /** 11 11 * Tests is_php_version_compatible(). … … 13 13 * @dataProvider data_is_php_version_compatible 14 14 * 15 * @param mixed $test_value 16 * @param bool $expected 15 * @ticket 54257 17 16 * 18 * @ticket 54257 17 * @param mixed $required The minimum required PHP version. 18 * @param bool $expected The expected result. 19 19 */ 20 public function test_is_php_version_compatible( $ test_value, $expected ) {21 $this->assertSame( is_php_version_compatible( $test_value ), $expected);20 public function test_is_php_version_compatible( $required, $expected ) { 21 $this->assertSame( $expected, is_php_version_compatible( $required ) ); 22 22 } 23 23 24 24 /** 25 * Provides test scenarios for test_php_version_compatible.25 * Data provider. 26 26 * 27 27 * @return array 28 28 */ 29 function data_is_php_version_compatible() {29 public function data_is_php_version_compatible() { 30 30 $php_version = phpversion(); 31 31 32 $more = explode( '.', $php_version ); 33 $less = $more; 32 $version_parts = explode( '.', $php_version ); 33 $lower_version = $version_parts; 34 $higher_version = $version_parts; 34 35 35 -- $less[ count( $less ) - 1 ]; 36 ++ $more[ count( $less ) - 1 ]; 36 // Adjust the major version numbers. 37 --$lower_version[0]; 38 ++$higher_version[0]; 39 40 $lower_version = implode( '.', $lower_version ); 41 $higher_version = implode( '.', $higher_version ); 37 42 38 43 return array( 39 'greater' => array( 40 'test_value' => implode( '.', $more ), 41 'expected' => false, 44 // Happy paths. 45 'a lower required version' => array( 46 'required' => $lower_version, 47 'expected' => true, 42 48 ), 43 ' same'=> array(44 ' test_value' => $php_version,45 'expected' 49 'the same version' => array( 50 'required' => $php_version, 51 'expected' => true, 46 52 ), 47 'less' => array( 48 'test_value' => implode( '.', $less ), 49 'expected' => true, 53 'a higher required version' => array( 54 'required' => $higher_version, 55 'expected' => false, 56 ), 57 58 // Falsey values. 59 'false' => array( 60 'required' => false, 61 'expected' => true, 62 ), 63 'null' => array( 64 'required' => null, 65 'expected' => true, 66 ), 67 '0 int' => array( 68 'required' => 0, 69 'expected' => true, 70 ), 71 '0.0 float' => array( 72 'required' => 0.0, 73 'expected' => true, 74 ), 75 '0 string' => array( 76 'required' => '0', 77 'expected' => true, 78 ), 79 'empty string' => array( 80 'required' => '', 81 'expected' => true, 82 ), 83 'empty array' => array( 84 'required' => array(), 85 'expected' => true, 50 86 ), 51 87 ); -
trunk/tests/phpunit/tests/functions/isWpVersionCompatible.php
r53227 r53237 2 2 3 3 /** 4 * Tests the is_ php_version_compatiblefunction.4 * Tests the is_wp_version_compatible() function. 5 5 * 6 6 * @group functions.php 7 7 * @covers ::is_wp_version_compatible 8 8 */ 9 class Tests_Functions_ isWpVersionCompatible extends WP_UnitTestCase {9 class Tests_Functions_IsWpVersionCompatible extends WP_UnitTestCase { 10 10 /** 11 * Test is_wp_version_compatible().11 * Tests is_wp_version_compatible(). 12 12 * 13 13 * @dataProvider data_is_wp_version_compatible 14 14 * 15 * @param mixed $test_value 16 * @param bool $expected 15 * @ticket 54257 17 16 * 18 * @ticket 54257 17 * @param mixed $required The minimum required WordPress version. 18 * @param bool $expected The expected result. 19 19 */ 20 public function test_is_wp_version_compatible( $ test_value, $expected ) {21 $this->assertSame( is_wp_version_compatible( $test_value ), $expected);20 public function test_is_wp_version_compatible( $required, $expected ) { 21 $this->assertSame( $expected, is_wp_version_compatible( $required ) ); 22 22 } 23 23 24 24 /** 25 * Provides test scenarios test_is_wp_version_compatible.25 * Data provider. 26 26 * 27 27 * @return array 28 28 */ 29 function data_is_wp_version_compatible() {30 $wp_version = get_bloginfo( 'version' );29 public function data_is_wp_version_compatible() { 30 global $wp_version; 31 31 32 $more = explode( '.', $wp_version ); 33 $less = $more; 32 $version_parts = explode( '.', $wp_version ); 33 $lower_version = $version_parts; 34 $higher_version = $version_parts; 34 35 35 -- $less[0]; 36 ++ $more[0]; 36 // Adjust the major version numbers. 37 --$lower_version[0]; 38 ++$higher_version[0]; 39 40 $lower_version = implode( '.', $lower_version ); 41 $higher_version = implode( '.', $higher_version ); 37 42 38 43 return array( 39 'greater' => array( 40 'test_value' => implode( '.', $more ), 41 'expected' => false, 44 // Happy paths. 45 'the same version' => array( 46 'required' => $wp_version, 47 'expected' => true, 42 48 ), 43 ' same'=> array(44 ' test_value' => $wp_version,45 'expected' 49 'a lower required version' => array( 50 'required' => $lower_version, 51 'expected' => true, 46 52 ), 47 'less' => array( 48 'test_value' => implode( '.', $less ), 49 'expected' => true, 53 'a higher required version' => array( 54 'required' => $higher_version, 55 'expected' => false, 56 ), 57 58 // Falsey values. 59 'false' => array( 60 'required' => false, 61 'expected' => true, 62 ), 63 'null' => array( 64 'required' => null, 65 'expected' => true, 66 ), 67 '0 int' => array( 68 'required' => 0, 69 'expected' => true, 70 ), 71 '0.0 float' => array( 72 'required' => 0.0, 73 'expected' => true, 74 ), 75 '0 string' => array( 76 'required' => '0', 77 'expected' => true, 78 ), 79 'empty string' => array( 80 'required' => '', 81 'expected' => true, 82 ), 83 'empty array' => array( 84 'required' => array(), 85 'expected' => true, 86 ), 87 ); 88 } 89 90 /** 91 * Tests is_wp_version_compatible() with development versions. 92 * 93 * @dataProvider data_is_wp_version_compatible_with_development_versions 94 * 95 * @ticket 54257 96 * 97 * @param string $required The minimum required WordPress version. 98 * @param string $wp The value for the $wp_version global variable. 99 * @param bool $expected The expected result. 100 */ 101 public function test_is_wp_version_compatible_with_development_versions( $required, $wp, $expected ) { 102 global $wp_version; 103 104 $original_version = $wp_version; 105 $wp_version = $wp; 106 $actual = is_wp_version_compatible( $required ); 107 108 // Reset the version before the assertion in case of failure. 109 $wp_version = $original_version; 110 111 $this->assertSame( $expected, $actual ); 112 } 113 114 /** 115 * Data provider. 116 * 117 * @return array 118 */ 119 public function data_is_wp_version_compatible_with_development_versions() { 120 global $wp_version; 121 122 // For consistent results, remove possible suffixes. 123 list( $version ) = explode( '-', $wp_version ); 124 125 $version_parts = explode( '.', $version ); 126 $lower_version = $version_parts; 127 $higher_version = $version_parts; 128 129 // Adjust the major version numbers. 130 --$lower_version[0]; 131 ++$higher_version[0]; 132 133 $lower_version = implode( '.', $lower_version ); 134 $higher_version = implode( '.', $higher_version ); 135 136 return array( 137 'a lower required version and an alpha wordpress version' => array( 138 'required' => $lower_version, 139 'wp' => $version . '-alpha-12341-src', 140 'expected' => true, 141 ), 142 'a lower required version and a beta wordpress version' => array( 143 'required' => $lower_version, 144 'wp' => $version . '-beta1', 145 'expected' => true, 146 ), 147 'a lower required version and a release candidate wordpress version' => array( 148 'required' => $lower_version, 149 'wp' => $version . '-RC1', 150 'expected' => true, 151 ), 152 'the same required version and an alpha wordpress version' => array( 153 'required' => $version, 154 'wp' => $version . '-alpha-12341-src', 155 'expected' => true, 156 ), 157 'the same required version and a beta wordpress version' => array( 158 'required' => $version, 159 'wp' => $version . '-beta1', 160 'expected' => true, 161 ), 162 'the same required version and a release candidate wordpress version' => array( 163 'required' => $version, 164 'wp' => $version . '-RC1', 165 'expected' => true, 166 ), 167 'a higher required version and an alpha wordpress version' => array( 168 'required' => $higher_version, 169 'wp' => $version . '-alpha-12341-src', 170 'expected' => false, 171 ), 172 'a higher required version and a beta wordpress version' => array( 173 'required' => $higher_version, 174 'wp' => $version . '-beta1', 175 'expected' => false, 176 ), 177 'a higher required version and a release candidate wordpress version' => array( 178 'required' => $higher_version, 179 'wp' => $version . '-RC1', 180 'expected' => false, 50 181 ), 51 182 );
Note: See TracChangeset
for help on using the changeset viewer.