forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial tests for image rendering (WordPress#66010)
- Add initial tests for image rendering Co-authored-by: SantosGuillamot <[email protected]> Co-authored-by: cbravobernal <[email protected]>
- Loading branch information
1 parent
9c7fe4b
commit a8f0d6d
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |