Skip to content

Commit 2216f14

Browse files
committed
Unimprove ensure_style_asset_file_created helper
Reverts part of 9f816a3 It turns out the depenency src is empty when a build hasn't been done
1 parent 885bddd commit 2216f14

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

tests/phpunit/tests/template.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,9 +1707,12 @@ static function () {
17071707
$this->assertTrue( WP_Block_Type_Registry::get_instance()->is_registered( 'core/separator' ), 'Expected the core/separator block to be registered.' );
17081708

17091709
// Ensure stylesheet files exist on the filesystem since a build may not have been done.
1710-
$this->ensure_style_asset_file_created( 'wp-block-library' );
1710+
$this->ensure_style_asset_file_created(
1711+
'wp-block-library',
1712+
wp_should_load_separate_core_block_assets() ? 'css/dist/block-library/common.css' : 'css/dist/block-library/style.css'
1713+
);
17111714
if ( wp_should_load_separate_core_block_assets() ) {
1712-
$this->ensure_style_asset_file_created( 'wp-block-separator' );
1715+
$this->ensure_style_asset_file_created( 'wp-block-separator', 'blocks/separator/style.css' );
17131716
}
17141717
$this->assertFalse( wp_is_block_theme(), 'Test is not relevant to block themes (only classic themes).' );
17151718

@@ -1812,22 +1815,16 @@ static function () {
18121815
*
18131816
* self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
18141817
*
1815-
* @param string $handle Style handle.
1818+
* @param string $handle Style handle.
1819+
* @param string $relative_path Relative path to the CSS file in wp-includes.
18161820
*
18171821
* @throws Exception If the supplied style handle is not registered as expected.
18181822
*/
1819-
private function ensure_style_asset_file_created( string $handle ) {
1823+
private function ensure_style_asset_file_created( string $handle, string $relative_path ) {
18201824
$dependency = wp_styles()->query( $handle );
18211825
if ( ! $dependency ) {
18221826
throw new Exception( "The stylesheet for $handle is not registered." );
18231827
}
1824-
if ( ! $dependency->src ) {
1825-
throw new Exception( "The stylesheet URL for $handle is empty." );
1826-
}
1827-
if ( ! str_contains( $dependency->src, '/wp-includes/' ) ) {
1828-
throw new Exception( "Expected the stylesheet URL for $handle to be in the includes directory, but got {$dependency->src}" );
1829-
}
1830-
$relative_path = preg_replace( '#^.*?/wp-includes/#', '/', $dependency->src );
18311828
$dependency->src = includes_url( $relative_path );
18321829
$path = ABSPATH . WPINC . '/' . $relative_path;
18331830
if ( ! file_exists( $path ) ) {

0 commit comments

Comments
 (0)