Skip to content

Tests: Restore original theme after classic sidebar widget tests. - #14815

Draft
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-widgets-classic-sidebars
Draft

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-widgets-classic-sidebars

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65893

What

Restores the active theme stylesheet in tear_down() within Tests_Widgets_WpBlockThemeRegisterClassicSidebars in tests/phpunit/tests/widgets/wpBlockThemeRegisterClassicSidebar.php.

Why

test_should_reregister_previous_theme_sidebar() calls switch_theme( 'block-theme' ) without restoring the incoming stylesheet, leaving later test suites in the same process on block-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_Widgets_WpBlockThemeRegisterClassicSidebars --order-by=random --random-order-seed=1
  3. Run random order with seed 2:
    npm run test:php -- --filter Tests_Widgets_WpBlockThemeRegisterClassicSidebars --order-by=random --random-order-seed=2
  4. Run default order:
    npm run test:php -- --filter Tests_Widgets_WpBlockThemeRegisterClassicSidebars
  5. Confirm all three finish with OK (3 tests, 7 assertions).

Use of AI Tools

  • Cursor

Save the active stylesheet before tests that switch to block-theme 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 preserves existing behavior and has no identified blocking issues; tests were not run.

No open issues 🎉

What changed in this PR

Improves test isolation by restoring the incoming theme after classic sidebar widget tests, preventing theme changes from affecting later tests.

Changes:

  • Captures the active stylesheet during set_up().
  • Restores it in tear_down() when changed, preserving existing sidebar cleanup.
File Description
tests/​phpunit/​tests/​widgets/​wpBlockThemeRegisterClassicSidebar.php Adds per-test stylesheet capture and conditional theme restoration.

Review effort: Balanced

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