From f678a5c114a23e79f1565ec747cddfb71b6088b5 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Thu, 26 Jun 2025 23:54:39 +0200 Subject: [PATCH 1/2] Fix wrong regex for WP 10+ --- includes/Traits/Version_Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Traits/Version_Utils.php b/includes/Traits/Version_Utils.php index 7594f5d5c..b0f625bb3 100644 --- a/includes/Traits/Version_Utils.php +++ b/includes/Traits/Version_Utils.php @@ -27,7 +27,7 @@ protected function get_wordpress_stable_version(): string { // Strip off any -alpha, -RC, -beta suffixes. list( $version, ) = explode( '-', $version ); - if ( preg_match( '#^\d.\d#', $version, $matches ) ) { + if ( preg_match( '#^\d+\.\d+#', $version, $matches ) ) { $version = $matches[0]; } From be68404f5bc61cf34505b0eda6466f698c63dd15 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 30 Jun 2025 22:06:48 +0545 Subject: [PATCH 2/2] Add unit test for the change --- includes/Traits/Version_Utils.php | 2 +- .../tests/Traits/Version_Utils_Tests.php | 88 ++++++++++++------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/includes/Traits/Version_Utils.php b/includes/Traits/Version_Utils.php index b0f625bb3..2b36a0caf 100644 --- a/includes/Traits/Version_Utils.php +++ b/includes/Traits/Version_Utils.php @@ -27,7 +27,7 @@ protected function get_wordpress_stable_version(): string { // Strip off any -alpha, -RC, -beta suffixes. list( $version, ) = explode( '-', $version ); - if ( preg_match( '#^\d+\.\d+#', $version, $matches ) ) { + if ( preg_match( '#^\d+\.\d#', $version, $matches ) ) { $version = $matches[0]; } diff --git a/tests/phpunit/tests/Traits/Version_Utils_Tests.php b/tests/phpunit/tests/Traits/Version_Utils_Tests.php index 248caf43d..7c40b0b00 100644 --- a/tests/phpunit/tests/Traits/Version_Utils_Tests.php +++ b/tests/phpunit/tests/Traits/Version_Utils_Tests.php @@ -13,39 +13,20 @@ class Version_Utils_Tests extends WP_UnitTestCase { protected $info_transient_key = 'wp_plugin_check_latest_version_info'; - public function set_up() { - parent::set_up(); - - $info_data = array( - 'response' => 'upgrade', - 'download' => 'https://downloads.wordpress.org/release/wordpress-6.7.1.zip', - 'locale' => 'en_US', - 'packages' => array( - 'full' => 'https://downloads.wordpress.org/release/wordpress-6.7.1.zip', - 'no_content' => 'https://downloads.wordpress.org/release/wordpress-6.7.1-no-content.zip', - 'new_bundled' => 'https://downloads.wordpress.org/release/wordpress-6.7.1-new-bundled.zip', - 'partial' => false, - 'rollback' => false, - ), - 'current' => '6.7.1', - 'version' => '6.7.1', - 'php_version' => '7.2.24', - 'mysql_version' => '5.5.5', - 'new_bundled' => '6.7', - 'partial_version' => false, - ); - - set_transient( $this->info_transient_key, $info_data ); - } - - public function test_wordpress_latest_version() { - $version = $this->get_wordpress_latest_version(); - $this->assertSame( '6.7.1', $version ); + /** + * @dataProvider data_version_test_cases + */ + public function test_wordpress_latest_version( $full_version, $expected_major ) { + $this->set_test_version_data( $full_version ); + $this->assertSame( $full_version, $this->get_wordpress_latest_version() ); } - public function test_wordpress_stable_version() { - $version = $this->get_wordpress_stable_version(); - $this->assertSame( '6.7', $version ); + /** + * @dataProvider data_version_test_cases + */ + public function test_wordpress_stable_version( $full_version, $expected_major ) { + $this->set_test_version_data( $full_version ); + $this->assertSame( $expected_major, $this->get_wordpress_stable_version() ); } /** @@ -56,9 +37,35 @@ public function test_wordpress_relative_major_version( $version, $steps, $new_ve $this->assertSame( $new_version, $result ); } - public function tear_down() { - delete_transient( $this->info_transient_key ); - parent::tear_down(); + protected function set_test_version_data( $version ) { + $major_version = substr( $version, 0, strrpos( $version, '.' ) ); + + set_transient( + $this->info_transient_key, + array( + 'version' => $version, + 'new_bundled' => $major_version, + 'current' => $version, + 'response' => 'upgrade', + 'download' => "https://downloads.wordpress.org/release/wordpress-{$version}.zip", + 'php_version' => '7.2.24', + 'mysql_version' => '5.5.5', + 'packages' => array( + 'full' => "https://downloads.wordpress.org/release/wordpress-{$version}.zip", + 'no_content' => "https://downloads.wordpress.org/release/wordpress-{$version}-no-content.zip", + 'new_bundled' => "https://downloads.wordpress.org/release/wordpress-{$version}-new-bundled.zip", + 'partial' => false, + 'rollback' => false, + ), + ) + ); + } + + public function data_version_test_cases() { + return array( + 'single-digit-version' => array( '6.7.1', '6.7' ), + 'double-digit-version' => array( '11.8.3', '11.8' ), + ); } public function data_wordpress_version_items() { @@ -73,6 +80,19 @@ public function data_wordpress_version_items() { array( '6.0', -2, '5.8' ), array( '5.8', 2, '6.0' ), array( '6.1', -2, '5.9' ), + array( '11.2', 1, '11.3' ), + array( '11.2', -1, '11.1' ), + array( '10.9', 1, '11.0' ), + array( '11.0', -1, '10.9' ), + array( '0.9', 1, '1.0' ), + array( '1.0', -1, '0.9' ), + array( '99.9', 1, '100.0' ), + array( '100.0', -1, '99.9' ), ); } + + public function tear_down() { + delete_transient( $this->info_transient_key ); + parent::tear_down(); + } }