From 0ca59a1f974ac9c40ab7224270b1ff5f78229374 Mon Sep 17 00:00:00 2001 From: Ashutosh Gautam Date: Sat, 14 Sep 2024 10:09:04 +0530 Subject: [PATCH 01/13] feat: Add CoreHeadingTest --- tests/unit/CoreHeadingTest.php | 115 +++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/unit/CoreHeadingTest.php diff --git a/tests/unit/CoreHeadingTest.php b/tests/unit/CoreHeadingTest.php new file mode 100644 index 00000000..62cbfc4d --- /dev/null +++ b/tests/unit/CoreHeadingTest.php @@ -0,0 +1,115 @@ +post_id = wp_insert_post( + array( + 'post_title' => 'Post with Heading', + 'post_content' => preg_replace( + '/\s+/', + ' ', + trim( + ' + +

Sample Heading

+ + ' + ) + ), + 'post_status' => 'publish', + ) + ); + } + + public function tearDown(): void + { + parent::tearDown(); + wp_delete_post($this->post_id, true); + } + + public function test_retrieve_core_heading_attributes() + { + $query = ' + fragment CoreHeadingBlockFragment on CoreHeading { + attributes { + content + level + textAlign + style + } + } + + query GetPosts { + posts(first: 1) { + nodes { + databaseId + editorBlocks { + name + ...CoreHeadingBlockFragment + } + } + } + } + '; + + $actual = graphql(array('query' => $query)); + $node = $actual['data']['posts']['nodes'][0]; + + // Verify that the ID of the first post matches the one we just created. + $this->assertEquals($this->post_id, $node['databaseId']); + + // There should be only one block using that query when not using flat: true + $this->assertEquals(count($node['editorBlocks']), 1); + $this->assertEquals($node['editorBlocks'][0]['name'], 'core/heading'); + + $this->assertEquals( + $node['editorBlocks'][0]['attributes'], + [ + 'content' => 'Sample Heading', + 'level' => 2, + 'textAlign' => 'center', + 'style' => [ + 'typography' => [ + 'fontSize' => '28px', + 'fontStyle' => 'normal', + 'fontWeight' => '700', + ], + ], + ] + ); + } + + public function test_retrieve_core_heading_content() + { + $query = ' + fragment CoreHeadingBlockFragment on CoreHeading { + content + } + + query GetPosts { + posts(first: 1) { + nodes { + editorBlocks { + ...CoreHeadingBlockFragment + } + } + } + } + '; + + $actual = graphql(array('query' => $query)); + $node = $actual['data']['posts']['nodes'][0]; + + $this->assertEquals($node['editorBlocks'][0]['content'], 'Sample Heading'); + } +} From 039a0d102bb0ac3204c512da70c2ecf61a5c43ed Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 15 Sep 2024 19:26:17 +0000 Subject: [PATCH 02/13] chore: refactor CoreHeadingTest --- tests/unit/CoreHeadingTest.php | 259 +++++++++++++++++++-------------- 1 file changed, 149 insertions(+), 110 deletions(-) diff --git a/tests/unit/CoreHeadingTest.php b/tests/unit/CoreHeadingTest.php index 62cbfc4d..f992b241 100644 --- a/tests/unit/CoreHeadingTest.php +++ b/tests/unit/CoreHeadingTest.php @@ -2,114 +2,153 @@ namespace WPGraphQL\ContentBlocks\Unit; -final class CoreHeadingTest extends PluginTestCase -{ - public $instance; - public $post_id; - - public function setUp(): void - { - parent::setUp(); - global $wpdb; - - $this->post_id = wp_insert_post( - array( - 'post_title' => 'Post with Heading', - 'post_content' => preg_replace( - '/\s+/', - ' ', - trim( - ' - -

Sample Heading

- - ' - ) - ), - 'post_status' => 'publish', - ) - ); - } - - public function tearDown(): void - { - parent::tearDown(); - wp_delete_post($this->post_id, true); - } - - public function test_retrieve_core_heading_attributes() - { - $query = ' - fragment CoreHeadingBlockFragment on CoreHeading { - attributes { - content - level - textAlign - style - } - } - - query GetPosts { - posts(first: 1) { - nodes { - databaseId - editorBlocks { - name - ...CoreHeadingBlockFragment - } - } - } - } - '; - - $actual = graphql(array('query' => $query)); - $node = $actual['data']['posts']['nodes'][0]; - - // Verify that the ID of the first post matches the one we just created. - $this->assertEquals($this->post_id, $node['databaseId']); - - // There should be only one block using that query when not using flat: true - $this->assertEquals(count($node['editorBlocks']), 1); - $this->assertEquals($node['editorBlocks'][0]['name'], 'core/heading'); - - $this->assertEquals( - $node['editorBlocks'][0]['attributes'], - [ - 'content' => 'Sample Heading', - 'level' => 2, - 'textAlign' => 'center', - 'style' => [ - 'typography' => [ - 'fontSize' => '28px', - 'fontStyle' => 'normal', - 'fontWeight' => '700', - ], - ], - ] - ); - } - - public function test_retrieve_core_heading_content() - { - $query = ' - fragment CoreHeadingBlockFragment on CoreHeading { - content - } - - query GetPosts { - posts(first: 1) { - nodes { - editorBlocks { - ...CoreHeadingBlockFragment - } - } - } - } - '; - - $actual = graphql(array('query' => $query)); - $node = $actual['data']['posts']['nodes'][0]; - - $this->assertEquals($node['editorBlocks'][0]['content'], 'Sample Heading'); - } +final class CoreHeadingTest extends PluginTestCase { + public $post_id; + + public function setUp(): void { + parent::setUp(); + + $this->post_id = wp_insert_post( + [ + 'post_title' => 'Post with Heading', + 'post_content' => '', + 'post_status' => 'publish', + ] + ); + } + + public function tearDown(): void { + parent::tearDown(); + + wp_delete_post( $this->post_id, true ); + } + + public function query(): string { + return ' + fragment CoreHeadingBlockFragment on CoreHeading { + attributes { + align + anchor + backgroundColor + className + content + cssClassName + fontFamily + fontSize + gradient + level + lock + # metadata + placeholder + style + textAlign + textColor + } + } + + query Post( $id: ID! ) { + post(id: $id, idType: DATABASE_ID) { + databaseId + editorBlocks { + apiVersion + blockEditorCategoryName + clientId + cssClassNames + innerBlocks { + name + } + isDynamic + name + parentClientId + renderedHtml + ... on BlockWithSupportsAnchor { + anchor + } + ...CoreHeadingBlockFragment + } + } + } + '; + } + + public function test_retrieve_core_heading_attributes() { + $block_content = ' + +

Sample Heading

+ + '; + + // 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, + ]; + + // Test the query. + + $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' ); + + // Verify that the ID of the first post matches the one we just created. + $this->assertEquals( $this->post_id, $actual['data']['post']['databaseId'], 'The post ID should match' ); + + // There should be only one block using that query when not using flat: true + $this->assertEquals( 1, count( $actual['data']['post']['editorBlocks'] ) ); + + // Verify the block data. + error_log( print_r( $actual['data']['post']['editorBlocks'][0], true ) ); + $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['apiVersion'], 'The apiVersion should be present' ); + $this->assertEquals( 'text', $actual['data']['post']['editorBlocks'][0]['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' ); + $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['clientId'], 'The clientId should be present' ); + + // @todo this is not working + // $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['cssClassNames'], 'The cssClassNames should be present' ); + + $this->assertEmpty( $actual['data']['post']['editorBlocks'][0]['innerBlocks'], 'There should be no inner blocks' ); + $this->assertEquals( 'core/heading', $actual['data']['post']['editorBlocks'][0]['name'], 'The block name should be core/heading' ); + $this->assertEmpty( $actual['data']['post']['editorBlocks'][0]['parentClientId'], 'There should be no parentClientId' ); + $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['renderedHtml'], 'The renderedHtml should be present' ); + + // Verify the attributes. + $this->assertEquals( + [ + 'align' => null, + 'anchor' => null, + 'backgroundColor' => null, + 'className' => null, + 'content' => 'Sample Heading', + 'cssClassName' => 'wp-block-heading has-text-align-center', + 'fontFamily' => null, + 'fontSize' => null, + 'gradient' => null, + 'level' => 2.0, // @todo this should be an integer + 'lock' => null, + 'placeholder' => null, + 'style' => wp_json_encode( + [ + 'typography' => [ + 'fontSize' => '28px', + 'fontStyle' => 'normal', + 'fontWeight' => '700', + ], + ], + ), + 'textAlign' => 'center', + 'textColor' => null, + ], + $actual['data']['post']['editorBlocks'][0]['attributes'], + ); + } } From 92e7ae61441a4043f30de07e3e2fce5b9b01fb4e Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 15 Sep 2024 19:41:28 +0000 Subject: [PATCH 03/13] chore: cleanup --- tests/unit/CoreHeadingTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/unit/CoreHeadingTest.php b/tests/unit/CoreHeadingTest.php index f992b241..3ca5e058 100644 --- a/tests/unit/CoreHeadingTest.php +++ b/tests/unit/CoreHeadingTest.php @@ -15,12 +15,16 @@ public function setUp(): void { '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 { @@ -95,8 +99,6 @@ public function test_retrieve_core_heading_attributes() { $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' ); @@ -108,7 +110,6 @@ public function test_retrieve_core_heading_attributes() { $this->assertEquals( 1, count( $actual['data']['post']['editorBlocks'] ) ); // Verify the block data. - error_log( print_r( $actual['data']['post']['editorBlocks'][0], true ) ); $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['apiVersion'], 'The apiVersion should be present' ); $this->assertEquals( 'text', $actual['data']['post']['editorBlocks'][0]['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' ); $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['clientId'], 'The clientId should be present' ); From cdec9ee302ae34473c3f7eae5f5636b867732dfa Mon Sep 17 00:00:00 2001 From: Ashutosh Gautam Date: Wed, 18 Sep 2024 20:04:25 +0530 Subject: [PATCH 04/13] feat: Add tests for additional snippets - cover the attributes that are null --- tests/unit/CoreHeadingTest.php | 223 ++++++++++++++++++++++++++++++--- 1 file changed, 206 insertions(+), 17 deletions(-) diff --git a/tests/unit/CoreHeadingTest.php b/tests/unit/CoreHeadingTest.php index 3ca5e058..d8f03259 100644 --- a/tests/unit/CoreHeadingTest.php +++ b/tests/unit/CoreHeadingTest.php @@ -49,7 +49,6 @@ className textColor } } - query Post( $id: ID! ) { post(id: $id, idType: DATABASE_ID) { databaseId @@ -82,7 +81,6 @@ public function test_retrieve_core_heading_attributes() { '; - // Update the post content with the block content. wp_update_post( [ 'ID' => $this->post_id, @@ -95,34 +93,31 @@ public function test_retrieve_core_heading_attributes() { 'id' => $this->post_id, ]; - // Test the query. - $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' ); - // Verify that the ID of the first post matches the one we just created. $this->assertEquals( $this->post_id, $actual['data']['post']['databaseId'], 'The post ID should match' ); - // There should be only one block using that query when not using flat: true $this->assertEquals( 1, count( $actual['data']['post']['editorBlocks'] ) ); - // Verify the block data. - $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['apiVersion'], 'The apiVersion should be present' ); - $this->assertEquals( 'text', $actual['data']['post']['editorBlocks'][0]['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' ); - $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['clientId'], 'The clientId should be present' ); + $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' ); // @todo this is not working - // $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['cssClassNames'], 'The cssClassNames should be present' ); + // $this->assertNotEmpty( $block['cssClassNames'], 'The cssClassNames should be present' ); - $this->assertEmpty( $actual['data']['post']['editorBlocks'][0]['innerBlocks'], 'There should be no inner blocks' ); - $this->assertEquals( 'core/heading', $actual['data']['post']['editorBlocks'][0]['name'], 'The block name should be core/heading' ); - $this->assertEmpty( $actual['data']['post']['editorBlocks'][0]['parentClientId'], 'There should be no parentClientId' ); - $this->assertNotEmpty( $actual['data']['post']['editorBlocks'][0]['renderedHtml'], 'The renderedHtml should be present' ); + $this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' ); + $this->assertEquals( 'core/heading', $block['name'], 'The block name should be core/heading' ); + $this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' ); + $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' ); - // Verify the attributes. + $attributes = $block['attributes']; $this->assertEquals( [ 'align' => null, @@ -149,7 +144,201 @@ public function test_retrieve_core_heading_attributes() { 'textAlign' => 'center', 'textColor' => null, ], - $actual['data']['post']['editorBlocks'][0]['attributes'], + $attributes, + ); + } + + public function test_retrieve_core_heading_with_colors_and_alignment() { + $block_content = ' + +

Colored Heading

+ + '; + + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $actual = graphql([ + 'query' => $this->query(), + 'variables' => ['id' => $this->post_id], + ]); + + $block = $actual['data']['post']['editorBlocks'][0]; + $attributes = $block['attributes']; + + $this->assertEquals( 'Colored Heading', $attributes['content'] ); + $this->assertEquals( 3.0, $attributes['level'] ); + $this->assertEquals( 'right', $attributes['textAlign'] ); + $this->assertEquals( 'wide', $attributes['align'] ); + + $style = json_decode($attributes['style'], true); + $this->assertEquals('#cf2e2e', $style['color']['background']); + $this->assertEquals('#ffffff', $style['color']['text']); + } + + public function test_retrieve_core_heading_with_font_and_anchor() { + $block_content = ' + +

Custom Font Heading

+ + '; + + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $actual = graphql([ + 'query' => $this->query(), + 'variables' => ['id' => $this->post_id], + ]); + + $block = $actual['data']['post']['editorBlocks'][0]; + $attributes = $block['attributes']; + + $this->assertEquals( 'Custom Font Heading', $attributes['content'] ); + $this->assertEquals( 'custom-id', $attributes['anchor'] ); + + $style = json_decode($attributes['style'], true); + $this->assertEquals('Arial', $style['typography']['fontFamily']); + $this->assertEquals('32px', $style['typography']['fontSize']); + } + + public function test_retrieve_core_heading_with_gradient() { + $block_content = ' + +

Gradient Heading

+ + '; + + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $actual = graphql([ + 'query' => $this->query(), + 'variables' => ['id' => $this->post_id], + ]); + + $block = $actual['data']['post']['editorBlocks'][0]; + $attributes = $block['attributes']; + + $this->assertEquals( 'Gradient Heading', $attributes['content'] ); + + $style = json_decode($attributes['style'], true); + $this->assertEquals('linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)', $style['color']['gradient']); + } + + public function test_retrieve_core_heading_with_background_color() { + $block_content = ' + +

Heading with Background Color

+ +

Heading with Text Color

+ +

Heading with Font Size

+ +

Heading with Custom Class

+ + ./wp-graphql-content-blocks.php + ./includes/ + /vendor/ + /node_modules/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + + /includes/utilities/DomHelpers.php + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + + + /tests/ + + + diff --git a/tests/unit/CoreHeadingTest.php b/tests/unit/CoreHeadingTest.php index 9f0bf4a3..126f9fa7 100644 --- a/tests/unit/CoreHeadingTest.php +++ b/tests/unit/CoreHeadingTest.php @@ -3,7 +3,7 @@ namespace WPGraphQL\ContentBlocks\Unit; final class CoreHeadingTest extends PluginTestCase { - public $post_id; + public int $post_id; public function setUp(): void { parent::setUp(); @@ -109,9 +109,6 @@ public function test_retrieve_core_heading_attributes() { $this->assertEquals( 'text', $block['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' ); $this->assertNotEmpty( $block['clientId'], 'The clientId should be present' ); - // @todo this is not working - // $this->assertNotEmpty( $block['cssClassNames'], 'The cssClassNames should be present' ); - $this->assertEmpty( $block['innerBlocks'], 'There should be no inner blocks' ); $this->assertEquals( 'core/heading', $block['name'], 'The block name should be core/heading' ); $this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' ); @@ -176,7 +173,7 @@ public function test_retrieve_core_heading_with_colors_and_alignment() { [ 'align' => 'wide', // Previously untested 'anchor' => null, - 'backgroundColor' => null, // @todo: This is not returning correctly. + 'backgroundColor' => null, 'className' => null, 'content' => 'Colored Heading', 'cssClassName' => 'wp-block-heading has-text-align-right has-text-color has-background alignwide', @@ -186,14 +183,62 @@ public function test_retrieve_core_heading_with_colors_and_alignment() { 'level' => 3.0, 'lock' => null, 'placeholder' => null, - 'style' => wp_json_encode([ - 'color' => [ - 'background' => '#cf2e2e', - 'text' => '#ffffff', - ], - ]), + 'style' => wp_json_encode( + [ + 'color' => [ + 'background' => '#cf2e2e', + 'text' => '#ffffff', + ], + ] + ), 'textAlign' => 'right', - 'textColor' => null, // @todo: This is not returning correctly. + 'textColor' => null, + ], + $attributes + ); + } + + public function test_retrieve_core_heading_with_background_text_color() { + $block_content = ' + +

Colored Heading

+ + '; + + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $actual = graphql( + [ + 'query' => $this->query(), + 'variables' => [ 'id' => $this->post_id ], + ] + ); + + $block = $actual['data']['post']['editorBlocks'][0]; + $attributes = $block['attributes']; + + $this->assertEquals( + [ + 'align' => 'wide', + 'anchor' => null, + 'backgroundColor' => 'accent-4', // Previously untested + 'className' => null, + 'content' => 'Colored Heading', + 'cssClassName' => 'wp-block-heading alignwide has-text-align-right has-accent-3-color has-accent-4-background-color has-text-color has-background', + 'fontFamily' => null, + 'fontSize' => null, + 'gradient' => null, + 'level' => 3.0, + 'lock' => null, + 'placeholder' => null, + 'style' => null, + 'textAlign' => 'right', + 'textColor' => 'accent-3', // Previously untested ], $attributes ); @@ -231,18 +276,20 @@ public function test_retrieve_core_heading_with_font_and_anchor() { 'className' => null, 'content' => 'Custom Font Heading', 'cssClassName' => 'wp-block-heading', - 'fontFamily' => null, // @todo: This is not returning correctly. - 'fontSize' => null, // @todo: This is not returning correctly. + 'fontFamily' => null, + 'fontSize' => null, 'gradient' => null, 'level' => 2.0, 'lock' => null, 'placeholder' => null, - 'style' => wp_json_encode([ - 'typography' => [ - 'fontFamily' => 'Arial', // Previously untested - 'fontSize' => '32px', // Previously untested - ], - ]), + 'style' => wp_json_encode( + [ + 'typography' => [ + 'fontFamily' => 'Arial', // Previously untested + 'fontSize' => '32px', // Previously untested + ], + ] + ), 'textAlign' => null, 'textColor' => null, ], @@ -250,7 +297,99 @@ public function test_retrieve_core_heading_with_font_and_anchor() { ); } + public function test_retrieve_core_heading_with_font_family_and_size() { + $block_content = ' + +

hurrah

+ + '; + + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $actual = graphql( + [ + 'query' => $this->query(), + 'variables' => [ 'id' => $this->post_id ], + ] + ); + + $block = $actual['data']['post']['editorBlocks'][0]; + $attributes = $block['attributes']; + + $this->assertEquals( + [ + 'align' => null, + 'anchor' => null, + 'backgroundColor' => 'accent', + 'className' => 'is-style-default', + 'content' => 'hurrah', + 'cssClassName' => 'wp-block-heading is-style-default has-contrast-2-color has-accent-background-color has-text-color has-background has-system-sans-serif-font-family has-xx-large-font-size', + 'fontFamily' => 'system-sans-serif', // Previously untested + 'fontSize' => 'xx-large', // Previously untested + 'gradient' => null, + 'level' => 2.0, + 'lock' => null, + 'placeholder' => null, + 'style' => null, + 'textAlign' => null, + 'textColor' => 'contrast-2', + ], + $attributes + ); + } + public function test_retrieve_core_heading_with_gradient() { + $block_content = ' + +

hello

+ + '; + + wp_update_post( + [ + 'ID' => $this->post_id, + 'post_content' => $block_content, + ] + ); + + $actual = graphql( + [ + 'query' => $this->query(), + 'variables' => [ 'id' => $this->post_id ], + ] + ); + + $block = $actual['data']['post']['editorBlocks'][0]; + $attributes = $block['attributes']; + + $this->assertEquals( + [ + 'align' => null, + 'anchor' => null, + 'backgroundColor' => null, + 'className' => null, + 'content' => 'hello', + 'cssClassName' => 'wp-block-heading has-gradient-3-gradient-background has-background has-medium-font-size', + 'fontFamily' => null, + 'fontSize' => 'medium', + 'gradient' => 'gradient-3', // Previously untested + 'level' => 2.0, + 'lock' => null, + 'placeholder' => null, + 'style' => null, + 'textAlign' => null, + 'textColor' => null, + ], + $attributes + ); + } + + public function test_retrieve_core_heading_with_custom_gradient() { $block_content = '

Gradient Heading

@@ -284,15 +423,17 @@ public function test_retrieve_core_heading_with_gradient() { 'cssClassName' => 'wp-block-heading has-background', 'fontFamily' => null, 'fontSize' => null, - 'gradient' => null, // @todo: This is not returning correctly. + 'gradient' => null, 'level' => 2.0, 'lock' => null, 'placeholder' => null, - 'style' => wp_json_encode([ - 'color' => [ - 'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)', - ], - ]), + 'style' => wp_json_encode( + [ + 'color' => [ + 'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)', + ], + ] + ), 'textAlign' => null, 'textColor' => null, ], From ba1e53284a2163cf2432cc07e5a548cb92e90949 Mon Sep 17 00:00:00 2001 From: Ashutosh Gautam Date: Tue, 24 Sep 2024 02:01:17 +0530 Subject: [PATCH 10/13] fix: Remove phpcs.xml --- phpcs.xml | 148 ------------------------------------------------------ 1 file changed, 148 deletions(-) delete mode 100644 phpcs.xml diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 7d6aadfb..00000000 --- a/phpcs.xml +++ /dev/null @@ -1,148 +0,0 @@ - - - Sniffs for WPGraphQL Content Blocks - - - ./wp-graphql-content-blocks.php - ./includes/ - /vendor/ - /node_modules/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - - /includes/utilities/DomHelpers.php - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - - - /tests/ - - - From 110103c0515ac07a949a5ac6abfee8b6cbc51c48 Mon Sep 17 00:00:00 2001 From: Ashutosh Gautam Date: Tue, 24 Sep 2024 03:30:37 +0530 Subject: [PATCH 11/13] fix: Add doc-blocks, remove duplicate tests --- tests/unit/CoreHeadingTest.php | 290 ++++++--------------------------- 1 file changed, 50 insertions(+), 240 deletions(-) diff --git a/tests/unit/CoreHeadingTest.php b/tests/unit/CoreHeadingTest.php index 126f9fa7..4af5c7f1 100644 --- a/tests/unit/CoreHeadingTest.php +++ b/tests/unit/CoreHeadingTest.php @@ -3,8 +3,16 @@ namespace WPGraphQL\ContentBlocks\Unit; final class CoreHeadingTest extends PluginTestCase { - public int $post_id; - + /** + * The ID of the post created for the test. + * + * @var int + */ + public $post_id; + + /** + * Set up the test environment. + */ public function setUp(): void { parent::setUp(); @@ -19,6 +27,9 @@ public function setUp(): void { \WPGraphQL::clear_schema(); } + /** + * Tear down the test environment. + */ public function tearDown(): void { parent::tearDown(); @@ -27,6 +38,11 @@ public function tearDown(): void { \WPGraphQL::clear_schema(); } + /** + * Provide the GraphQL query for testing. + * + * @return string The GraphQL query. + */ public function query(): string { return ' fragment CoreHeadingBlockFragment on CoreHeading { @@ -74,6 +90,11 @@ className '; } + /** + * Test the retrieval of core/heading block attributes. + * + * @return void + */ public function test_retrieve_core_heading_attributes() { $block_content = ' @@ -145,6 +166,11 @@ public function test_retrieve_core_heading_attributes() { ); } + /** + * Test retrieval of core/heading block with colors and alignment. + * + * @return void + */ public function test_retrieve_core_heading_with_colors_and_alignment() { $block_content = ' @@ -198,6 +224,11 @@ public function test_retrieve_core_heading_with_colors_and_alignment() { ); } + /** + * Test retrieval of core/heading block with background and text color. + * + * @return void + */ public function test_retrieve_core_heading_with_background_text_color() { $block_content = ' @@ -244,6 +275,11 @@ public function test_retrieve_core_heading_with_background_text_color() { ); } + /** + * Test retrieval of core/heading block with font and anchor. + * + * @return void + */ public function test_retrieve_core_heading_with_font_and_anchor() { $block_content = ' @@ -297,6 +333,11 @@ public function test_retrieve_core_heading_with_font_and_anchor() { ); } + /** + * Test retrieval of core/heading block with className, font family and font size. + * + * @return void + */ public function test_retrieve_core_heading_with_font_family_and_size() { $block_content = ' @@ -326,7 +367,7 @@ public function test_retrieve_core_heading_with_font_family_and_size() { 'align' => null, 'anchor' => null, 'backgroundColor' => 'accent', - 'className' => 'is-style-default', + 'className' => 'is-style-default', // Previously untested 'content' => 'hurrah', 'cssClassName' => 'wp-block-heading is-style-default has-contrast-2-color has-accent-background-color has-text-color has-background has-system-sans-serif-font-family has-xx-large-font-size', 'fontFamily' => 'system-sans-serif', // Previously untested @@ -343,6 +384,11 @@ public function test_retrieve_core_heading_with_font_family_and_size() { ); } + /** + * Test retrieval of core/heading block with font size & gradient. + * + * @return void + */ public function test_retrieve_core_heading_with_gradient() { $block_content = ' @@ -376,7 +422,7 @@ public function test_retrieve_core_heading_with_gradient() { 'content' => 'hello', 'cssClassName' => 'wp-block-heading has-gradient-3-gradient-background has-background has-medium-font-size', 'fontFamily' => null, - 'fontSize' => 'medium', + 'fontSize' => 'medium', // Previously untested 'gradient' => 'gradient-3', // Previously untested 'level' => 2.0, 'lock' => null, @@ -388,240 +434,4 @@ public function test_retrieve_core_heading_with_gradient() { $attributes ); } - - public function test_retrieve_core_heading_with_custom_gradient() { - $block_content = ' - -

Gradient Heading

- - '; - - wp_update_post( - [ - 'ID' => $this->post_id, - 'post_content' => $block_content, - ] - ); - - $actual = graphql( - [ - 'query' => $this->query(), - 'variables' => [ 'id' => $this->post_id ], - ] - ); - - $block = $actual['data']['post']['editorBlocks'][0]; - $attributes = $block['attributes']; - - $this->assertEquals( - [ - 'align' => null, - 'anchor' => null, - 'backgroundColor' => null, - 'className' => null, - 'content' => 'Gradient Heading', - 'cssClassName' => 'wp-block-heading has-background', - 'fontFamily' => null, - 'fontSize' => null, - 'gradient' => null, - 'level' => 2.0, - 'lock' => null, - 'placeholder' => null, - 'style' => wp_json_encode( - [ - 'color' => [ - 'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)', - ], - ] - ), - 'textAlign' => null, - 'textColor' => null, - ], - $attributes - ); - } - - public function test_retrieve_core_heading_with_background_color() { - $block_content = ' - -

Heading with Background Color

- -

Heading with Text Color

- -

Heading with Font Size

- -

Heading with Custom Class

- +

Locked Heading

+