Skip to content

Tests: Add unit tests for get_theme_root_uri(). - #16191

Open
rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/theme-get-theme-root-uri
Open

rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/theme-get-theme-root-uri

Conversation

@rejaulalomkhan

@rejaulalomkhan rejaulalomkhan commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/66823

Description

Adds tests for get_theme_root_uri() in tests/phpunit/tests/theme/getThemeRootUri.php.

The main cases cover the mapping added in [20016] (#17597): a registered absolute theme directory gets a content URL when it is under WP_CONTENT_DIR, and a site URL when it is elsewhere under ABSPATH.

Test Checks
test_get_theme_root_uri_with_wp_content_dir_path() A registered directory under WP_CONTENT_DIR resolves through content_url().
test_get_theme_root_uri_with_abspath() A registered directory under ABSPATH resolves through site_url().
test_theme_root_uri_filter_receives_requested_stylesheet() The theme_root_uri filter receives the requested stylesheet, and its return value is used.
test_get_theme_root_uri_default() With no arguments, the result is content_url( 'themes' ).
test_get_theme_root_uri_with_relative_root() An unregistered relative root resolves through content_url().

$wp_theme_directories is restored after each test.

Testing Instructions

npm run test:php -- tests/phpunit/tests/theme/getThemeRootUri.php
npm run test:php -- -c tests/phpunit/multisite.xml tests/phpunit/tests/theme/getThemeRootUri.php
npm run test:php -- --group themes
  • 5 tests pass on single site and multisite. The themes group (822 tests) passes in default and random order.
  • If get_theme_root_uri() passes get_stylesheet() to the filter instead of the requested theme, the filter test fails.
  • PHPCS reports no issues.

This Pull Request is for code review only. Please keep all other discussion to the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Use of AI Tools

AI assistance: Yes
Tool(s): Google Antigravity (first version); Claude Code (review follow-up)
Model(s): Gemini 3.8 Flash; Claude Opus 5.5
Used for: drafting the tests and the review changes, running the tests and the mutation check, and drafting this description. I reviewed every line and take responsibility for the change.

Cover default theme root URI, relative paths, absolute paths under WP_CONTENT_DIR and ABSPATH, and the theme_root_uri filter.

See #17597.
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rejaulalomkhan, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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

No active review issues were identified for the added get_theme_root_uri() test coverage.

No open issues 🎉

What changed in this PR

Adds dedicated PHPUnit coverage for get_theme_root_uri(), verifying theme directory URI resolution without changing production code.

Changes:

  • Tests default and relative theme root URIs.
  • Tests registered absolute theme directories within WP_CONTENT_DIR and ABSPATH.
  • Verifies that the theme_root_uri filter can override the returned URI.
File Description
tests/​phpunit/​tests/​theme/​getThemeRootUri.php Adds five tests covering URI resolution and filtering, with theme directory state restored after each test.

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom-root cases protect useful behavior: a registered directory under WP_CONTENT_DIR gets a content URL, while one elsewhere under ABSPATH gets a site URL. Please keep those cases and the directory restore. Drop the blanket remove_all_filters( 'theme_root_uri' ); the base class restores hooks. The filter test returns a constant even if Core forwards the wrong theme. Please either check the requested stylesheet argument or drop that case.

Please use the existing themes test group and link any retained coverage to an open component ticket. The historical ticket can stay as context.

AI review · gpt-6

Use the themes group, drop the blanket theme_root_uri filter removal, and
check that the filter receives the requested stylesheet. Link the tests to
the new Themes ticket and keep #17597 as context on the custom-root cases.

See #66823.
@rejaulalomkhan

Copy link
Copy Markdown
Member Author

Thanks, @lancewillett! Updated in df7a883:

  • Kept the WP_CONTENT_DIR and ABSPATH cases and the $wp_theme_directories restore.
  • Dropped remove_all_filters( 'theme_root_uri' ) from tear_down().
  • The filter test now builds its return value from the stylesheet argument and calls get_theme_root_uri( 'my-theme', 'custom-themes' ). When I changed Core to pass get_stylesheet() instead, that test failed.
  • Switched to @group themes.
  • Opened #66823 (Themes) for this coverage and linked the tests to it. #17597 stays on the two custom-root cases as context.

Single site, multisite and the themes group (default and random order) pass. PHPCS is clean.

AI assistance · Claude Code (Claude Opus 5.5)

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revised filter test catches Core passing the wrong stylesheet. Both custom-root cases also passed with the shared hook cleanup in place. I ran all five tests in randomized order on single-site and multisite.

AI review · gpt-6.2-astra

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

No active review issues are reported for the added get_theme_root_uri() unit tests.

No open issues 🎉

Review effort: Balanced

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

There are no active review issues with the added theme-root URI test coverage.

No open issues 🎉

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

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants