Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old theme #6

Open
wants to merge 25 commits into
base: trunk
Choose a base branch
from
Open
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
89 changes: 45 additions & 44 deletions .github/files/generate-ci-matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,38 @@
// Matrix definitions. Each will be combined with `$default_matrix_vars` later in processing.
$matrix = array();

// Add PHP tests.

Check warning on line 61 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

This comment is 50% valid code; is this commented out code? (Squiz.PHP.CommentedOutCode.Found)
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(

Check failure on line 64 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Spaces must be used for mid-line alignment; tabs are not allowed (Universal.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed)

Check failure on line 64 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Expected 1 space before comment text but found 2; use block comment if you need indentation (Squiz.Commenting.InlineComment.SpacingBefore)
// 'name' => "PHP tests: PHP $php WP latest",

Check failure on line 65 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Spaces must be used for mid-line alignment; tabs are not allowed (Universal.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed)

Check failure on line 65 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Expected 1 space before comment text but found 6; use block comment if you need indentation (Squiz.Commenting.InlineComment.SpacingBefore)
// 'script' => 'test-php',

Check failure on line 66 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Spaces must be used for mid-line alignment; tabs are not allowed (Universal.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed)

Check failure on line 66 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Expected 1 space before comment text but found 6; use block comment if you need indentation (Squiz.Commenting.InlineComment.SpacingBefore)
// 'php' => $php,

Check failure on line 67 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Spaces must be used for mid-line alignment; tabs are not allowed (Universal.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed)

Check failure on line 67 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Expected 1 space before comment text but found 6; use block comment if you need indentation (Squiz.Commenting.InlineComment.SpacingBefore)
// 'wp' => 'latest',

Check failure on line 68 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Spaces must be used for mid-line alignment; tabs are not allowed (Universal.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed)

Check failure on line 68 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Expected 1 space before comment text but found 6; use block comment if you need indentation (Squiz.Commenting.InlineComment.SpacingBefore)
// 'timeout' => 20, // 2024-11-12: Successful runs seem to take up to ~7 minutes.
// );
// }

// foreach ( array( 'previous', 'trunk' ) as $wp ) {

Check warning on line 73 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

This comment is 53% valid code; is this commented out code? (Squiz.PHP.CommentedOutCode.Found)
// $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.

Check warning on line 84 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

This comment is 51% valid code; is this commented out code? (Squiz.PHP.CommentedOutCode.Found)
// $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(
Expand All @@ -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.

Check warning on line 104 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

This comment is 50% valid code; is this commented out code? (Squiz.PHP.CommentedOutCode.Found)
// $matrix[] = array(
// 'name' => 'JS tests',
// 'script' => 'test-js',
// 'timeout' => 15, // 2024-11-12: Successful runs seem to take ~5 minutes.
// );

// // Add Coverage tests.

Check warning on line 111 in .github/files/generate-ci-matrix.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

This comment is 50% valid code; is this commented out code? (Squiz.PHP.CommentedOutCode.Found)
// $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.
Expand Down
3 changes: 3 additions & 0 deletions .github/files/setup-wordpress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
132 changes: 70 additions & 62 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-old_theme
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other


2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/action-test-php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions projects/plugins/jetpack/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:disable

use Automattic\Jetpack\Sync\Defaults;
use Automattic\Jetpack\Sync\Modules;
Expand Down Expand Up @@ -250,18 +250,75 @@ private function perform_network_enable_disable_assertions( $test_themes, $event
}

public function test_install_edit_delete_theme_sync() {
error_log(var_export('test_install_edit_delete_theme_sync', true));
$theme_slug = 'itek';
$theme_name = 'iTek';

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 );
$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 );
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/wpcomsh/changelog/fix-old_theme
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed


Loading
Loading