From 8695bd75501f8d3147d87a66500a5b831cd30467 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 24 May 2023 11:33:11 +0200 Subject: [PATCH] Post Template Block: Guard against duplicated block-supports --- phpunit/blocks/render-post-template-test.php | 73 ++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 phpunit/blocks/render-post-template-test.php diff --git a/phpunit/blocks/render-post-template-test.php b/phpunit/blocks/render-post-template-test.php new file mode 100644 index 0000000000000..13b5623cdd5dd --- /dev/null +++ b/phpunit/blocks/render-post-template-test.php @@ -0,0 +1,73 @@ +post->create_and_get( + array( + 'post_type' => 'post', + 'post_status' => 'publish', + 'post_name' => 'metaldog', + 'post_title' => 'Metal Dog', + 'post_content' => 'Metal Dog content', + 'post_excerpt' => 'Metal Dog', + ) + ); + + self::$other_post = self::factory()->post->create_and_get( + array( + 'post_type' => 'post', + 'post_status' => 'publish', + 'post_name' => 'ceilingcat', + 'post_title' => 'Ceiling Cat', + 'post_content' => 'Ceiling Cat content', + 'post_excerpt' => 'Ceiling Cat', + ) + ); + } + + public function test_rendering_post_template() { + $parsed_blocks = parse_blocks( + '' + ); + $block = new WP_Block( $parsed_blocks[0] ); + $markup = $block->render(); + + $post_id = self::$post->ID; + $other_post_id = self::$other_post->ID; + + $expected = << +
  • +

    Ceiling Cat

    +
    +

    Ceiling Cat

    +
    +
  • +
  • +

    Metal Dog

    +
    +

    Metal Dog

    +
    +
  • + +END; + $this->assertSame( + str_replace( array( "\n", "\t" ), '', $expected ), + str_replace( array( "\n", "\t" ), '', $markup ) + ); + } +}