Skip to content

Tests: Restore original theme after cross-origin isolation media tests - #14816

Draft
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-media-cross-origin-isolation
Draft

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-media-cross-origin-isolation

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65893

What

Restores the active theme stylesheet in tear_down() within Tests_Media_wpCrossOriginIsolation in tests/phpunit/tests/media/wpCrossOriginIsolation.php.

Why

test_skips_cross_origin_isolation_for_classic_theme_site_editor_home() calls switch_theme( 'twentytwentyone' ) without restoring the incoming stylesheet, leaving later test suites in the same process on that theme.

How

  • Saves $this->original_stylesheet = get_stylesheet(); during set_up().
  • Restores via switch_theme( $this->original_stylesheet ); in tear_down() when the stylesheet changed.

Testing Instructions

  1. Start the environment: npm run env:start && npm run env:install.
  2. Run random order with seed 1:
    npm run test:php -- --filter Tests_Media_wpCrossOriginIsolation --order-by=random --random-order-seed=1
  3. Run random order with seed 2:
    npm run test:php -- --filter Tests_Media_wpCrossOriginIsolation --order-by=random --random-order-seed=2
  4. Run default order:
    npm run test:php -- --filter Tests_Media_wpCrossOriginIsolation
  5. Confirm all three finish with OK (21 tests, 30 assertions).

Use of AI Tools

  • Cursor

Save the active stylesheet before tests that switch themes and restore it after each test so theme state does not leak into later suites.

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

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

The localized cleanup follows existing test-fixture patterns and has no identified blocking issues; tests were not run.

No open issues 🎉

What changed in this PR

This PR improves isolation in the cross-origin media tests by restoring the incoming theme, preventing theme changes from affecting later tests in the same process.

Changes:

  • Captures the active stylesheet during set_up().
  • Restores it before parent teardown only when the stylesheet has changed.
File Description
tests/​phpunit/​tests/​media/​wpCrossOriginIsolation.php Saves and conditionally restores the active theme stylesheet.

Review effort: Balanced

Align equals signs in set_up() to satisfy PHPCS Generic.Formatting.MultipleStatementAlignment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants