From ea3ab2af3ded8d50775239d173b03ff5de4eecda Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:33:03 +0530 Subject: [PATCH] temp : split up test for layout and textAlign --- tests/unit/CoreQuoteTest.php | 134 +++++++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 6 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index c336bed7..11ff719d 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -247,13 +247,135 @@ public function test_retrieve_core_quote_additional_attributes(): void { /** - * Test case for retrieving core quote block untested attributes. - * - * Covers : 'layout' and 'textAlign'. + * Test case for retrieving core quote block layout attribute. */ - public function test_retrieve_core_quote_layout_text_align_attributes(): void { - // layout and textAlign are only supported in WP 6.5+. + public function test_retrieve_core_quote_layout_attributes(): void { + // layout are only supported in WP 6.5+. if ( ! is_wp_version_compatible( '6.5' ) ) { + $this->markTestSkipped( 'This test requires WP 6.5 or higher.' ); + } + $block_content = ' + +
+

Sample Quote

+ Citation
+ + '; + + // Update the post content with the block content. + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $query = ' + fragment CoreQuoteBlockFragment on CoreQuote { + innerBlocks { + ... on CoreParagraph{ + attributes { + content + } + } + } + attributes { + anchor + backgroundColor + citation + className + cssClassName + fontFamily + fontSize + gradient + layout + lock + # metadata + style + textColor + value + } + } + + query Post( $id: ID! ) { + post(id: $id, idType: DATABASE_ID) { + databaseId + editorBlocks { + apiVersion + blockEditorCategoryName + clientId + cssClassNames + innerBlocks { + name + } + isDynamic + name + parentClientId + renderedHtml + ...CoreQuoteBlockFragment + } + } + } + '; + $variables = [ + 'id' => $this->post_id, + ]; + + $actual = graphql( compact( 'query', 'variables' ) ); + error_log( print_r( $actual, true ) ); + + $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' ); + + unset( $block['attributes']['citation'] ); // Tested above. + unset( $block['attributes']['className'] ); // Tested above. + unset( $block['attributes']['cssClassName'] ); // Tested above. + + unset( $block['attributes']['anchor'] ); // Tested above. + unset( $block['attributes']['backgroundColor'] ); // Tested above. + unset( $block['attributes']['fontFamily'] ); // Tested above. + unset( $block['attributes']['fontSize'] ); // Tested above. + unset( $block['attributes']['gradient'] ); // Tested above. + unset( $block['attributes']['lock'] ); // Tested above. + unset( $block['attributes']['style'] ); // Tested above. + unset( $block['attributes']['textColor'] ); // Tested above. + + + // Verify the attributes. + $this->assertEquals( + [ + 'value' => '

Sample Quote

', + 'textAlign' => 'center', // Previously untested. + ], + $block['attributes'], + ); + } + + + /** + * Test case for retrieving core quote block 'textAlign' attribute. + */ + public function test_retrieve_core_quote_text_align_attributes(): void { + // textAlign is only supported in WP 6.6+. + if ( ! is_wp_version_compatible( '6.6' ) ) { $this->markTestSkipped( 'This test requires WP 6.6 or higher.' ); } $block_content = ' @@ -372,7 +494,7 @@ className 'flexWrap' => 'nowrap', ] ), - 'textAlign' => 'center', // Previously untested. + 'textAlign' => 'center', ], $block['attributes'], );