From a8f0d6d8c9e2ffe841c02f74c68213c11ae6ca30 Mon Sep 17 00:00:00 2001 From: Mario Santos <34552881+SantosGuillamot@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:26:59 +0200 Subject: [PATCH] Add initial tests for image rendering (#66010) - Add initial tests for image rendering Co-authored-by: SantosGuillamot Co-authored-by: cbravobernal --- phpunit/blocks/render-block-image-test.php | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 phpunit/blocks/render-block-image-test.php diff --git a/phpunit/blocks/render-block-image-test.php b/phpunit/blocks/render-block-image-test.php new file mode 100644 index 0000000000000..fe39aee8c50b9 --- /dev/null +++ b/phpunit/blocks/render-block-image-test.php @@ -0,0 +1,62 @@ +'; + $parsed_blocks = parse_blocks( + '' + ); + $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 = '
'; + $parsed_blocks = parse_blocks( + '' + ); + $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 = '
'; + $parsed_blocks = parse_blocks( + '' + ); + $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 ); + } +}