Skip to content

Commit 9b112d5

Browse files
authored
Merge pull request #987 from kkmuffme/patch-1
Fix wrong regex for WP 10+
2 parents 9d2f354 + 59b26d0 commit 9b112d5

File tree

2 files changed

+55
-35
lines changed

2 files changed

+55
-35
lines changed

includes/Traits/Version_Utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function get_wordpress_stable_version(): string {
2727
// Strip off any -alpha, -RC, -beta suffixes.
2828
list( $version, ) = explode( '-', $version );
2929

30-
if ( preg_match( '#^\d.\d#', $version, $matches ) ) {
30+
if ( preg_match( '#^\d+\.\d#', $version, $matches ) ) {
3131
$version = $matches[0];
3232
}
3333

tests/phpunit/tests/Traits/Version_Utils_Tests.php

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,20 @@ class Version_Utils_Tests extends WP_UnitTestCase {
1313

1414
protected $info_transient_key = 'wp_plugin_check_latest_version_info';
1515

16-
public function set_up() {
17-
parent::set_up();
18-
19-
$info_data = array(
20-
'response' => 'upgrade',
21-
'download' => 'https://downloads.wordpress.org/release/wordpress-6.7.1.zip',
22-
'locale' => 'en_US',
23-
'packages' => array(
24-
'full' => 'https://downloads.wordpress.org/release/wordpress-6.7.1.zip',
25-
'no_content' => 'https://downloads.wordpress.org/release/wordpress-6.7.1-no-content.zip',
26-
'new_bundled' => 'https://downloads.wordpress.org/release/wordpress-6.7.1-new-bundled.zip',
27-
'partial' => false,
28-
'rollback' => false,
29-
),
30-
'current' => '6.7.1',
31-
'version' => '6.7.1',
32-
'php_version' => '7.2.24',
33-
'mysql_version' => '5.5.5',
34-
'new_bundled' => '6.7',
35-
'partial_version' => false,
36-
);
37-
38-
set_transient( $this->info_transient_key, $info_data );
39-
}
40-
41-
public function test_wordpress_latest_version() {
42-
$version = $this->get_wordpress_latest_version();
43-
$this->assertSame( '6.7.1', $version );
16+
/**
17+
* @dataProvider data_version_test_cases
18+
*/
19+
public function test_wordpress_latest_version( $full_version, $expected_major ) {
20+
$this->set_test_version_data( $full_version );
21+
$this->assertSame( $full_version, $this->get_wordpress_latest_version() );
4422
}
4523

46-
public function test_wordpress_stable_version() {
47-
$version = $this->get_wordpress_stable_version();
48-
$this->assertSame( '6.7', $version );
24+
/**
25+
* @dataProvider data_version_test_cases
26+
*/
27+
public function test_wordpress_stable_version( $full_version, $expected_major ) {
28+
$this->set_test_version_data( $full_version );
29+
$this->assertSame( $expected_major, $this->get_wordpress_stable_version() );
4930
}
5031

5132
/**
@@ -56,9 +37,35 @@ public function test_wordpress_relative_major_version( $version, $steps, $new_ve
5637
$this->assertSame( $new_version, $result );
5738
}
5839

59-
public function tear_down() {
60-
delete_transient( $this->info_transient_key );
61-
parent::tear_down();
40+
protected function set_test_version_data( $version ) {
41+
$major_version = substr( $version, 0, strrpos( $version, '.' ) );
42+
43+
set_transient(
44+
$this->info_transient_key,
45+
array(
46+
'version' => $version,
47+
'new_bundled' => $major_version,
48+
'current' => $version,
49+
'response' => 'upgrade',
50+
'download' => "https://downloads.wordpress.org/release/wordpress-{$version}.zip",
51+
'php_version' => '7.2.24',
52+
'mysql_version' => '5.5.5',
53+
'packages' => array(
54+
'full' => "https://downloads.wordpress.org/release/wordpress-{$version}.zip",
55+
'no_content' => "https://downloads.wordpress.org/release/wordpress-{$version}-no-content.zip",
56+
'new_bundled' => "https://downloads.wordpress.org/release/wordpress-{$version}-new-bundled.zip",
57+
'partial' => false,
58+
'rollback' => false,
59+
),
60+
)
61+
);
62+
}
63+
64+
public function data_version_test_cases() {
65+
return array(
66+
'single-digit-version' => array( '6.7.1', '6.7' ),
67+
'double-digit-version' => array( '11.8.3', '11.8' ),
68+
);
6269
}
6370

6471
public function data_wordpress_version_items() {
@@ -73,6 +80,19 @@ public function data_wordpress_version_items() {
7380
array( '6.0', -2, '5.8' ),
7481
array( '5.8', 2, '6.0' ),
7582
array( '6.1', -2, '5.9' ),
83+
array( '11.2', 1, '11.3' ),
84+
array( '11.2', -1, '11.1' ),
85+
array( '10.9', 1, '11.0' ),
86+
array( '11.0', -1, '10.9' ),
87+
array( '0.9', 1, '1.0' ),
88+
array( '1.0', -1, '0.9' ),
89+
array( '99.9', 1, '100.0' ),
90+
array( '100.0', -1, '99.9' ),
7691
);
7792
}
93+
94+
public function tear_down() {
95+
delete_transient( $this->info_transient_key );
96+
parent::tear_down();
97+
}
7898
}

0 commit comments

Comments
 (0)