Skip to content

Tests: Restore original theme after template path allowed tests - #14829

Draft
shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-wp-is-template-path-allowed
Draft

shail-mehta wants to merge 2 commits into
WordPress:trunkfrom
shail-mehta:tests/restore-theme-wp-is-template-path-allowed

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65893

What

Restores the active theme stylesheet in tear_down() within Tests_Theme_wpIsTemplatePathAllowed in tests/phpunit/tests/theme/wpIsTemplatePathAllowed.php.

Why

Several tests call switch_theme() (for example to default or child themes) 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_Theme_wpIsTemplatePathAllowed --order-by=random --random-order-seed=1
  3. Run random order with seed 2:
    npm run test:php -- --filter Tests_Theme_wpIsTemplatePathAllowed --order-by=random --random-order-seed=2
  4. Run default order:
    npm run test:php -- --filter Tests_Theme_wpIsTemplatePathAllowed
  5. Confirm all three finish with OK.

Use of AI Tools

  • Cursor

Save and restore the active stylesheet around Tests_Theme_wpIsTemplatePathAllowed so switch_theme() calls do not leak into later suites.

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 cleanup follows established theme-test patterns and has no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR improves theme-test isolation by restoring the stylesheet active before each test, preventing theme changes from affecting later tests in the same process.

Changes:

  • Captures the original stylesheet during set_up().
  • Restores it during tear_down() only if it changed, preserving parent lifecycle calls.
  • Adds the Trac ticket annotation for #65893.
File Description
tests/​phpunit/​tests/​theme/​wpIsTemplatePathAllowed.php Adds stylesheet capture and restoration to isolate theme-switching tests.

Review effort: Balanced

@shail-mehta shail-mehta changed the title Tests/restore theme wp is template path allowed Tests: Restore original theme after template path allowed tests Oct 25, 2026
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