Skip to content

Commit

Permalink
Expand test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
petitphp committed Sep 8, 2023
1 parent a117a89 commit 711d3af
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<!-- wp:group {"tagName":"header","layout":{"type":"flex","flexWrap":"wrap"}} -->
<header id="masthead" class="wp-block-group">
<h4>wptexturize</h4>
<p>'cause today's effort makes it worth tomorrow's "holiday"...</p>
<h4>convert_smilies</h4>
<p>:)</p>
<h4>shortcode_unautop (shortcode wrapped in paragraph)</h4>
<p>[test_shortcode]_unautop</p>
<h4>wp_filter_content_tags</h4>
<img width="408" height="287" src="https://placekitten.com/408/287">
<h4>do_shortcode</h4>
<!-- wp:shortcode -->
[test_shortcode]
[test_shortcode]_shortcode_block
<!-- /wp:shortcode -->
<h4>$wp_embed->autoembed</h4>
https://youtube.com/shorts/_H4vwkGvWjE?feature=share
</header>
<!-- /wp:group -->
64 changes: 61 additions & 3 deletions tests/phpunit/tests/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ public function test_wp_generate_block_templates_export_file() {
}

/**
* Should expand shortcodes in block template part.
* Should run `do_shortcode` in block template part.
*
* @ticket 56780
* @covers ::block_template_part
*/
public function test_block_template_part_render_shortcode() {
public function test_block_template_part_do_shortcode() {
add_shortcode( self::TEST_SHORTCODE, array( $this, 'render_test_shortcode' ) );

ob_start();
Expand All @@ -358,7 +358,65 @@ public function test_block_template_part_render_shortcode() {

remove_shortcode( self::TEST_SHORTCODE );

$this->assertStringContainsString( 'test_shortcode_rendered', $generated_content );
$this->assertStringContainsString( 'test_shortcode_rendered_unautop', $generated_content, 'Should render shortcodes in paragraph tags' );
$this->assertStringContainsString( 'test_shortcode_rendered_shortcode_block', $generated_content, 'Should render shortcodes in shortcode blocks' );
}

/**
* Should run `wp_filter_content_tags` in block template part.
*
* @ticket 56780
* @covers ::block_template_part
*/
public function test_block_template_part_wp_filter_content_tags() {
ob_start();
block_template_part( 'template-part-shortcode' );
$generated_content = ob_get_clean();

$this->assertStringContainsString( '<img decoding="async" loading="lazy" width="408" height="287" src="https://placekitten.com/408/287">', $generated_content );
}

/**
* Should run `convert_smilies` in block template part.
*
* @ticket 56780
* @covers ::block_template_part
*/
public function test_block_template_part_convert_smilies() {
ob_start();
block_template_part( 'template-part-shortcode' );
$generated_content = ob_get_clean();

$this->assertStringContainsString( '🙂', $generated_content );
}

/**
* Should run `WP_Embed::autoembed` in block template part.
*
* @ticket 56780
* @covers ::block_template_part
*/
public function test_block_template_part_autoembed() {
ob_start();
block_template_part( 'template-part-shortcode' );
$generated_content = ob_get_clean();

$this->assertStringContainsString( '<iframe', $generated_content, 'Should replace Youtube link with an iframe' );
$this->assertStringContainsString( 'src="https://www.youtube.com/embed/_H4vwkGvWjE', $generated_content, 'Should use the correct src for the iframe' );
}

/**
* Should run `wptexturize` in block template part.
*
* @ticket 56780
* @covers ::block_template_part
*/
public function test_block_template_part_wptexturize() {
ob_start();
block_template_part( 'template-part-shortcode' );
$generated_content = ob_get_clean();

$this->assertStringContainsString( '&#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221;&#8230;', $generated_content );
}

public function render_test_shortcode() {
Expand Down

0 comments on commit 711d3af

Please sign in to comment.