Changeset 57707
- Timestamp:
- 02/25/2024 10:15:11 PM (7 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r57610 r57707 8764 8764 list( $version ) = explode( '-', $wp_version ); 8765 8765 8766 if ( is_string( $required ) ) { 8767 $trimmed = trim( $required ); 8768 8769 if ( substr_count( $trimmed, '.' ) > 1 && str_ends_with( $trimmed, '.0' ) ) { 8770 $required = substr( $trimmed, 0, -2 ); 8771 } 8772 } 8773 8766 8774 return empty( $required ) || version_compare( $version, $required, '>=' ); 8767 8775 } -
trunk/tests/phpunit/tests/functions/isWpVersionCompatible.php
r56971 r57707 44 44 return array( 45 45 // Happy paths. 46 'the same version' => array(46 'the same version' => array( 47 47 'required' => $wp_version, 48 48 'expected' => true, 49 49 ), 50 'a lower required version' => array( 51 'required' => $lower_version, 52 'expected' => true, 53 ), 54 'a higher required version' => array( 55 'required' => $higher_version, 56 'expected' => false, 50 'a lower required version' => array( 51 'required' => $lower_version, 52 'expected' => true, 53 ), 54 'a higher required version' => array( 55 'required' => $higher_version, 56 'expected' => false, 57 ), 58 59 // Acceptable versions containing '.0'. 60 'correct version ending with x.0' => array( 61 'required' => '5.0', 62 'expected' => true, 63 ), 64 'correct version with x.0.x in middle of version' => array( 65 'required' => '5.0.1', 66 'expected' => true, 57 67 ), 58 68 59 69 // Falsey values. 60 'false' => array(70 'false' => array( 61 71 'required' => false, 62 72 'expected' => true, 63 73 ), 64 'null' => array(74 'null' => array( 65 75 'required' => null, 66 76 'expected' => true, 67 77 ), 68 '0 int' => array(78 '0 int' => array( 69 79 'required' => 0, 70 80 'expected' => true, 71 81 ), 72 '0.0 float' => array(82 '0.0 float' => array( 73 83 'required' => 0.0, 74 84 'expected' => true, 75 85 ), 76 '0 string' => array(86 '0 string' => array( 77 87 'required' => '0', 78 88 'expected' => true, 79 89 ), 80 'empty string' => array(90 'empty string' => array( 81 91 'required' => '', 82 92 'expected' => true, 83 93 ), 84 'empty array' => array(94 'empty array' => array( 85 95 'required' => array(), 96 'expected' => true, 97 ), 98 ); 99 } 100 101 /** 102 * Tests that is_wp_version_compatible() gracefully handles incorrect version numbering. 103 * 104 * @dataProvider data_is_wp_version_compatible_should_gracefully_handle_trailing_point_zero_version_numbers 105 * 106 * @ticket 59448 107 * 108 * @param mixed $required The minimum required WordPress version. 109 * @param string $wp The value for the $wp_version global variable. 110 * @param bool $expected The expected result. 111 */ 112 public function test_is_wp_version_compatible_should_gracefully_handle_trailing_point_zero_version_numbers( $required, $wp, $expected ) { 113 global $wp_version; 114 $original_version = $wp_version; 115 $wp_version = $wp; 116 117 $actual = is_wp_version_compatible( $required ); 118 119 // Reset the version before the assertion in case of failure. 120 $wp_version = $original_version; 121 122 $this->assertSame( $expected, $actual, 'The expected result was not returned.' ); 123 } 124 125 /** 126 * Data provider. 127 * 128 * @return array 129 */ 130 public function data_is_wp_version_compatible_should_gracefully_handle_trailing_point_zero_version_numbers() { 131 return array( 132 'an incorrect trailing .0 and the same version' => array( 133 'required' => '5.2.0', 134 'wp' => '5.2', 135 'expected' => true, 136 ), 137 'an incorrect trailing .0 and the same x.0 version' => array( 138 'required' => '5.0.0', 139 'wp' => '5.0', 140 'expected' => true, 141 ), 142 'an incorrect trailing .0 and space and same x.0 version' => array( 143 'required' => '5.0.0 ', 144 'wp' => '5.0', 145 'expected' => true, 146 ), 147 'incorrect preceding and trailing spaces trailing .0' => array( 148 'required' => ' 5.0.0 ', 149 'wp' => '5.0', 150 'expected' => true, 151 ), 152 'an incorrect trailing .0 on x.0.x version' => array( 153 'required' => '5.0.1.0', 154 'wp' => '5.0.1', 155 'expected' => true, 156 ), 157 'an incorrect trailing .0 and an earlier version' => array( 158 'required' => '5.0.0', 159 'wp' => '4.0', 160 'expected' => false, 161 ), 162 'an incorrect trailing .0 and an earlier x.0 version' => array( 163 'required' => '5.0.0', 164 'wp' => '4.0', 165 'expected' => false, 166 ), 167 'an incorrect trailing .0 and a later version' => array( 168 'required' => '5.0.0', 169 'wp' => '6.0', 170 'expected' => true, 171 ), 172 'an incorrect trailing .0 and a later x.0 version' => array( 173 'required' => '5.0.0', 174 'wp' => '6.0', 86 175 'expected' => true, 87 176 ), -
trunk/tests/phpunit/tests/rest-api/rest-plugins-controller.php
r57531 r57707 1022 1022 $this->assertSame( $network_only, $data['network_only'] ); 1023 1023 $this->assertSame( '5.6.0', $data['requires_php'] ); 1024 $this->assertSame( '5.4 .0', $data['requires_wp'] );1024 $this->assertSame( '5.4', $data['requires_wp'] ); 1025 1025 $this->assertSame( 'test-plugin', $data['textdomain'] ); 1026 1026 } … … 1150 1150 * Text Domain: test-plugin 1151 1151 * Requires PHP: 5.6.0 1152 * Requires at least: 5.4 .0{$network}1152 * Requires at least: 5.4{$network} 1153 1153 */ 1154 1154 PHP;
Note: See TracChangeset
for help on using the changeset viewer.