From 2fad2993877b64ae6d91e1b42e2847092c3233e4 Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Thu, 19 Dec 2019 18:48:49 +0000 Subject: [PATCH] Editor: Add unit tests for v5.3.1 block serialization functions r46896 was intended to have included unit tests for the block serialization functions added as part of the changeset. Props: @aduth. Fixes: #49048 git-svn-id: https://develop.svn.wordpress.org/trunk@46997 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/blocks/serialization.php | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/phpunit/tests/blocks/serialization.php diff --git a/tests/phpunit/tests/blocks/serialization.php b/tests/phpunit/tests/blocks/serialization.php new file mode 100644 index 0000000000..48ee778b82 --- /dev/null +++ b/tests/phpunit/tests/blocks/serialization.php @@ -0,0 +1,60 @@ +assertEquals( $expected, $actual ); + } + + function data_serialize_identity_from_parsed() { + return array( + // Void block. + array( '' ), + + // Freeform content ($block_name = null). + array( 'Example.' ), + + // Block with content. + array( 'Example.' ), + + // Block with attributes. + array( '' ), + + // Block with inner blocks. + array( "Example.\n\nExample.\n\n" ), + + // Block with attribute values that may conflict with HTML comment. + array( '' ), + ); + } + + function test_serialized_block_name() { + $this->assertEquals( null, strip_core_block_namespace( null ) ); + $this->assertEquals( 'example', strip_core_block_namespace( 'example' ) ); + $this->assertEquals( 'example', strip_core_block_namespace( 'core/example' ) ); + $this->assertEquals( 'plugin/example', strip_core_block_namespace( 'plugin/example' ) ); + } + +}