Skip to content

Commit

Permalink
test : post_content_inner_blocks edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
Ta5r committed Dec 17, 2024
1 parent 2354106 commit b191c59
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/unit/ContentBlocksResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ function () use ( $mock_template ) {

// Resolve blocks as nested
$resolved_blocks = $this->instance->resolve_content_blocks( $post_model, [ 'flat' => false ] );
error_log( print_r( $resolved_blocks, true ) );

// Assertions
$this->assertCount( 1, $resolved_blocks, 'There should be only one top-level block (template-part).' );
Expand All @@ -406,4 +405,50 @@ function () use ( $mock_template ) {
$this->assertEquals( 'core/heading', $resolved_flat_blocks[2]['blockName'] );
}

/**
* Tests behavior when post-content block is empty.
*/
public function test_resolve_content_blocks_resolves_post_content_inner_blocks_with_empty_post_content_block() {
error_log( 'test_resolve_content_blocks_resolves_post_content_inner_blocks_with_empty_post_content_block' );
$empty_post_content = '<!-- wp:post-content /-->';

wp_update_post([
'ID' => $this->post_id,
'post_content' => $empty_post_content,
]);

$post_model = new Post( get_post( $this->post_id ) );

$resolved_blocks = $this->instance->resolve_content_blocks( $post_model, [ 'flat' => false ] );
error_log( print_r( $resolved_blocks, true ) );

$this->assertCount( 1, $resolved_blocks, 'There should be one top-level block.' );
$this->assertEquals( 'core/post-content', $resolved_blocks[0]['blockName'] );
$this->assertEmpty( $resolved_blocks[0]['innerBlocks'], 'The post-content block should have no inner blocks.' );
}

/**
* Tests behavior when no post-content block exists.
*/
public function test_resolve_content_blocks_resolves_post_content_inner_blocks_with_no_post_content_block() {
error_log( 'test_resolve_content_blocks_resolves_post_content_inner_blocks_with_no_post_content_block' );
$post_content = '
<!-- wp:paragraph -->
<p>This is just a paragraph block.</p>
<!-- /wp:paragraph -->
';

wp_update_post([
'ID' => $this->post_id,
'post_content' => $post_content,
]);

$post_model = new Post( get_post( $this->post_id ) );

$resolved_blocks = $this->instance->resolve_content_blocks( $post_model, [ 'flat' => true ] );
error_log( print_r( $resolved_blocks, true ) );

$this->assertCount( 1, $resolved_blocks, 'There should only be one block.' );
$this->assertEquals( 'core/paragraph', $resolved_blocks[0]['blockName'] );
}
}

0 comments on commit b191c59

Please sign in to comment.