Skip to content

Commit fd0c402

Browse files
committed
Debug
1 parent 2524386 commit fd0c402

File tree

4 files changed

+101
-8
lines changed

4 files changed

+101
-8
lines changed

.github/workflows/phpunit-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
secrets: inherit
7070
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
7171
strategy:
72-
fail-fast: false
72+
fail-fast: true
7373
matrix:
7474
event: ['${{ github.event_name }}']
7575
os: [ ubuntu-24.04 ]
@@ -205,7 +205,7 @@ jobs:
205205
secrets: inherit
206206
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
207207
strategy:
208-
fail-fast: false
208+
fail-fast: true
209209
matrix:
210210
event: ['${{ github.event_name }}']
211211
os: [ ubuntu-24.04 ]
@@ -428,7 +428,7 @@ jobs:
428428
secrets: inherit
429429
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
430430
strategy:
431-
fail-fast: false
431+
fail-fast: true
432432
matrix:
433433
event: ['${{ github.event_name }}']
434434
os: [ ubuntu-24.04 ]
@@ -495,7 +495,7 @@ jobs:
495495
secrets: inherit
496496
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
497497
strategy:
498-
fail-fast: false
498+
fail-fast: true
499499
matrix:
500500
php: [ '7.2', '7.4', '8.0', '8.4' ]
501501
db-type: [ 'mysql' ]
@@ -524,7 +524,7 @@ jobs:
524524
secrets: inherit
525525
if: ${{ ! startsWith( github.repository, 'WordPress/' ) && github.event_name == 'pull_request' }}
526526
strategy:
527-
fail-fast: false
527+
fail-fast: true
528528
matrix:
529529
php: [ '7.2', '8.4' ]
530530
db-version: [ '8.4', '11.8' ]

