From ea33470e212c28ca0368b3baa087a28896896290 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Mon, 23 Sep 2024 21:13:49 +0530 Subject: [PATCH] fix : checks for inner blocks, cssClassName issue. --- tests/unit/CoreQuoteTest.php | 39 ++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index c15516a9..c91792f5 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -35,6 +35,13 @@ public function tearDown(): void { public function query(): string { return ' fragment CoreQuoteBlockFragment on CoreQuote { + innerBlocks { + ... on CoreParagraph{ + attributes { + content + } + } + } attributes { anchor backgroundColor @@ -106,27 +113,37 @@ public function test_retrieve_core_quote_fields_and_attributes(): void { $this->assertArrayNotHasKey( 'errors', $actual, 'There should not be any errors' ); $this->assertArrayHasKey( 'data', $actual, 'The data key should be present' ); $this->assertArrayHasKey( 'post', $actual['data'], 'The post key should be present' ); + $this->assertEquals( $this->post_id, $actual['data']['post']['databaseId'], 'The post ID should match' ); + $this->assertEquals( 1, count( $actual['data']['post']['editorBlocks'] ), 'There should be only one block' ); $block = $actual['data']['post']['editorBlocks'][0]; + $this->assertNotEmpty( $block['apiVersion'], 'The apiVersion should be present' ); $this->assertEquals( 'text', $block['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' ); $this->assertNotEmpty( $block['clientId'], 'The clientId should be present' ); + $this->assertEquals( $block['cssClassNames'][0], 'custom-quote-class' ); + $this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' ); $this->assertEquals( 'core/quote', $block['name'], 'The block name should be core/quote' ); $this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' ); $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' ); - // Verify the attributes. + // Verify the attributes.. + + // WordPress 6.4+ adds layout styles, so `cssClassName` needs to be checked separately. + $this->assertStringContainsString( 'wp-block-quote', $block['attributes']['cssClassName'] ); + $this->assertStringContainsString( 'custom-quote-class', $block['attributes']['cssClassName'] ); + unset( $block['attributes']['cssClassName'] ); + $this->assertEquals( [ 'anchor' => null, 'backgroundColor' => null, 'citation' => 'Author Name', 'className' => 'custom-quote-class', - 'cssClassName' => 'wp-block-quote custom-quote-class', 'fontFamily' => null, 'fontSize' => null, 'gradient' => null, @@ -142,14 +159,14 @@ public function test_retrieve_core_quote_fields_and_attributes(): void { /** * Test case for retrieving core quote block untested attributes. * - * Covers : 'anchor', 'backgroundColor', 'fontFamily', 'fontSize', 'gradient', 'lock', 'style' and 'textColor'. + * Covers : 'anchor', 'backgroundColor', 'fontFamily', 'fontSize', 'gradient', 'lock', 'style', 'textColor' and 'value'. */ - public function test_retrieve_core_quote_attributes(): void { + public function test_retrieve_core_quote_additional_attributes(): void { $block_content = ' -
-

Quote, with heading color

- Citation
+
+

Sample Quote

+ Citation
'; @@ -171,14 +188,20 @@ public function test_retrieve_core_quote_attributes(): void { $this->assertArrayNotHasKey( 'errors', $actual, 'There should not be any errors' ); $this->assertArrayHasKey( 'data', $actual, 'The data key should be present' ); $this->assertArrayHasKey( 'post', $actual['data'], 'The post key should be present' ); + $this->assertEquals( $this->post_id, $actual['data']['post']['databaseId'], 'The post ID should match' ); // Verify the block data. $block = $actual['data']['post']['editorBlocks'][0]; + $this->assertNotEmpty( $block['apiVersion'], 'The apiVersion should be present' ); $this->assertEquals( 'text', $block['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' ); $this->assertNotEmpty( $block['clientId'], 'The clientId should be present' ); + $this->assertNotEmpty( $block['innerBlocks'], 'There should be no inner blocks' ); + $this->assertEquals( 1, count( $block['innerBlocks'] ), 'There should be only one inner block' ); + $this->assertEquals( 'core/paragraph', $block['innerBlocks'][0]['name'], 'The inner block name should be core/paragraph' ); + $this->assertEquals( 'core/quote', $block['name'], 'The block name should be core/quote' ); $this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' ); $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' ); @@ -213,7 +236,7 @@ public function test_retrieve_core_quote_attributes(): void { ] ), 'textColor' => 'vivid-red', // Previously untested. - 'value' => '', + 'value' => '

Sample Quote

', // Previously untested. ], $block['attributes'], );