From cfc2e27f423d9cfebc4caa56778a32ee0b9617e7 Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Tue, 24 Nov 2026 09:41:34 +0600 Subject: [PATCH 1/2] Tests: Add unit tests for get_theme_root_uri(). Cover default theme root URI, relative paths, absolute paths under WP_CONTENT_DIR and ABSPATH, and the theme_root_uri filter. See #17597. --- tests/phpunit/tests/theme/getThemeRootUri.php | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/phpunit/tests/theme/getThemeRootUri.php diff --git a/tests/phpunit/tests/theme/getThemeRootUri.php b/tests/phpunit/tests/theme/getThemeRootUri.php new file mode 100644 index 0000000000000..41f0b6c9b9944 --- /dev/null +++ b/tests/phpunit/tests/theme/getThemeRootUri.php @@ -0,0 +1,114 @@ +old_wp_theme_directories = $wp_theme_directories; + } + + /** + * Clean up after each test. + */ + public function tear_down() { + global $wp_theme_directories; + $wp_theme_directories = $this->old_wp_theme_directories; + remove_all_filters( 'theme_root_uri' ); + parent::tear_down(); + } + + /** + * Tests that get_theme_root_uri() defaults to content_url( 'themes' ) when called without arguments. + * + * @ticket 17597 + */ + public function test_get_theme_root_uri_default() { + $expected = content_url( 'themes' ); + $actual = get_theme_root_uri(); + + $this->assertSame( $expected, $actual, 'Default theme root URI should match content_url( "themes" ).' ); + } + + /** + * Tests that get_theme_root_uri() handles relative theme roots. + * + * @ticket 17597 + */ + public function test_get_theme_root_uri_with_relative_root() { + $expected = content_url( 'custom-themes' ); + $actual = get_theme_root_uri( 'default', 'custom-themes' ); + + $this->assertSame( $expected, $actual, 'Relative theme root should resolve via content_url().' ); + } + + /** + * Tests that get_theme_root_uri() resolves absolute theme root within WP_CONTENT_DIR. + * + * @ticket 17597 + */ + public function test_get_theme_root_uri_with_wp_content_dir_path() { + global $wp_theme_directories; + + $custom_dir = WP_CONTENT_DIR . '/my-themes'; + $wp_theme_directories = (array) $wp_theme_directories; + $wp_theme_directories[] = $custom_dir; + + $expected = content_url( '/my-themes' ); + $actual = get_theme_root_uri( 'my-theme', $custom_dir ); + + $this->assertSame( $expected, $actual, 'Theme root within WP_CONTENT_DIR should resolve relative to content_url().' ); + } + + /** + * Tests that get_theme_root_uri() resolves absolute theme root within ABSPATH. + * + * @ticket 17597 + */ + public function test_get_theme_root_uri_with_abspath() { + global $wp_theme_directories; + + $custom_dir = ABSPATH . 'custom-themes'; + $wp_theme_directories = (array) $wp_theme_directories; + $wp_theme_directories[] = $custom_dir; + + $expected = site_url( 'custom-themes' ); + $actual = get_theme_root_uri( 'my-theme', $custom_dir ); + + $this->assertSame( $expected, $actual, 'Theme root within ABSPATH should resolve relative to site_url().' ); + } + + /** + * Tests that theme_root_uri filter modifies the returned URI. + * + * @ticket 17597 + */ + public function test_theme_root_uri_filter() { + add_filter( + 'theme_root_uri', + static function ( $theme_root_uri, $siteurl, $stylesheet_or_template ) { + return 'https://cdn.example.com/themes'; + }, + 10, + 3 + ); + + $this->assertSame( 'https://cdn.example.com/themes', get_theme_root_uri(), 'Filter should modify returned theme root URI.' ); + } +} From df7a883a156d9654baad9a5eb6c83af21271d623 Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Wed, 25 Nov 2026 23:29:59 +0600 Subject: [PATCH 2/2] Tests: Address review feedback on get_theme_root_uri() tests. 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. --- tests/phpunit/tests/theme/getThemeRootUri.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/tests/theme/getThemeRootUri.php b/tests/phpunit/tests/theme/getThemeRootUri.php index 41f0b6c9b9944..bf2e2960c4053 100644 --- a/tests/phpunit/tests/theme/getThemeRootUri.php +++ b/tests/phpunit/tests/theme/getThemeRootUri.php @@ -2,7 +2,7 @@ /** * Test get_theme_root_uri(). * - * @group theme + * @group themes * * @covers ::get_theme_root_uri */ @@ -30,14 +30,13 @@ public function set_up() { public function tear_down() { global $wp_theme_directories; $wp_theme_directories = $this->old_wp_theme_directories; - remove_all_filters( 'theme_root_uri' ); parent::tear_down(); } /** * Tests that get_theme_root_uri() defaults to content_url( 'themes' ) when called without arguments. * - * @ticket 17597 + * @ticket 66823 */ public function test_get_theme_root_uri_default() { $expected = content_url( 'themes' ); @@ -49,7 +48,7 @@ public function test_get_theme_root_uri_default() { /** * Tests that get_theme_root_uri() handles relative theme roots. * - * @ticket 17597 + * @ticket 66823 */ public function test_get_theme_root_uri_with_relative_root() { $expected = content_url( 'custom-themes' ); @@ -62,6 +61,7 @@ public function test_get_theme_root_uri_with_relative_root() { * Tests that get_theme_root_uri() resolves absolute theme root within WP_CONTENT_DIR. * * @ticket 17597 + * @ticket 66823 */ public function test_get_theme_root_uri_with_wp_content_dir_path() { global $wp_theme_directories; @@ -80,6 +80,7 @@ public function test_get_theme_root_uri_with_wp_content_dir_path() { * Tests that get_theme_root_uri() resolves absolute theme root within ABSPATH. * * @ticket 17597 + * @ticket 66823 */ public function test_get_theme_root_uri_with_abspath() { global $wp_theme_directories; @@ -95,20 +96,24 @@ public function test_get_theme_root_uri_with_abspath() { } /** - * Tests that theme_root_uri filter modifies the returned URI. + * Tests that the theme_root_uri filter receives the requested stylesheet and its return value is used. * - * @ticket 17597 + * @ticket 66823 */ - public function test_theme_root_uri_filter() { + public function test_theme_root_uri_filter_receives_requested_stylesheet() { add_filter( 'theme_root_uri', static function ( $theme_root_uri, $siteurl, $stylesheet_or_template ) { - return 'https://cdn.example.com/themes'; + return 'https://cdn.example.com/' . $stylesheet_or_template; }, 10, 3 ); - $this->assertSame( 'https://cdn.example.com/themes', get_theme_root_uri(), 'Filter should modify returned theme root URI.' ); + $this->assertSame( + 'https://cdn.example.com/my-theme', + get_theme_root_uri( 'my-theme', 'custom-themes' ), + 'The filter should receive the requested stylesheet, and its return value should be used.' + ); } }