Skip to content

Tests: Restore original theme in WP_Block_Templates_UnitTestCase::tear_down() - #14813

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

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

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65893

What

Restores the active theme stylesheet in tear_down() within WP_Block_Templates_UnitTestCase in tests/phpunit/tests/block-templates/base.php.

Why

Classes extending WP_Block_Templates_UnitTestCase call switch_theme( 'block-theme' ) in set_up() and never restore the incoming stylesheet. That leaves 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 -- --test-suffix .php tests/phpunit/tests/block-templates --order-by=random --random-order-seed=1
  3. Run random order with seed 2:
    npm run test:php -- --test-suffix .php tests/phpunit/tests/block-templates --order-by=random --random-order-seed=2
  4. Run default order:
    npm run test:php -- --test-suffix .php tests/phpunit/tests/block-templates
  5. Confirm all three finish with OK (83 tests, 214 assertions).

Use of AI Tools

  • Cursor

…r_down().

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

The focused change preserves existing cleanup behavior and addresses theme leakage without any identified blocking issues.

No open issues 🎉

What changed in this PR

This PR improves block-template test isolation by restoring the incoming theme after each test, preventing theme changes from affecting later test suites.

Changes:

  • Records the original stylesheet during set_up().
  • Restores it in tear_down() when changed, before invoking parent cleanup.
File Description
tests/​phpunit/​tests/​block-templates/​base.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