Skip to content

Tests: Restore original theme after general template tests. - #14814

Draft
shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-general-template
Draft

shail-mehta wants to merge 1 commit into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-general-template

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65893

What

Restores the active theme stylesheet in tear_down() within Tests_General_Template in tests/phpunit/tests/general/template.php.

Why

Tests_General_Template::set_up() calls switch_theme( 'default' ) without restoring the incoming stylesheet, leaving later test suites in the same process on the default 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 -- tests/phpunit/tests/general/template.php --order-by=random --random-order-seed=1
  3. Run random order with seed 2:
    npm run test:php -- tests/phpunit/tests/general/template.php --order-by=random --random-order-seed=2
  4. Run default order:
    npm run test:php -- tests/phpunit/tests/general/template.php
  5. Confirm all three finish with OK (36 tests, 80 assertions).

Use of AI Tools

  • Cursor

Save the active stylesheet before switching to the default theme fixture 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 focused lifecycle cleanup follows existing test-suite patterns and has no identified blocking issues; tests were not run.

No open issues 🎉

What changed in this PR

This PR improves isolation in Tests_General_Template by restoring the incoming theme after each test, preventing theme changes from affecting later tests in the same process.

Changes:

  • Captures the original stylesheet before switching to the default theme.
  • Restores it during teardown only when the stylesheet has changed.
File Description
tests/​phpunit/​tests/​general/​template.php Saves and restores the active stylesheet around each test.

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