Skip to content

Tests: Restore original theme after block template tests - #14817

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

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

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65893

What

Restores the active theme stylesheet in tear_down() within:

  • Tests_Block_Template in tests/phpunit/tests/block-template.php
  • Tests_Block_Template_Utils in tests/phpunit/tests/block-template-utils.php

Why

Both classes call switch_theme( 'block-theme' ) in set_up() 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_Block_Template(_Utils)?::/' --order-by=random --random-order-seed=1
  3. Run random order with seed 2:
    npm run test:php -- --filter '/Tests_Block_Template(_Utils)?::/' --order-by=random --random-order-seed=2
  4. Run default order:
    npm run test:php -- --filter '/Tests_Block_Template(_Utils)?::/'
  5. Confirm runs finish with OK (55 tests, 117 assertions).

Use of AI Tools

  • Cursor

Save the active stylesheet before switching to the block-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

Both changes use the established theme-restoration pattern, preserve teardown ordering, and have no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR improves isolation between block template tests by restoring the active theme after each test.

Changes:

  • Saves the incoming stylesheet before switching to the test theme in both fixtures.
  • Restores that stylesheet when needed during teardown, before parent cleanup.
File Description
tests/​phpunit/​tests/​block-template.php Saves and restores the original stylesheet around block template tests.
tests/​phpunit/​tests/​block-template-utils.php Adds equivalent theme restoration to block template utility tests.

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