Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/Traits/Version_Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
88 changes: 54 additions & 34 deletions tests/phpunit/tests/Traits/Version_Utils_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}

/**
Expand All @@ -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() {
Expand All @@ -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();
}
}
Loading