Skip to content

Commit

Permalink
Remove hard-coded WP latest version check (#28)
Browse files Browse the repository at this point in the history
* copy the wp-latest.json file out of the tmp directory into the tests
this way we can use that file to validate against the version of WP that WP is reporting for itself and remove the hard-coded versions

* adds a helper method that gets the wp version from wp-latest.json

* use the version stored in wp-latest.json

* remove commented out var_dump

* ignore the vip sniff

* remove the true (for no db install) that i used for testing
  • Loading branch information
jazzsequence authored Dec 12, 2023
1 parent 983a72c commit 133425b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<exclude name="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>*/*</exclude-pattern>
</exclude>
<exclude name="WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown">
<exclude-pattern>*/*</exclude-pattern>
</exclude>
<exclude name="WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid">
<exclude-pattern>inc/pantheon-page-cache.php</exclude-pattern>
</exclude>
Expand Down
6 changes: 6 additions & 0 deletions bin/phpunit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ DIRNAME=$(dirname "$0")
echo "🤔 Installing WP Unit tests..."
bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 latest

echo "📄 Copying wp-latest.json..."
cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json"

echo "🏃‍♂️ Running PHPUnit on Single Site"
composer phpunit --ansi

echo "🧹 Removing files before testing nightly WP..."
rm -rf "$WP_TESTS_DIR" "$WP_CORE_DIR"
rm "${DIRNAME}/../tests/wp-latest.json"

echo "🤔 Installing WP Unit tests with WP nightly version..."
bash "${DIRNAME}/install-wp-tests.sh" wordpress_test root root 127.0.0.1 nightly true
echo "📄 Copying wp-latest.json..."
cp /tmp/wp-latest.json "${DIRNAME}/../tests/wp-latest.json"
echo "🏃‍♂️ Running PHPUnit on Single Site (Nightly WordPress)"
composer phpunit --ansi

Expand Down
21 changes: 20 additions & 1 deletion tests/phpunit/test-pantheon-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ public function __construct() {
self::$wp_version = _pantheon_get_current_wordpress_version();
}

/**
* Get the latest WordPress version from the wp-latest.json file.
*
* @return string|bool The latest WordPress version or false if the file doesn't exist.
*/
private static function get_latest_wp_version_from_file() {
$file = dirname( __DIR__ ) . '/wp-latest.json';

if ( ! file_exists( $file ) ) {
return false;
}

$version_raw = json_decode( file_get_contents( $file ) );
$version = $version_raw->offers[0]->current;

return $version;
}

/**
* Test the _pantheon_hide_update_nag function.
*/
Expand All @@ -46,9 +64,10 @@ public function test_pantheon_hide_update_nag() {
public function test_pantheon_get_current_wordpress_version() {
// Run the function.
$result = _pantheon_get_current_wordpress_version();
$current_version = self::get_latest_wp_version_from_file();

// 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 );
$this->assertEquals( $current_version, $result );
}

/**
Expand Down

0 comments on commit 133425b

Please sign in to comment.