Skip to content

Commit

Permalink
Normalize the HTML to replace wp_unique_id in certain classnames with 1
Browse files Browse the repository at this point in the history
This relates to a change in the Columns block that added layout support.
See WordPress/gutenberg#37360 (comment).
Blocks that opt into layout support are gifted generated classnames of wp_unique_id( 'wp-container-' ).
One possible approach is to update test_do_block_output in Tests_Blocks_Render to swap the id for something
we expect. It's how Gutenberg approaches it when testing generated classnames in elements support.
  • Loading branch information
adamziel committed Apr 12, 2022
1 parent c50d107 commit 219118a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/phpunit/tests/blocks/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,16 @@ public function test_do_block_output( $html_filename, $server_html_filename ) {
}
}

$html = do_blocks( self::strip_r( file_get_contents( $html_path ) ) );
$expected_html = self::strip_r( file_get_contents( $server_html_path ) );
$html = do_blocks( self::strip_r( file_get_contents( $html_path ) ) );
// If blocks opt into Gutenberg's layout implementation
// the container will receive an added classname of `wp_unique_id( 'wp-container-' )`
// so we need to normalize the random id.
$normalized_html = preg_replace( '/wp-container-\d+/', 'wp-container-1', $html );
$expected_html = self::strip_r( file_get_contents( $server_html_path ) );

$this->assertSame(
$expected_html,
$html,
$normalized_html,
"File '$html_path' does not match expected value"
);
}
Expand Down

0 comments on commit 219118a

Please sign in to comment.