src/wp-includes/class-wp-block.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ public function render( $options = array() ) {
628628
*/
629629
if ( ( ! empty( $this->block_type->style_handles ) ) ) {
630630
foreach ( $this->block_type->style_handles as $style_handle ) {
631+
if ( ! empty( $GLOBALS['debug_on_demand_block_style'] ) ) {
632+
error_log( __FILE__ . ':' . __LINE__ . ' enqueue: ' . json_encode( $style_handle ) );
633+
}
631634
wp_enqueue_style( $style_handle );
632635
}
633636
}
@@ -675,6 +678,9 @@ public function render( $options = array() ) {
675678
$after_styles_queue = wp_styles()->queue;
676679
$after_scripts_queue = wp_scripts()->queue;
677680
$after_script_modules_queue = wp_script_modules()->get_queue();
681+
if ( ! empty( $GLOBALS['debug_on_demand_block_style'] ) ) {
682+
error_log( __FILE__ . ':' . __LINE__ . ' $after_styles_queue: ' . json_encode( $after_styles_queue ) );
683+
}
678684

679685
/*
680686
* As a very special case, a dynamic block may in fact include a call to wp_head() (and thus wp_enqueue_scripts()),
@@ -706,6 +712,9 @@ public function render( $options = array() ) {
706712
) {
707713
foreach ( array_diff( $after_styles_queue, $before_styles_queue ) as $handle ) {
708714
wp_dequeue_style( $handle );
715+
if ( ! empty( $GLOBALS['debug_on_demand_block_style'] ) ) {
716+
error_log( __FILE__ . ':' . __LINE__ . ' wp_dequeue_style: ' . json_encode( $handle ) );
717+
}
709718
}
710719
foreach ( array_diff( $after_scripts_queue, $before_scripts_queue ) as $handle ) {
711720
wp_dequeue_script( $handle );

src/wp-includes/script-loader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,8 @@ function wp_hoist_late_printed_styles() {
36603660
$printed_block_styles = '';
36613661
$printed_late_styles = '';
36623662
$capture_late_styles = static function () use ( &$printed_block_styles, &$printed_late_styles ) {
3663+
error_log( __FILE__ . ':' . __LINE__ . ' wp_styles()->queue: ' . json_encode( wp_styles()->queue ) );
3664+
36633665
// Gather the styles related to on-demand block enqueues.
36643666
$all_block_style_handles = array();
36653667
foreach ( WP_Block_Type_Registry::get_instance()->get_all_registered() as $block_type ) {
@@ -3682,11 +3684,14 @@ function wp_hoist_late_printed_styles() {
36823684
* to preserve the CSS cascade. The logic in this `if` statement is derived from `wp_print_styles()`.
36833685
*/
36843686
$enqueued_block_styles = array_values( array_intersect( $all_block_style_handles, wp_styles()->queue ) );
3687+
error_log( __FILE__ . ':' . __LINE__ . ' $enqueued_block_styles: ' . json_encode( $enqueued_block_styles ) );
3688+
error_log( __FILE__ . ':' . __LINE__ . ' wp_styles()->done: ' . json_encode( wp_styles()->done ) );
36853689
if ( count( $enqueued_block_styles ) > 0 ) {
36863690
ob_start();
36873691
wp_styles()->do_items( $enqueued_block_styles );
36883692
$printed_block_styles = ob_get_clean();
36893693
}
3694+
error_log( __FILE__ . ':' . __LINE__ . ' wp_styles()->done: ' . json_encode( wp_styles()->done ) );
36903695

36913696
/*
36923697
* Print all remaining styles not related to blocks. This contains a subset of the logic from
@@ -3696,6 +3701,7 @@ function wp_hoist_late_printed_styles() {
36963701
ob_start();
36973702
wp_styles()->do_footer_items();
36983703
$printed_late_styles = ob_get_clean();
3704+
error_log( __FILE__ . ':' . __LINE__ . ' wp_styles()->done: ' . json_encode( wp_styles()->done ) );
36993705
};
37003706

37013707
/*

tests/phpunit/tests/template.php

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ public function set_up() {
127127
$this->original_wp_styles = $wp_styles;
128128
$wp_scripts = null;
129129
$wp_styles = null;
130-
wp_scripts();
131-
wp_styles();
132130

133131
foreach ( self::RESTORED_CONFIG_OPTIONS as $option ) {
134132
$this->original_ini_config[ $option ] = ini_get( $option );
@@ -1647,6 +1645,9 @@ function (): void {
16471645
* @dataProvider data_wp_hoist_late_printed_styles
16481646
*/
16491647
public function test_wp_hoist_late_printed_styles( ?Closure $set_up, int $inline_size_limit, array $expected_styles ): void {
1648+
$GLOBALS['debug_on_demand_block_style'] = true; // TODO: Remove.
1649+
error_log( "\n##BEGIN DEBUG ####################################\n" );
1650+
16501651
switch_theme( 'default' );
16511652
global $wp_styles;
16521653
$wp_styles = null;
@@ -1674,8 +1675,49 @@ static function () {
16741675

16751676
// Ensure that separate core block assets get registered.
16761677
register_core_block_style_handles();
1678+
$this->assertTrue( WP_Block_Type_Registry::get_instance()->is_registered( 'core/separator' ), 'Expected the core/separator block to be registered.' );
1679+
1680+
// Ensure
1681+
$this->ensure_style_asset_file_created( 'wp-block-library', 'css/dist/block-library/style.css' );
1682+
// $handle = 'wp-block-library';
1683+
// $this->assertTrue( wp_style_is( $handle, 'registered' ), 'Expected the wp-block-library style to be registered.' );
1684+
// $dependency = wp_styles()->query( $handle );
1685+
// $relative_path = 'css/dist/block-library/style.css';
1686+
// error_log( __FILE__ . ':' . __LINE__ . ' $dependency->src === ' . $dependency->src );
1687+
// $dependency->src = includes_url( $relative_path );
1688+
// $path = ABSPATH . WPINC . '/blocks/separator/style.css';
1689+
// if ( ! file_exists( $path ) ) {
1690+
// mkdir( dirname( $path ), 0777, true );
1691+
// error_log( __FILE__ . ':' . __LINE__ . ' FILE DOES NOT EXIST: ' . $path );
1692+
// file_put_contents( $path, '/* The separator CSS */' );
1693+
// } else {
1694+
// error_log( __FILE__ . ':' . __LINE__ . ' FILE DOES EXIST: ' . $path );
1695+
// }
1696+
// wp_style_add_data( $handle, 'path', $path );
1697+
16771698
if ( wp_should_load_separate_core_block_assets() ) {
1678-
$this->assertTrue( wp_style_is( 'wp-block-separator', 'registered' ), 'Expected the wp-block-separator style to be registered.' );
1699+
$this->ensure_style_asset_file_created( 'wp-block-separator', 'blocks/separator/style.css' );
1700+
1701+
// $handle = 'wp-block-separator';
1702+
// $this->assertTrue( wp_style_is( $handle, 'registered' ), 'Expected the wp-block-separator style to be registered.' );
1703+
// $dependency = wp_styles()->query( $handle );
1704+
// error_log( __FILE__ . ':' . __LINE__ . ' $dependency->src === ' . $dependency->src );
1705+
// $relative_path = 'blocks/separator/style.css';
1706+
// $dependency->src = includes_url( $relative_path );
1707+
// $path = ABSPATH . WPINC . '/' . $relative_path;
1708+
// if ( ! file_exists( $path ) ) {
1709+
// mkdir( dirname( $path ), 0777, true );
1710+
// error_log( __FILE__ . ':' . __LINE__ . ' FILE DOES NOT EXIST: ' . $path );
1711+
// file_put_contents( $path, '/* The separator CSS */' );
1712+
// } else {
1713+
// error_log( __FILE__ . ':' . __LINE__ . ' FILE DOES EXIST: ' . $path );
1714+
// }
1715+
// wp_style_add_data( $handle, 'path', $path );
1716+
1717+
$handle = 'wp-block-separator';
1718+
$done = wp_styles()->done;
1719+
error_log( __FILE__ . ':' . __LINE__ . ": wp_print_styles($handle): " . get_echo( 'wp_print_styles', array( $handle ) ) );
1720+
wp_styles()->done = $done;
16791721
}
16801722

16811723
$this->assertFalse( wp_is_block_theme(), 'Test is not relevant to block themes (only classic themes).' );
@@ -1712,6 +1754,9 @@ static function () {
17121754
'the_content',
17131755
'<!-- wp:separator --><hr class="wp-block-separator has-alpha-channel-opacity"/><!-- /wp:separator -->'
17141756
);
1757+
if ( ! empty( $GLOBALS['debug_on_demand_block_style'] ) ) {
1758+
error_log( __FILE__ . ':' . __LINE__ . ' wp_styles()->queue: ' . json_encode( wp_styles()->queue ) );
1759+
}
17151760

17161761
// Simulate footer scripts.
17171762
$footer_output = get_echo( 'wp_footer' );
@@ -1757,6 +1802,39 @@ static function () {
17571802
$found_subset_styles,
17581803
'Expected the same styles. Snapshot: ' . self::get_array_snapshot_export( $found_styles )
17591804
);
1805+
1806+
unset( $GLOBALS['debug_on_demand_block_style'] ); // TODO: Remove.
1807+
error_log( "\n##END DEBUG ####################################\n" ); // TODO: Remove.
1808+
}
1809+
1810+
/**
1811+
* Ensures a CSS file is on the filesystem.
1812+
*
1813+
* This is needed because unit tests may be run without a build step having been done. Something similar can be seen
1814+
* elsewhere in tests for the `wp-emoji-loader.js` script:
1815+
*
1816+
* self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
1817+
*
1818+
* @param string $handle Style handle.
1819+
* @param string $relative_path Relative path to the CSS file in the includes directory.
1820+
*/
1821+
private function ensure_style_asset_file_created( string $handle, string $relative_path ) {
1822+
$this->assertTrue( wp_style_is( $handle, 'registered' ), 'Expected the wp-block-separator style to be registered.' );
1823+
$dependency = wp_styles()->query( $handle );
1824+
error_log( __FILE__ . ':' . __LINE__ . ' $dependency->src === ' . $dependency->src );
1825+
$dependency->src = includes_url( $relative_path );
1826+
$path = ABSPATH . WPINC . '/' . $relative_path;
1827+
if ( ! file_exists( $path ) ) {
1828+
$dir = dirname( $path );
1829+
if ( ! file_exists( $dir ) ) {
1830+
mkdir( $dir, 0777, true );
1831+
}
1832+
error_log( __FILE__ . ':' . __LINE__ . ' FILE DOES NOT EXIST: ' . $path );
1833+
file_put_contents( $path, "/* CSS for $handle */" );
1834+
} else {
1835+
error_log( __FILE__ . ':' . __LINE__ . ' FILE DOES EXIST: ' . $path );
1836+
}
1837+
wp_style_add_data( $handle, 'path', $path );
17601838
}
17611839

17621840
public function assertTemplateHierarchy( $url, array $expected, $message = '' ) {

0 commit comments

Comments
 (0)