Skip to content

Commit

Permalink
PHPUnit test updates for WP 6.4.1 (#27)
Browse files Browse the repository at this point in the history
* remove setting the $wp_version to 6.3.1
looks like we can't actually override the global since it will get set as soon as we run _pantheon_get_current_wordpress_version.
The WordPress version will always be the installed version from this function so we just need to remember to update the unit tests for this one.

* bump the wp version to current

* set a static wp_version property that we can use later

* figure out the next beta version based on the current version

* dynamically get the next beta version

* add @var for linting
  • Loading branch information
jazzsequence authored Nov 30, 2023
1 parent 08f07be commit 983a72c
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions tests/phpunit/test-pantheon-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
* Pantheon Updates Test Case
*/
class Test_Pantheon_Updates extends WP_UnitTestCase {
/**
* The current WordPress version.
*
* @var string
*/
private static $wp_version;

/**
* The main constructor.
*/
public function __construct() {
parent::__construct();
self::$wp_version = _pantheon_get_current_wordpress_version();
}

/**
* Test the _pantheon_hide_update_nag function.
*/
Expand All @@ -29,14 +44,11 @@ public function test_pantheon_hide_update_nag() {
* Test the _pantheon_get_current_wordpress_version function.
*/
public function test_pantheon_get_current_wordpress_version() {
global $wp_version;
$wp_version = '6.3.1'; // Mocking the WP version for this test.

// Run the function.
$result = _pantheon_get_current_wordpress_version();
// Check that the returned version is correct.
$this->assertEquals( '6.3.1', $result );

// Check that the returned version is correct. This value needs to be changed when the WordPress version is updated.
$this->assertEquals( '6.4.1', $result );
}

/**
Expand Down Expand Up @@ -122,10 +134,20 @@ public function test_pantheon_upstream_update_notice_core_not_latest() {
$this->assertStringContainsString( 'Check for updates on <a href="https://dashboard.pantheon.io/sites/test-site">your Pantheon dashboard</a>', $output );
}

/**
* Get the next beta version based on the current version.
*/
private static function get_next_beta_version() {
$version_parts = explode( '.', self::$wp_version );
$version_parts[2] = (int) $version_parts[2] + 1;
return implode( '.', $version_parts ) . '-beta';
}

/**
* Test the _pantheon_upstream_update_notice function for beta/pre-release version.
*/
public function test_pantheon_upstream_update_notice_core_prerelease() {
$beta_version = self::get_next_beta_version();
set_current_screen( 'update-core' );

// Simulate that the core is a prerelease.
Expand All @@ -134,12 +156,12 @@ public function test_pantheon_upstream_update_notice_core_prerelease() {
(object) [
'updates' => [
(object) [
'current' => '6.4-beta',
'current' => $beta_version,
'response' => 'upgrade',
'locale' => 'en_us',
],
],
'version_checked' => '6.4-beta',
'version_checked' => $beta_version,
],
);

Expand Down

0 comments on commit 983a72c

Please sign in to comment.