Skip to content

Commit

Permalink
Add initial tests for image rendering (#66010)
Browse files Browse the repository at this point in the history
- Add initial tests for image rendering

Co-authored-by: SantosGuillamot <[email protected]>
Co-authored-by: cbravobernal <[email protected]>
  • Loading branch information
3 people authored Oct 15, 2024
1 parent d655af6 commit 9262906
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions phpunit/blocks/render-block-image-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Image block rendering tests.
*
* @package WordPress
* @subpackage Blocks
*/

/**
* Tests for the Image block.
*
* @group blocks
*/
class Tests_Blocks_Render_Image extends WP_UnitTestCase {
/**
* @covers ::render_block_core_image
*/
public function test_should_render_block_core_image_when_src_is_defined() {
$attributes = array();
$content = '<figure class="wp-block-image"><img src="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2021/04/canola.jpg" aria-label="test render"/></figure>';
$parsed_blocks = parse_blocks(
'<!-- wp:image -->'
);
$parsed_block = $parsed_blocks[0];
$block = new WP_Block( $parsed_block );

$rendered_block = gutenberg_render_block_core_image( $attributes, $content, $block );
$this->assertStringContainsString( 'aria-label="test render"', $rendered_block );
}

/**
* @covers ::render_block_core_image
*/
public function test_should_not_render_block_core_image_when_src_is_not_defined() {
$attributes = array();
$content = '<figure class="wp-block-image"><img /></figure>';
$parsed_blocks = parse_blocks(
'<!-- wp:image -->'
);
$parsed_block = $parsed_blocks[0];
$block = new WP_Block( $parsed_block );

$rendered_block = gutenberg_render_block_core_image( $attributes, $content, $block );
$this->assertEquals( '', $rendered_block );
}

/**
* @covers ::render_block_core_image
*/
public function test_should_not_render_block_core_image_when_src_is_empty_string() {
$attributes = array();
$content = '<figure class="wp-block-image"><img src=""/></figure>';
$parsed_blocks = parse_blocks(
'<!-- wp:image -->'
);
$parsed_block = $parsed_blocks[0];
$block = new WP_Block( $parsed_block );

$rendered_block = gutenberg_render_block_core_image( $attributes, $content, $block );
$this->assertEquals( '', $rendered_block );
}
}

0 comments on commit 9262906

Please sign in to comment.