Skip to content

Tests: Isolate global styles revisions block variation tests on multisite - #16256

Open
noruzzamans wants to merge 2 commits into
WordPress:trunkfrom
noruzzamans:fix/66755-global-styles-revisions-isolation
Open

noruzzamans wants to merge 2 commits into
WordPress:trunkfrom
noruzzamans:fix/66755-global-styles-revisions-isolation

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Four block style variation tests in WP_REST_Global_Styles_Revisions_Controller_Test fail on multisite when run in isolation or in reverse order (--order-by=reverse), because self::$admin_id lacks unfiltered_html on multisite. When wp_update_post() saves the fixture, wp_filter_global_styles_post() runs WP_Theme_JSON::remove_insecure_properties(), which strips unregistered block style variations before the revision is stored. In full default runs, an earlier test (Tests_Block_Supports_BlockStyleVariations) leaves block-style-variation-a registered in WP_Block_Styles_Registry, masking the failure.

This grants super admin to self::$admin_id on multisite for those four tests before setting the current user, and revokes it with kses_init() in tear_down().

Failing before the fix (multisite, isolated)

npm run test:php -- -c tests/phpunit/multisite.xml --filter WP_REST_Global_Styles_Revisions_Controller_Test

Output:

1) WP_REST_Global_Styles_Revisions_Controller_Test::test_multiple_block_variations_are_preserved
Undefined array key "styles"

2) WP_REST_Global_Styles_Revisions_Controller_Test::test_theme_variations_are_registered_for_revisions
Undefined array key "styles"

3) WP_REST_Global_Styles_Revisions_Controller_Test::test_get_item_preserves_block_style_variations
Response should contain styles.
Failed asserting that an array has the key 'styles'.

4) WP_REST_Global_Styles_Revisions_Controller_Test::test_get_items_preserves_block_style_variations
Should have 2 revisions.
Failed asserting that actual size 1 matches expected size 2.

ERRORS!
Tests: 50, Assertions: 219, Errors: 2, Failures: 2.

Also reproduced in reverse order on multisite (npm run test:php -- -c tests/phpunit/multisite.xml --order-by=reverse --stop-on-failure --filter "Tests_Filesystem_WpFilesystemDirect_Copy|Tests_[U-Z]|WP_").

Passing with the fix

  • Multisite isolated (npm run test:php -- -c tests/phpunit/multisite.xml --filter WP_REST_Global_Styles_Revisions_Controller_Test): OK (50 tests, 234 assertions)
  • Single-site isolated (npm run test:php -- --filter WP_REST_Global_Styles_Revisions_Controller_Test): OK (50 tests, 234 assertions)
  • PHPCS (composer exec phpcs -- tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php): 0 errors, 0 warnings

Trac ticket: https://core.trac.wordpress.org/ticket/66755

@noruzzamans
noruzzamans marked this pull request as ready for review November 26, 2026 06:00
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props noruzzaman, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the scoped privilege setup and cleanup in the four multisite global styles revision tests.

No open issues 🎉

What changed in this PR

This PR makes four global styles revision tests independent of execution order on multisite by allowing their administrator user to save block style variations without KSES stripping them.

Changes:

  • Adds a helper that grants super admin on multisite before setting the current administrator user.
  • Updates the four affected tests to use the helper.
  • Adds teardown cleanup to revoke super admin and reinitialize KSES.
File Description
tests/​phpunit/​tests/​rest-api/​rest-global-styles-revisions-controller.php Adds scoped privilege setup and cleanup for four block style variation tests.

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The four multisite failures are reproducible. Granting the fixture user the capability needed to save these four revisions fixes them. Could you keep that part and drop the flag and new teardown? The base case rolls back the site-admin option, restores hooks and resets the current user. With the flag, revoke and explicit kses_init() removed, the class still passed all 50 tests and 234 assertions in each site mode with seed 42. If another existing test needs the extra cleanup, please share the failing order so we can check that case.

AI review · gpt-6.2-astra

@noruzzamans

Copy link
Copy Markdown
Member Author

Thank you, @lancewillett. Dropped the $granted_super_admin flag and tear_down() in 6e314dc486, keeping only the multisite grant_super_admin() setup in the four tests. Re-verified WP_REST_Global_Styles_Revisions_Controller_Test on both single-site and multisite with --order-by=random --random-order-seed=42 (50 tests, 234 assertions).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the multisite test-fixture capability changes.

No open issues 🎉

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest revision removes the flag and teardown. The four failing multisite cases now grant the fixture user the capability needed to save the variation data. The narrowed class passed 50 tests and 234 assertions in both site modes, including random order.

AI review · gpt-6.2-astra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants