From 4e91c98485fc28dcb5042252571b75aae3568fd8 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Tue, 16 Jul 2024 21:05:06 +0300 Subject: [PATCH 1/6] Added PHP 7.0 testing in WordPress previous. --- .github/files/generate-ci-matrix.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/files/generate-ci-matrix.php b/.github/files/generate-ci-matrix.php index ce67ff260078d..07b56dc2ffba0 100755 --- a/.github/files/generate-ci-matrix.php +++ b/.github/files/generate-ci-matrix.php @@ -58,7 +58,7 @@ $matrix = array(); // Add PHP tests. -foreach ( array( '7.0', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ) as $php ) { +foreach ( array( '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ) as $php ) { $matrix[] = array( 'name' => "PHP tests: PHP $php WP latest", 'script' => 'test-php', @@ -68,6 +68,15 @@ ); } +// TODO: When WordPress 6.5 is no longer supported, this can be removed. +$matrix[] = array( + 'name' => 'PHP tests: PHP 7.0 WP previous', + 'script' => 'test-php', + 'php' => '7.0', + 'wp' => 'previous', + 'timeout' => 20, // 2023-08-17: Successful runs seem to take up to ~12 minutes. +); + foreach ( array( 'previous', 'trunk' ) as $wp ) { $phpver = $versions['PHP_VERSION']; $matrix[] = array( From 39fdfbfd68021929cd7bb88c51ce0e0815c3ab47 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 16 Jul 2024 14:54:46 -0400 Subject: [PATCH 2/6] Still run package tests against 7.0 --- .github/files/generate-ci-matrix.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/files/generate-ci-matrix.php b/.github/files/generate-ci-matrix.php index 07b56dc2ffba0..fb470f485d935 100755 --- a/.github/files/generate-ci-matrix.php +++ b/.github/files/generate-ci-matrix.php @@ -70,11 +70,12 @@ // TODO: When WordPress 6.5 is no longer supported, this can be removed. $matrix[] = array( - 'name' => 'PHP tests: PHP 7.0 WP previous', - 'script' => 'test-php', - 'php' => '7.0', - 'wp' => 'previous', - 'timeout' => 20, // 2023-08-17: Successful runs seem to take up to ~12 minutes. + 'name' => 'PHP tests: PHP 7.0 WP previous', + 'script' => 'test-php', + 'php' => '7.0', + 'wp' => 'previous', + 'timeout' => 20, // 2023-08-17: Successful runs seem to take up to ~12 minutes. + 'force-package-tests' => true, ); foreach ( array( 'previous', 'trunk' ) as $wp ) { From 05633cd3678024422e58f5a47ac3a3e7ea75f978 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 16 Jul 2024 15:08:37 -0400 Subject: [PATCH 3/6] Fix WorDBless + WP_BRANCH=previous --- .github/files/setup-wordpress-env.sh | 24 +++++++++++++++++++----- .github/workflows/tests.yml | 18 ++++++++++-------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.github/files/setup-wordpress-env.sh b/.github/files/setup-wordpress-env.sh index 1b233f1095790..be37da51e0766 100755 --- a/.github/files/setup-wordpress-env.sh +++ b/.github/files/setup-wordpress-env.sh @@ -32,30 +32,31 @@ echo "::endgroup::" echo "::group::Preparing WordPress from \"$WP_BRANCH\" branch"; case "$WP_BRANCH" in trunk) - TAG=trunk + WORDPRESS_TAG=trunk ;; latest) - TAG=$(php ./tools/get-wp-version.php) + WORDPRESS_TAG=$(php ./tools/get-wp-version.php) ;; previous) # We hard-code the version here because there's a time near WP releases where # we've dropped the old 'previous' but WP hasn't actually released the new 'latest' - TAG=6.4 + WORDPRESS_TAG=6.4 ;; *) echo "Unrecognized value for WP_BRANCH: $WP_BRANCH" >&2 exit 1 ;; esac -git clone --depth=1 --branch "$TAG" git://develop.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH" +git clone --depth=1 --branch "$WORDPRESS_TAG" git://develop.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH" # We need a built version of WordPress to test against, so download that into the src directory instead of what's in wordpress-develop. rm -rf "/tmp/wordpress-$WP_BRANCH/src" -git clone --depth=1 --branch "$TAG" git://core.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH/src" +git clone --depth=1 --branch "$WORDPRESS_TAG" git://core.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH/src" echo "::endgroup::" if [[ -n "$GITHUB_ENV" ]]; then echo "WORDPRESS_DEVELOP_DIR=/tmp/wordpress-$WP_BRANCH" >> "$GITHUB_ENV" echo "WORDPRESS_DIR=/tmp/wordpress-$WP_BRANCH/src" >> "$GITHUB_ENV" + echo "WORDPRESS_TAG=$WORDPRESS_TAG" >> "$GITHUB_ENV" fi # Don't symlink, it breaks when copied later. @@ -123,6 +124,19 @@ for PLUGIN in projects/plugins/*/composer.json; do fi cd "$BASE" + # Upgrade/downgrade WorDBless if necessary. + if [[ ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) && "$TEST_SCRIPT" == "test-php" ]]; then + VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version') + if [[ -n "$VER" ]]; then + INSVER=$WORDPRESS_TAG + [[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER" + echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\"" + # Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first. + rm -rf "$DIR/wordpress" + composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER" + fi + fi + cp -r "$DIR" "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME" # Plugin dir for tests in WP >= 5.6-beta1 ln -s "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME" "/tmp/wordpress-$WP_BRANCH/tests/phpunit/data/plugins/$NAME" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 78082fc0f54dc..ac88025faf6f0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -165,15 +165,17 @@ jobs: echo 'Platform reqs failed, running `composer update`' composer --working-dir="$DIR" update fi - fi - if [[ "$WP_BRANCH" == 'trunk' && "$TEST_SCRIPT" == "test-php" ]]; then - VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version') - if [[ -n "$VER" ]]; then - echo 'Supposed to run tests against WordPress trunk, so upgrading roots/wordpress and roots/wordpress-no-content to dev-main' - # Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first. - rm -rf "$DIR/wordpress" - composer --working-dir="$DIR" require --dev roots/wordpress="dev-main as $VER" roots/wordpress-no-content="dev-main as $VER" + if [[ "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ]]; then + VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version') + if [[ -n "$VER" ]]; then + INSVER=$WORDPRESS_TAG + [[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER" + echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\"" + # Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first. + rm -rf "$DIR/wordpress" + composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER" + fi fi fi From eb52c685570b5d105158b692f95cd8feaaf1dd3e Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 16 Jul 2024 15:17:00 -0400 Subject: [PATCH 4/6] Clear composer cache earlier --- .github/workflows/tests.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ac88025faf6f0..5face1f9d875e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -78,6 +78,14 @@ jobs: pnpm install echo "::endgroup::" + # If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version. + if [[ "$WP_BRANCH" == 'trunk' && "$TEST_SCRIPT" == "test-php" ]]; then + echo "::group::Clear composer cache for roots/wordpress" + DIR=$(composer config cache-files-dir) + rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content" + echo "::endgroup::" + fi + - name: Detect changed projects id: changed run: | @@ -105,12 +113,6 @@ jobs: FORCE_PACKAGE_TESTS: ${{ matrix.force-package-tests && 'true' || 'false' }} CHANGED: ${{ steps.changed.outputs.projects }} run: | - # If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version. - if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" ) ]]; then - DIR=$(composer config cache-files-dir) - rm -rf "$DIR/roots/wordpress" - fi - EXIT=0 mkdir artifacts for P in composer.json projects/*/*/composer.json; do From af20e421b0fbc866704ffe1921f53a09534241b7 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 16 Jul 2024 15:18:52 -0400 Subject: [PATCH 5/6] Shift Jetpack legacy full sync tests to PHP 7.2 --- .../plugins/jetpack/changelog/add-manual-previous-70-testing | 5 +++++ projects/plugins/jetpack/tests/action-test-php.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 projects/plugins/jetpack/changelog/add-manual-previous-70-testing diff --git a/projects/plugins/jetpack/changelog/add-manual-previous-70-testing b/projects/plugins/jetpack/changelog/add-manual-previous-70-testing new file mode 100644 index 0000000000000..5278e48862393 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-manual-previous-70-testing @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Run Legacy Full Sync tests with PHP 7.2, now that 7.0 is on its way out. + + diff --git a/projects/plugins/jetpack/tests/action-test-php.sh b/projects/plugins/jetpack/tests/action-test-php.sh index eb82fd51d98cd..ce33f626c37a8 100755 --- a/projects/plugins/jetpack/tests/action-test-php.sh +++ b/projects/plugins/jetpack/tests/action-test-php.sh @@ -25,7 +25,7 @@ if [[ "$WP_BRANCH" == "trunk" ]]; then echo "::endgroup::" fi -if [[ "$WP_BRANCH" == "latest" && "$PHP_VERSION" == "7.0" ]]; then +if [[ "$WP_BRANCH" == "latest" && "$PHP_VERSION" == "7.2" ]]; then echo "::group::Jetpack Legacy Full Sync tests" LEGACY_FULL_SYNC=1 phpunit --group=legacy-full-sync echo "::endgroup::" From 244be206570e1c1c226155ebe26d1bc613d67e8a Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 16 Jul 2024 15:26:51 -0400 Subject: [PATCH 6/6] Fix test for 6.4 and 6.5 --- .../changelog/add-manual-previous-70-testing | 5 +++++ .../verbum-comments/class-verbum-block-utils-test.php | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-manual-previous-70-testing diff --git a/projects/packages/jetpack-mu-wpcom/changelog/add-manual-previous-70-testing b/projects/packages/jetpack-mu-wpcom/changelog/add-manual-previous-70-testing new file mode 100644 index 0000000000000..50cd36eddae57 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/add-manual-previous-70-testing @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Fix a test to work with both WP 6.4 and 6.5. + + diff --git a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/class-verbum-block-utils-test.php b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/class-verbum-block-utils-test.php index a3ea95d1cfd44..35cc2e567c63e 100644 --- a/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/class-verbum-block-utils-test.php +++ b/projects/packages/jetpack-mu-wpcom/tests/php/features/verbum-comments/class-verbum-block-utils-test.php @@ -45,8 +45,14 @@ public function test_comment_text_block_sanitization_sanity_check() { $comment_content = '

test

  • 1
  • 2
  • 3

something

someone
'; $filtered_content = preg_replace( '/\R+/', '', Verbum_Block_Utils::render_verbum_blocks( $comment_content ) ); - $expected_content = '

test

  • 1
  • 2
  • 3

something

someone
'; - $this->assertEquals( $expected_content, $filtered_content ); + // Once we drop WP 6.4, we can change this back to assertSame(). + $expected_content = $this->logicalOr( + // WP 6.4 + $this->identicalTo( '

test

  • 1
  • 2
  • 3

something

someone
' ), + // WP 6.5+ + $this->identicalTo( '

test

  • 1
  • 2
  • 3

something

someone
' ) + ); + $this->assertThat( $filtered_content, $expected_content ); } /**