Skip to content

Tests: Restore original theme after Customize Manager tests - #14818

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

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

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Trac ticket: #65893

What

Restores the active theme stylesheet in tear_down() within Tests_WP_Customize_Manager in tests/phpunit/tests/customize/manager.php.

Why

test_constructor_deferred_changeset_uuid() calls switch_theme( 'twentyseventeen' ) 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 the contaminating test:
    npm run test:php -- --filter test_constructor_deferred_changeset_uuid
  3. Run random order with seed 1:
    npm run test:php -- --test-suffix .php tests/phpunit/tests/customize --order-by=random --random-order-seed=1
  4. Run random order with seed 2:
    npm run test:php -- --test-suffix .php tests/phpunit/tests/customize --order-by=random --random-order-seed=2
  5. Run default order:
    npm run test:php -- --test-suffix .php tests/phpunit/tests/customize

Use of AI Tools

  • Cursor

Save the active stylesheet before tests that switch themes 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 narrowly scoped cleanup fits the existing test lifecycle, with no blocking issues identified in static review.

No open issues 🎉

What changed in this PR

This PR improves Customize Manager test isolation by restoring the incoming theme after 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 when the stylesheet has changed.
File Description
tests/​phpunit/​tests/​customize/​manager.php Saves and conditionally restores the active theme stylesheet.

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