diff --git a/.github/files/generate-ci-matrix.php b/.github/files/generate-ci-matrix.php index d7531e8eea9a..2eb7e111475f 100755 --- a/.github/files/generate-ci-matrix.php +++ b/.github/files/generate-ci-matrix.php @@ -59,36 +59,37 @@ $matrix = array(); // Add PHP tests. -foreach ( array( '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ) as $php ) { - $matrix[] = array( - 'name' => "PHP tests: PHP $php WP latest", - 'script' => 'test-php', - 'php' => $php, - 'wp' => 'latest', - 'timeout' => 20, // 2024-11-12: Successful runs seem to take up to ~7 minutes. - ); -} - -foreach ( array( 'previous', 'trunk' ) as $wp ) { - $phpver = $versions['PHP_VERSION']; - $matrix[] = array( - 'name' => "PHP tests: PHP {$phpver} WP $wp", - 'script' => 'test-php', - 'php' => $phpver, - 'wp' => $wp, - 'timeout' => 15, // 2024-11-12: Successful runs seem to take ~7 minutes with PHP 8.2. - ); -} - -// Add WooCommerce tests. -$matrix[] = array( - 'name' => 'PHP tests: PHP 7.4 WP latest with WooCommerce', - 'script' => 'test-php', - 'php' => '7.4', - 'wp' => 'latest', - 'timeout' => 20, - 'with-woocommerce' => true, -); +// foreach ( array( '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ) as $php ) { +// foreach ( array( '8.2' ) as $php ) { +// $matrix[] = array( +// 'name' => "PHP tests: PHP $php WP latest", +// 'script' => 'test-php', +// 'php' => $php, +// 'wp' => 'latest', +// 'timeout' => 20, // 2024-11-12: Successful runs seem to take up to ~7 minutes. +// ); +// } + +// foreach ( array( 'previous', 'trunk' ) as $wp ) { +// $phpver = $versions['PHP_VERSION']; +// $matrix[] = array( +// 'name' => "PHP tests: PHP {$phpver} WP $wp", +// 'script' => 'test-php', +// 'php' => $phpver, +// 'wp' => $wp, +// 'timeout' => 15, // 2024-11-12: Successful runs seem to take ~7 minutes with PHP 8.2. +// ); +// } + +// // Add WooCommerce tests. +// $matrix[] = array( +// 'name' => 'PHP tests: PHP 7.4 WP latest with WooCommerce', +// 'script' => 'test-php', +// 'php' => '7.4', +// 'wp' => 'latest', +// 'timeout' => 20, +// 'with-woocommerce' => true, +// ); // Add wpcomsh tests. $matrix[] = array( @@ -100,20 +101,20 @@ 'with-wpcomsh' => true, ); -// Add JS tests. -$matrix[] = array( - 'name' => 'JS tests', - 'script' => 'test-js', - 'timeout' => 15, // 2024-11-12: Successful runs seem to take ~5 minutes. -); - -// Add Coverage tests. -$matrix[] = array( - 'name' => 'Code coverage', - 'script' => 'test-coverage', - 'wp' => 'latest', - 'timeout' => 40, // 2024-11-12: Successful runs seem to take ~14 minutes. -); +// // Add JS tests. +// $matrix[] = array( +// 'name' => 'JS tests', +// 'script' => 'test-js', +// 'timeout' => 15, // 2024-11-12: Successful runs seem to take ~5 minutes. +// ); + +// // Add Coverage tests. +// $matrix[] = array( +// 'name' => 'Code coverage', +// 'script' => 'test-coverage', +// 'wp' => 'latest', +// 'timeout' => 40, // 2024-11-12: Successful runs seem to take ~14 minutes. +// ); // END matrix definitions. // Now, validation. diff --git a/.github/files/setup-wordpress-env.sh b/.github/files/setup-wordpress-env.sh index d344df4b17f5..4d0f90438056 100755 --- a/.github/files/setup-wordpress-env.sh +++ b/.github/files/setup-wordpress-env.sh @@ -49,6 +49,9 @@ EXIT=0 for PLUGIN in projects/plugins/*/composer.json; do DIR="${PLUGIN%/composer.json}" NAME="$(basename "$DIR")" + if [[ $NAME != 'jetpack' && $NAME != 'wpcomsh' ]]; then + continue; + fi echo "::group::Installing plugin $NAME into WordPress" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a18c812be4b0..e1eec0fb5f6d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -144,6 +144,12 @@ jobs: SLUG="${DIR#projects/}" fi + if [[ "${SLUG%%/*}" != "plugins" ]]; then + continue; + fi + if [[ $SLUG != "plugins/jetpack" && $SLUG != "plugins/wpcomsh" ]]; then + continue + fi if [[ "${SLUG%%/*}" != "plugins" && "$WP_BRANCH" != 'latest' && "$WP_BRANCH" != 'none' && "$FORCE_PACKAGE_TESTS" != "true" ]]; then echo "Skipping $SLUG, only plugins run for WP_BRANCH = $WP_BRANCH" continue @@ -168,7 +174,9 @@ jobs: continue fi fi - + if [[ $SLUG != 'plugins/jetpack' ]]; then + continue; + fi echo "Running tests for $SLUG" { # Composer install, if appropriate. Note setup-wordpress-env.sh did it already for plugins. @@ -366,64 +374,64 @@ jobs: tools/check-plugin-monorepo-deps.sh "${ARGS[@]}" # Probably this should be a linting test too, but we don't run linting on trunk or release branches. - phan: - name: Static analysis - runs-on: ubuntu-latest - timeout-minutes: 20 # 2024-05-02: Up to about 8 minutes now that we're running against the old WP stubs too. - steps: - - uses: actions/checkout@v4 - - name: Setup tools - uses: ./.github/actions/tool-setup - - name: Pnpm install - run: pnpm install - - name: Run phan - run: pnpm jetpack phan --all -v --update-baseline --format github - - name: Run phan for previous WP version too - env: - # Don't bother complaining about unused suppressions that may be used with the newer stubs. See .phan/config.base.php for how this gets applied. - NO_PHAN_UNUSED_SUPPRESSION: 1 - run: | - composer update --prefer-lowest php-stubs/wordpress-stubs php-stubs/wordpress-tests-stubs - # Don't re-update baselines here, only check. - pnpm jetpack phan --all -v --format github - - name: Check baselines - run: | - # Anything changed? (with a side of printing the diff) - if git diff --exit-code --ignore-matching-lines='^ // ' -- .phan/baseline.php '*/.phan/baseline.php'; then - exit 0 - fi - - # Collect which projects changed to suggest the right command. - PROJECTS=() - for f in $( git -c core.quotepath=off diff --name-only -- .phan/baseline.php '*/.phan/baseline.php' ); do - # --name-only and --ignore-matching-lines don't combine, so we have to do the check separately. - if git diff --quiet --exit-code --ignore-matching-lines='^ // ' -- "$f"; then - continue - fi - - if [[ "$f" == ".phan/baseline.php" ]]; then - SLUG=monorepo - elif [[ "$f" == projects/*/*/.phan/baseline.php ]]; then - SLUG=${f%/.phan/baseline.php} - SLUG=${SLUG#projects/} - elif SLUG=$( grep -v '^[ \t]*\/\/' .phan/monorepo-pseudo-projects.jsonc | jq -re --arg f "${f%.phan/baseline.php}" 'to_entries[] | select( .value == $f ) | .key' ); then - : # Ok - else - SLUG= - fi - if grep -q 'This baseline has no suppressions' "$f"; then - if [[ -n "$SLUG" ]]; then - echo "::error file=$f::This Phan baseline is now empty (good job!). You may remove it, or if you want to keep it (e.g. if you expect new unfixed issues to be added in the future) you can run \`jetpack phan --update-baseline $SLUG\` to update it." - else - echo "::error file=$f::This Phan baseline is now empty (good job!). You may remove it." - fi - elif [[ -n "$SLUG" ]]; then - PROJECTS+=( "$SLUG" ) - else - echo "::error file=$f::This Phan baseline has changed and should be updated. This Action was unable to determine the command needed to update it; please report this to the Garage team." - fi - done - if [[ ${#PROJECTS[@]} -gt 0 ]]; then - echo "::error::Phan baselines have changed (good job!). Run \`jetpack phan --update-baseline ${PROJECTS[*]}\` to update them." - fi - exit 1 + # phan: + # name: Static analysis + # runs-on: ubuntu-latest + # timeout-minutes: 20 # 2024-05-02: Up to about 8 minutes now that we're running against the old WP stubs too. + # steps: + # - uses: actions/checkout@v4 + # - name: Setup tools + # uses: ./.github/actions/tool-setup + # - name: Pnpm install + # run: pnpm install + # - name: Run phan + # run: pnpm jetpack phan --all -v --update-baseline --format github + # - name: Run phan for previous WP version too + # env: + # # Don't bother complaining about unused suppressions that may be used with the newer stubs. See .phan/config.base.php for how this gets applied. + # NO_PHAN_UNUSED_SUPPRESSION: 1 + # run: | + # composer update --prefer-lowest php-stubs/wordpress-stubs php-stubs/wordpress-tests-stubs + # # Don't re-update baselines here, only check. + # pnpm jetpack phan --all -v --format github + # - name: Check baselines + # run: | + # # Anything changed? (with a side of printing the diff) + # if git diff --exit-code --ignore-matching-lines='^ // ' -- .phan/baseline.php '*/.phan/baseline.php'; then + # exit 0 + # fi + + # # Collect which projects changed to suggest the right command. + # PROJECTS=() + # for f in $( git -c core.quotepath=off diff --name-only -- .phan/baseline.php '*/.phan/baseline.php' ); do + # # --name-only and --ignore-matching-lines don't combine, so we have to do the check separately. + # if git diff --quiet --exit-code --ignore-matching-lines='^ // ' -- "$f"; then + # continue + # fi + + # if [[ "$f" == ".phan/baseline.php" ]]; then + # SLUG=monorepo + # elif [[ "$f" == projects/*/*/.phan/baseline.php ]]; then + # SLUG=${f%/.phan/baseline.php} + # SLUG=${SLUG#projects/} + # elif SLUG=$( grep -v '^[ \t]*\/\/' .phan/monorepo-pseudo-projects.jsonc | jq -re --arg f "${f%.phan/baseline.php}" 'to_entries[] | select( .value == $f ) | .key' ); then + # : # Ok + # else + # SLUG= + # fi + # if grep -q 'This baseline has no suppressions' "$f"; then + # if [[ -n "$SLUG" ]]; then + # echo "::error file=$f::This Phan baseline is now empty (good job!). You may remove it, or if you want to keep it (e.g. if you expect new unfixed issues to be added in the future) you can run \`jetpack phan --update-baseline $SLUG\` to update it." + # else + # echo "::error file=$f::This Phan baseline is now empty (good job!). You may remove it." + # fi + # elif [[ -n "$SLUG" ]]; then + # PROJECTS+=( "$SLUG" ) + # else + # echo "::error file=$f::This Phan baseline has changed and should be updated. This Action was unable to determine the command needed to update it; please report this to the Garage team." + # fi + # done + # if [[ ${#PROJECTS[@]} -gt 0 ]]; then + # echo "::error::Phan baselines have changed (good job!). Run \`jetpack phan --update-baseline ${PROJECTS[*]}\` to update them." + # fi + # exit 1 diff --git a/projects/plugins/jetpack/changelog/fix-old_theme b/projects/plugins/jetpack/changelog/fix-old_theme new file mode 100644 index 000000000000..1ef8afea050a --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-old_theme @@ -0,0 +1,4 @@ +Significance: patch +Type: other + + diff --git a/projects/plugins/jetpack/tests/action-test-php.sh b/projects/plugins/jetpack/tests/action-test-php.sh index ce33f626c37a..d5b0e35ddb52 100755 --- a/projects/plugins/jetpack/tests/action-test-php.sh +++ b/projects/plugins/jetpack/tests/action-test-php.sh @@ -16,7 +16,7 @@ if [[ "$WITH_WPCOMSH" == true ]]; then fi echo "::group::Jetpack tests" -phpunit +phpunit --filter WP_Test_Jetpack_Sync_Themes echo "::endgroup::" if [[ "$WP_BRANCH" == "trunk" ]]; then diff --git a/projects/plugins/jetpack/tests/php/bootstrap.php b/projects/plugins/jetpack/tests/php/bootstrap.php index 2411078bd727..268299e37df7 100644 --- a/projects/plugins/jetpack/tests/php/bootstrap.php +++ b/projects/plugins/jetpack/tests/php/bootstrap.php @@ -145,6 +145,9 @@ function _manually_load_muplugin() { if ( ! is_dir( WPCOMSH_PREMIUM_THEMES_PATH ) ) { mkdir( WPCOMSH_PREMIUM_THEMES_PATH, 0777 ); } + echo 'WPCOMSH_PREMIUM_THEMES_PATH'; + echo WPCOMSH_PREMIUM_THEMES_PATH; + var_dump( scandir( WPCOMSH_PREMIUM_THEMES_PATH ) ); } // If we are running the uninstall tests don't load jetpack. diff --git a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-themes.php b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-themes.php index 6a779671f29e..4787a80f08c5 100644 --- a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-themes.php +++ b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-themes.php @@ -1,4 +1,4 @@ -server_event_storage->reset(); // Test Install Theme + error_log(var_export('install_theme', true)); + $this->install_theme( $theme_slug ); + error_log(var_export('end_install_theme', true)); + $this->sender->do_sync(); + + $event_data = $this->server_event_storage->get_most_recent_event( 'jetpack_installed_theme' ); + echo 'asdf'; + var_dump( $event_data ); + + $this->assertEquals( $event_data->args[0], $theme_slug ); + $this->assertEquals( $event_data->args[1]['name'], $theme_name ); + $this->assertTrue( (bool) $event_data->args[1]['version'] ); + $this->assertTrue( (bool) $event_data->args[1]['uri'] ); + + // Test Edit Theme + + /** + * This filter is already documented in wp-includes/pluggable.php + * + * @since 1.5.1 + */ + $_POST['newcontent'] = 'foo'; + apply_filters( 'wp_redirect', 'theme-editor.php?file=style.css&theme=' . $theme_slug . '&scrollto=0&updated=true' ); + $this->sender->do_sync(); + + $event_data = $this->server_event_storage->get_most_recent_event( 'jetpack_edited_theme' ); + $this->assertEquals( $event_data->args[0], $theme_slug ); + $this->assertEquals( $event_data->args[1]['name'], $theme_name ); + $this->assertTrue( (bool) $event_data->args[1]['version'] ); + $this->assertTrue( (bool) $event_data->args[1]['uri'] ); + + unset( $_POST['newcontent'] ); + + // Test Delete Theme + + delete_theme( $theme_slug ); + $this->sender->do_sync(); + + $event_data = $this->server_event_storage->get_most_recent_event( 'jetpack_deleted_theme' ); + + $this->assertEquals( $theme_slug, $event_data->args[0] ); + } + + public function test_install_edit_delete_theme_synac() { + error_log(var_export('test_install_edit_delete_theme_synac', true)); + $theme_slug = 'astra'; + $theme_name = 'Astra'; + + delete_theme( $theme_slug ); // Ensure theme is not lingering on file system + $this->server_event_storage->reset(); + + // Test Install Theme + error_log(var_export('install_theme', true)); $this->install_theme( $theme_slug ); + error_log(var_export('end_install_theme', true)); $this->sender->do_sync(); $event_data = $this->server_event_storage->get_most_recent_event( 'jetpack_installed_theme' ); + echo 'asdf'; + var_dump( $event_data ); $this->assertEquals( $event_data->args[0], $theme_slug ); $this->assertEquals( $event_data->args[1]['name'], $theme_name ); @@ -295,7 +352,7 @@ public function test_install_edit_delete_theme_sync() { $event_data = $this->server_event_storage->get_most_recent_event( 'jetpack_deleted_theme' ); - $this->assertEquals( 'itek', $event_data->args[0] ); + $this->assertEquals( $theme_slug, $event_data->args[0] ); } public function test_update_themes_sync() { @@ -478,6 +535,8 @@ private function install_theme( $slug ) { ) ); $overwrite = ''; + error_log(var_export('$api', true)); + error_log(var_export(!!$api, true)); if ( is_wp_error( $api ) ) { wp_die( $api ); diff --git a/projects/plugins/wpcomsh/changelog/fix-old_theme b/projects/plugins/wpcomsh/changelog/fix-old_theme new file mode 100644 index 000000000000..05ffe09f19e6 --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/fix-old_theme @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + + diff --git a/projects/plugins/wpcomsh/feature-plugins/managed-themes.php b/projects/plugins/wpcomsh/feature-plugins/managed-themes.php index 7d31ca8bc3b9..6f4d9018cab9 100644 --- a/projects/plugins/wpcomsh/feature-plugins/managed-themes.php +++ b/projects/plugins/wpcomsh/feature-plugins/managed-themes.php @@ -1,4 +1,4 @@ -get_stylesheet(); + error_log( var_export( $stylesheet, true ) ); if ( wpcomsh_is_theme_symlinked( $stylesheet ) && wpcomsh_is_wpcom_premium_theme( $stylesheet ) ) { return sprintf( 'premium/%s', $stylesheet ); @@ -70,6 +72,7 @@ function wpcomsh_handle_atomic_premium_theme_option() { * @return bool|\WP_Error */ function wpcomsh_jetpack_wpcom_theme_skip_download( $skip_download_filter_result, $theme_slug ) { + error_log( var_export( 'wpcomsh_jetpack_wpcom_theme_skip_download', true ) ); $theme_type = wpcomsh_get_wpcom_theme_type( $theme_slug ); // If we are dealing with a non WPCom theme, don't interfere. @@ -126,6 +129,7 @@ function () use ( $was_theme_symlinked ) { * @return bool */ function wpcomsh_jetpack_wpcom_theme_delete( $use_alternative_delete_method, $theme_slug ) { + var_dump( 'deleting' ); // phpcs:ignore if ( ! wpcomsh_is_wpcom_theme( $theme_slug ) || ! wpcomsh_is_theme_symlinked( $theme_slug ) ) { return false; } diff --git a/projects/plugins/wpcomsh/functions.php b/projects/plugins/wpcomsh/functions.php index ca9a94601217..8d3983f364a3 100644 --- a/projects/plugins/wpcomsh/functions.php +++ b/projects/plugins/wpcomsh/functions.php @@ -1,4 +1,4 @@ -cache->run_cached( 'wpcom-themes-' . $slug, fn() => $this->handle_request( $url ) ); + error_log( var_export( ['theme',$theme], true ) ); if ( ! $theme || isset( $theme->error ) ) { return null; diff --git a/projects/plugins/wpcomsh/wpcom-themes/includes/class-wpcom-themes-service.php b/projects/plugins/wpcomsh/wpcom-themes/includes/class-wpcom-themes-service.php index 15f1ee210bfd..a4aa065ee3d8 100644 --- a/projects/plugins/wpcomsh/wpcom-themes/includes/class-wpcom-themes-service.php +++ b/projects/plugins/wpcomsh/wpcom-themes/includes/class-wpcom-themes-service.php @@ -1,4 +1,4 @@ -get_theme( $package ); - + error_log( var_export( 'wpcom_theme', true ) ); + error_log( var_export( $wpcom_theme, true ) ); if ( ! $wpcom_theme ) { return $reply; }