From 6d978157dcdd5ad8fac3a4e8182b5e1bed5b1e39 Mon Sep 17 00:00:00 2001 From: DDEV User Date: Sat, 21 Sep 2024 18:55:16 +0000 Subject: [PATCH 01/17] tests: add tests for `CoreQuote` This was reset and cherrypicked to undo the bad merges/rebases Co-authored-by: Ta5r --- tests/unit/CoreQuoteTest.php | 245 +++++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 tests/unit/CoreQuoteTest.php diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php new file mode 100644 index 00000000..6024bf26 --- /dev/null +++ b/tests/unit/CoreQuoteTest.php @@ -0,0 +1,245 @@ +post_id = wp_insert_post( + [ + 'post_title' => 'Post with Quote', + 'post_content' => '', + 'post_status' => 'publish', + ] + ); + + \WPGraphQL::clear_schema(); + } + + public function tearDown(): void { + parent::tearDown(); + + wp_delete_post( $this->post_id, true ); + + \WPGraphQL::clear_schema(); + } + + public function query(): string { + return ' + fragment CoreQuoteBlockFragment on CoreQuote { + attributes { + anchor + backgroundColor + citation + className + cssClassName + fontFamily + fontSize + gradient + # layout + lock + # metadata + style + # textAlign + 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 + } + } + } + '; + } + + /** + * Test case for retrieving core quote block fields and attributes. + * + * The following aspects are tested: + * - The absence of errors in the GraphQL response. + * - Presence of the 'data' and 'post' keys in the response. + * - Matching post ID. + * - Correct block name ('core/quote'). + * - Correct retrieval of the block's attributes, especially 'citation', 'className', 'cssClassName' and 'value'. + * + * @return void + */ + public function test_retrieve_core_quote_fields_and_attributes() { + $block_content = ' + +

This is a sample quote block content.

Author Name
+ + '; + + // Update the post content with the block content. + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $query = $this->query(); + $variables = [ + 'id' => $this->post_id, + ]; + + $actual = graphql( compact( 'query', 'variables' ) ); + + $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. + $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, + 'lock' => null, + 'style' => null, + 'textColor' => null, + 'value' => '

This is a sample quote block content.

', + ], + $block['attributes'], + ); + } + + /** + * Test case for retrieving core quote block untested attributes. + * + * The following aspects are tested: + * - The absence of errors in the GraphQL response. + * - Presence of the 'data' and 'post' keys in the response. + * - Matching post ID. + * - Correct block name ('core/quote'). + * - Correct retrieval of the block's attributes, especially: + * - 'anchor' + * - 'backgroundColor' + * - 'fontFamily' + * - 'fontSize' + * - 'gradient' + * - 'lock' + * - 'style' + * - 'textColor' + * + * @return void + */ + public function test_retrieve_core_quote_attributes() { + $block_content = ' + +
+

Quote, with heading color

+ Citation
+ + '; + + // Update the post content with the block content. + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $query = $this->query(); + $variables = [ + 'id' => $this->post_id, + ]; + + $actual = graphql( compact( 'query', 'variables' ) ); + + $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( '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' ); + + $style = wp_json_encode( + [ + 'elements' => [ + 'heading' => [ + 'color' => [ + 'text' => 'var:preset|color|vivid-cyan-blue', + 'background' => 'var:preset|color|cyan-bluish-gray', + ], + ], + ], + ] + ); + + // Verify the attributes. + $this->assertEquals( + [ + 'anchor' => 'test-anchor', + 'backgroundColor' => 'pale-cyan-blue', + 'citation' => 'Citation', + 'className' => null, + 'cssClassName' => 'wp-block-quote', + 'fontFamily' => 'body', + 'fontSize' => 'small', + 'gradient' => 'pale-ocean', + 'lock' => wp_json_encode( + [ + 'move' => true, + 'remove' => true, + ] + ), + 'style' => $style, + 'textColor' => 'vivid-red', + 'value' => '', + ], + $block['attributes'], + ); + } +} From e2ce653d2f9c49f9ba92020f51bb35ac0c95c548 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Mon, 23 Sep 2024 20:14:19 +0530 Subject: [PATCH 02/17] chore : PR Reworks --- tests/unit/CoreQuoteTest.php | 70 ++++++++++++------------------------ 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index 6024bf26..c15516a9 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -79,16 +79,9 @@ className /** * Test case for retrieving core quote block fields and attributes. * - * The following aspects are tested: - * - The absence of errors in the GraphQL response. - * - Presence of the 'data' and 'post' keys in the response. - * - Matching post ID. - * - Correct block name ('core/quote'). - * - Correct retrieval of the block's attributes, especially 'citation', 'className', 'cssClassName' and 'value'. - * - * @return void + * Covers : 'citation', 'className', 'cssClassName' and 'value'. */ - public function test_retrieve_core_quote_fields_and_attributes() { + public function test_retrieve_core_quote_fields_and_attributes(): void { $block_content = '

This is a sample quote block content.

Author Name
@@ -149,24 +142,9 @@ public function test_retrieve_core_quote_fields_and_attributes() { /** * Test case for retrieving core quote block untested attributes. * - * The following aspects are tested: - * - The absence of errors in the GraphQL response. - * - Presence of the 'data' and 'post' keys in the response. - * - Matching post ID. - * - Correct block name ('core/quote'). - * - Correct retrieval of the block's attributes, especially: - * - 'anchor' - * - 'backgroundColor' - * - 'fontFamily' - * - 'fontSize' - * - 'gradient' - * - 'lock' - * - 'style' - * - 'textColor' - * - * @return void + * Covers : 'anchor', 'backgroundColor', 'fontFamily', 'fontSize', 'gradient', 'lock', 'style' and 'textColor'. */ - public function test_retrieve_core_quote_attributes() { + public function test_retrieve_core_quote_attributes(): void { $block_content = '
@@ -205,38 +183,36 @@ public function test_retrieve_core_quote_attributes() { $this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' ); $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' ); - $style = wp_json_encode( - [ - 'elements' => [ - 'heading' => [ - 'color' => [ - 'text' => 'var:preset|color|vivid-cyan-blue', - 'background' => 'var:preset|color|cyan-bluish-gray', - ], - ], - ], - ] - ); - // Verify the attributes. $this->assertEquals( [ - 'anchor' => 'test-anchor', - 'backgroundColor' => 'pale-cyan-blue', + 'anchor' => 'test-anchor', // Previously untested. + 'backgroundColor' => 'pale-cyan-blue', // Previously untested. 'citation' => 'Citation', 'className' => null, 'cssClassName' => 'wp-block-quote', - 'fontFamily' => 'body', - 'fontSize' => 'small', - 'gradient' => 'pale-ocean', - 'lock' => wp_json_encode( + 'fontFamily' => 'body', // Previously untested. + 'fontSize' => 'small', // Previously untested. + 'gradient' => 'pale-ocean', // Previously untested. + 'lock' => wp_json_encode( // Previously untested. [ 'move' => true, 'remove' => true, ] ), - 'style' => $style, - 'textColor' => 'vivid-red', + 'style' => wp_json_encode( // Previously untested. + [ + 'elements' => [ + 'heading' => [ + 'color' => [ + 'text' => 'var:preset|color|vivid-cyan-blue', + 'background' => 'var:preset|color|cyan-bluish-gray', + ], + ], + ], + ] + ), + 'textColor' => 'vivid-red', // Previously untested. 'value' => '', ], $block['attributes'], From ea33470e212c28ca0368b3baa087a28896896290 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Mon, 23 Sep 2024 21:13:49 +0530 Subject: [PATCH 03/17] 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'], ); From 0415fed20062f09afa4748ac37a5415b3ee9cb5b Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 01:45:29 +0530 Subject: [PATCH 04/17] chore : unset previously tested attributes, uncomment layout and textAlign --- tests/unit/CoreQuoteTest.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index c91792f5..d2ce2ad6 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -51,11 +51,11 @@ className fontFamily fontSize gradient - # layout + layout lock # metadata style - # textAlign + textAlign textColor value } @@ -151,6 +151,8 @@ public function test_retrieve_core_quote_fields_and_attributes(): void { 'style' => null, 'textColor' => null, 'value' => '

This is a sample quote block content.

', + 'layout' => null, + 'textAlign' => null, ], $block['attributes'], ); @@ -206,14 +208,15 @@ public function test_retrieve_core_quote_additional_attributes(): void { $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. + // Verify the attributes. $this->assertEquals( [ 'anchor' => 'test-anchor', // Previously untested. 'backgroundColor' => 'pale-cyan-blue', // Previously untested. - 'citation' => 'Citation', - 'className' => null, - 'cssClassName' => 'wp-block-quote', 'fontFamily' => 'body', // Previously untested. 'fontSize' => 'small', // Previously untested. 'gradient' => 'pale-ocean', // Previously untested. @@ -237,6 +240,8 @@ public function test_retrieve_core_quote_additional_attributes(): void { ), 'textColor' => 'vivid-red', // Previously untested. 'value' => '

Sample Quote

', // Previously untested. + 'layout' => null, + 'textAlign' => null, ], $block['attributes'], ); From c6bdab01fca584d822e6b32603374cc839c1c2dd Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 01:46:19 +0530 Subject: [PATCH 05/17] added changeset --- .changeset/thirty-chicken-drum.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/thirty-chicken-drum.md diff --git a/.changeset/thirty-chicken-drum.md b/.changeset/thirty-chicken-drum.md new file mode 100644 index 00000000..8cfaa014 --- /dev/null +++ b/.changeset/thirty-chicken-drum.md @@ -0,0 +1,5 @@ +--- +"@wpengine/wp-graphql-content-blocks": patch +--- + +test : Core Quote block fields and attributes. From 1df8f3b5c64dcbb56b543de91e74efaafcdff2b7 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 12:48:33 +0530 Subject: [PATCH 06/17] temp : log breaks --- tests/unit/CoreQuoteTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index d2ce2ad6..92bf3743 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -109,6 +109,7 @@ public function test_retrieve_core_quote_fields_and_attributes(): void { ]; $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' ); @@ -186,6 +187,7 @@ public function test_retrieve_core_quote_additional_attributes(): void { ]; $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' ); From d02ddb2403c82a5a44fac674bd93adda9a491319 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 15:43:38 +0530 Subject: [PATCH 07/17] fix : add checks for layout and textAlign attrbiutes that are WP version dependent. --- tests/unit/CoreQuoteTest.php | 85 ++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index 92bf3743..4300a844 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -51,11 +51,9 @@ className fontFamily fontSize gradient - layout lock # metadata style - textAlign textColor value } @@ -242,8 +240,87 @@ public function test_retrieve_core_quote_additional_attributes(): void { ), 'textColor' => 'vivid-red', // Previously untested. 'value' => '

Sample Quote

', // Previously untested. - 'layout' => null, - 'textAlign' => null, + ], + $block['attributes'], + ); + } + + + /** + * Test case for retrieving core quote block untested attributes. + * + * Covers : 'layout' and 'textAlign'. + */ + public function test_retrieve_core_quote_errorneous_attributes(): void { + // layout and textAlign are only supported in WP 6.5+. + // if ( ! is_wp_version_compatible( '6.6' ) ) { + // $this->markTestSkipped( 'This test requires WP 6.6 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 = $this->query(); + $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

', + 'layout' => 'test-layout', // Previously untested. + 'textAlign' => 'test-align', // Previously untested. ], $block['attributes'], ); From 6ea65b8442ee9267a15191b36f2db3f4bc8f7004 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 18:59:56 +0530 Subject: [PATCH 08/17] temp : trigger actions to test cases --- tests/unit/CoreQuoteTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index 4300a844..b78ee45e 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -150,8 +150,8 @@ public function test_retrieve_core_quote_fields_and_attributes(): void { 'style' => null, 'textColor' => null, 'value' => '

This is a sample quote block content.

', - 'layout' => null, - 'textAlign' => null, + // 'layout' => null, + // 'textAlign' => null, ], $block['attributes'], ); @@ -253,9 +253,9 @@ public function test_retrieve_core_quote_additional_attributes(): void { */ public function test_retrieve_core_quote_errorneous_attributes(): void { // layout and textAlign are only supported in WP 6.5+. - // if ( ! is_wp_version_compatible( '6.6' ) ) { - // $this->markTestSkipped( 'This test requires WP 6.6 or higher.' ); - // } + if ( ! is_wp_version_compatible( '6.5' ) ) { + $this->markTestSkipped( 'This test requires WP 6.6 or higher.' ); + } $block_content = '
From 1a219d7737d75cabc7eeb348a1b28b74fdc01658 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:06:19 +0530 Subject: [PATCH 09/17] temp : fix failing layout and textAlign attributes test --- tests/unit/CoreQuoteTest.php | 49 +++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index b78ee45e..d04c46ad 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -272,7 +272,54 @@ public function test_retrieve_core_quote_errorneous_attributes(): void { ] ); - $query = $this->query(); + $query = ' + fragment CoreQuoteBlockFragment on CoreQuote { + innerBlocks { + ... on CoreParagraph{ + attributes { + content + } + } + } + attributes { + anchor + backgroundColor + citation + className + cssClassName + fontFamily + fontSize + gradient + layout + lock + # metadata + style + textAlign + 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, ]; From e966835b20b2096b0e329c8a5b4c1d9d57f1822c Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:10:25 +0530 Subject: [PATCH 10/17] temp : fix expected value for textAlign assertion --- tests/unit/CoreQuoteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index d04c46ad..0f0a1c6a 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -367,7 +367,7 @@ className [ 'value' => '

Sample Quote

', 'layout' => 'test-layout', // Previously untested. - 'textAlign' => 'test-align', // Previously untested. + 'textAlign' => 'center', // Previously untested. ], $block['attributes'], ); From 2df79c5355499793d171da725c8525b65ff9d27a Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:26:24 +0530 Subject: [PATCH 11/17] fix : update testing logic of layout attribute --- tests/unit/CoreQuoteTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index 0f0a1c6a..c336bed7 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -251,13 +251,13 @@ public function test_retrieve_core_quote_additional_attributes(): void { * * Covers : 'layout' and 'textAlign'. */ - public function test_retrieve_core_quote_errorneous_attributes(): void { + public function test_retrieve_core_quote_layout_text_align_attributes(): void { // layout and textAlign are only supported in WP 6.5+. if ( ! is_wp_version_compatible( '6.5' ) ) { $this->markTestSkipped( 'This test requires WP 6.6 or higher.' ); } $block_content = ' - +

Sample Quote

Citation
@@ -366,7 +366,12 @@ className $this->assertEquals( [ 'value' => '

Sample Quote

', - 'layout' => 'test-layout', // Previously untested. + 'layout' => wp_json_encode( // Previously untested. + [ + 'type' => 'flex', + 'flexWrap' => 'nowrap', + ] + ), 'textAlign' => 'center', // Previously untested. ], $block['attributes'], From ea3ab2af3ded8d50775239d173b03ff5de4eecda Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:33:03 +0530 Subject: [PATCH 12/17] 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'], ); From 8e9f8e3e2ebfa5102dd59da683c33075a743cc9b Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:37:18 +0530 Subject: [PATCH 13/17] temp : fix the typo in previous commit --- tests/unit/CoreQuoteTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index 11ff719d..ae54ff53 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -363,7 +363,12 @@ className $this->assertEquals( [ 'value' => '

Sample Quote

', - 'textAlign' => 'center', // Previously untested. + 'layout' => wp_json_encode( // Previously untested. + [ + 'type' => 'flex', + 'flexWrap' => 'nowrap', + ] + ), ], $block['attributes'], ); @@ -488,13 +493,13 @@ className $this->assertEquals( [ 'value' => '

Sample Quote

', - 'layout' => wp_json_encode( // Previously untested. + 'layout' => wp_json_encode( [ 'type' => 'flex', 'flexWrap' => 'nowrap', ] ), - 'textAlign' => 'center', + 'textAlign' => 'center', // Previously untested. ], $block['attributes'], ); From 2f905284323b24e06ca853370acb3e02df13561e Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:46:52 +0530 Subject: [PATCH 14/17] chore : cleanup the redundant tests --- tests/unit/CoreQuoteTest.php | 72 +----------------------------------- 1 file changed, 1 insertion(+), 71 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index ae54ff53..5703f0ca 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -280,19 +280,8 @@ public function test_retrieve_core_quote_layout_attributes(): void { } } attributes { - anchor - backgroundColor - citation - className - cssClassName - fontFamily - fontSize - gradient layout - lock # metadata - style - textColor value } } @@ -317,6 +306,7 @@ className } } '; + $variables = [ 'id' => $this->post_id, ]; @@ -333,31 +323,7 @@ className // 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( @@ -409,20 +375,9 @@ public function test_retrieve_core_quote_text_align_attributes(): void { } } attributes { - anchor - backgroundColor - citation - className - cssClassName - fontFamily - fontSize - gradient layout - lock # metadata - style textAlign - textColor value } } @@ -462,32 +417,7 @@ className // 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( From dbd74c29fa358e20db34a5580724fb1fbdbde4af Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 19:50:08 +0530 Subject: [PATCH 15/17] remove : Remove error_log --- tests/unit/CoreQuoteTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index 5703f0ca..92522bca 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -107,7 +107,6 @@ public function test_retrieve_core_quote_fields_and_attributes(): void { ]; $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' ); @@ -185,7 +184,6 @@ public function test_retrieve_core_quote_additional_attributes(): void { ]; $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' ); @@ -312,7 +310,6 @@ public function test_retrieve_core_quote_layout_attributes(): void { ]; $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' ); @@ -407,7 +404,6 @@ public function test_retrieve_core_quote_text_align_attributes(): void { ]; $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' ); From 8c0f70f436a8e31831e87e361a319fc8d14a3fb9 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 20:42:04 +0530 Subject: [PATCH 16/17] chore : update the changeset description --- .changeset/thirty-chicken-drum.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/thirty-chicken-drum.md b/.changeset/thirty-chicken-drum.md index 8cfaa014..672426ba 100644 --- a/.changeset/thirty-chicken-drum.md +++ b/.changeset/thirty-chicken-drum.md @@ -2,4 +2,4 @@ "@wpengine/wp-graphql-content-blocks": patch --- -test : Core Quote block fields and attributes. +tests : Add tests for `CoreQuote` block. From 3632447635fc42afc4afd4e4eea22ddabea1eb95 Mon Sep 17 00:00:00 2001 From: Ta5r Date: Tue, 24 Sep 2024 20:44:15 +0530 Subject: [PATCH 17/17] remove : Remove the not-required commented test code. --- tests/unit/CoreQuoteTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/CoreQuoteTest.php b/tests/unit/CoreQuoteTest.php index 92522bca..407ffa08 100644 --- a/tests/unit/CoreQuoteTest.php +++ b/tests/unit/CoreQuoteTest.php @@ -149,8 +149,6 @@ public function test_retrieve_core_quote_fields_and_attributes(): void { 'style' => null, 'textColor' => null, 'value' => '

This is a sample quote block content.

', - // 'layout' => null, - // 'textAlign' => null, ], $block['attributes'], );