forked from wpengine/wp-graphql-content-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests : Add tests for Core Quote
block.
#23
Merged
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6d97815
tests: add tests for `CoreQuote`
e2ce653
chore : PR Reworks
Ta5r ea33470
fix : checks for inner blocks, cssClassName issue.
Ta5r 0415fed
chore : unset previously tested attributes, uncomment layout and text…
Ta5r c6bdab0
added changeset
Ta5r 1df8f3b
temp : log breaks
Ta5r d02ddb2
fix : add checks for layout and textAlign attrbiutes that are WP vers…
Ta5r 6ea65b8
temp : trigger actions to test cases
Ta5r 1a219d7
temp : fix failing layout and textAlign attributes test
Ta5r e966835
temp : fix expected value for textAlign assertion
Ta5r 2df79c5
fix : update testing logic of layout attribute
Ta5r ea3ab2a
temp : split up test for layout and textAlign
Ta5r 8e9f8e3
temp : fix the typo in previous commit
Ta5r 2f90528
chore : cleanup the redundant tests
Ta5r dbd74c2
remove : Remove error_log
Ta5r 8c0f70f
chore : update the changeset description
Ta5r 3632447
remove : Remove the not-required commented test code.
Ta5r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@wpengine/wp-graphql-content-blocks": patch | ||
--- | ||
|
||
test : Core Quote block fields and attributes. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,328 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\ContentBlocks\Unit; | ||
|
||
final class CoreQuoteTest extends PluginTestCase { | ||
/** | ||
* The ID of the post created for the test. | ||
* | ||
* @var int | ||
*/ | ||
public $post_id; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->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 { | ||
innerBlocks { | ||
... on CoreParagraph{ | ||
attributes { | ||
content | ||
} | ||
} | ||
} | ||
attributes { | ||
anchor | ||
backgroundColor | ||
citation | ||
className | ||
cssClassName | ||
fontFamily | ||
fontSize | ||
gradient | ||
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 | ||
} | ||
} | ||
} | ||
'; | ||
} | ||
|
||
/** | ||
* Test case for retrieving core quote block fields and attributes. | ||
* | ||
* Covers : 'citation', 'className', 'cssClassName' and 'value'. | ||
*/ | ||
public function test_retrieve_core_quote_fields_and_attributes(): void { | ||
$block_content = ' | ||
<!-- wp:quote {"className":"custom-quote-class"} --> | ||
<blockquote class="wp-block-quote custom-quote-class"><p>This is a sample quote block content.</p><cite>Author Name</cite></blockquote> | ||
<!-- /wp:quote --> | ||
'; | ||
|
||
// 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' ); | ||
|
||
$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.. | ||
|
||
// 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', | ||
'fontFamily' => null, | ||
'fontSize' => null, | ||
'gradient' => null, | ||
'lock' => null, | ||
'style' => null, | ||
'textColor' => null, | ||
'value' => '<p>This is a sample quote block content.</p>', | ||
// 'layout' => null, | ||
// 'textAlign' => null, | ||
], | ||
$block['attributes'], | ||
); | ||
} | ||
|
||
/** | ||
* Test case for retrieving core quote block untested attributes. | ||
* | ||
* Covers : 'anchor', 'backgroundColor', 'fontFamily', 'fontSize', 'gradient', 'lock', 'style', 'textColor' and 'value'. | ||
*/ | ||
public function test_retrieve_core_quote_additional_attributes(): void { | ||
$block_content = ' | ||
<!-- wp:quote {"lock":{"move":true,"remove":true},"fontFamily":"body","fontSize":"small","backgroundColor":"pale-cyan-blue","style":{"elements":{"heading":{"color":{"text":"var:preset|color|vivid-cyan-blue","background":"var:preset|color|cyan-bluish-gray"}}}},"textColor":"vivid-red","gradient":"pale-ocean"} --> | ||
<blockquote class="wp-block-quote" id="test-anchor"><!-- wp:paragraph --> | ||
<p>Sample Quote</p> | ||
<!-- /wp:paragraph --><cite>Citation</cite></blockquote> | ||
<!-- /wp:quote --> | ||
'; | ||
|
||
// 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. | ||
|
||
// Verify the attributes. | ||
$this->assertEquals( | ||
justlevine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[ | ||
'anchor' => 'test-anchor', // Previously untested. | ||
'backgroundColor' => 'pale-cyan-blue', // Previously untested. | ||
'fontFamily' => 'body', // Previously untested. | ||
'fontSize' => 'small', // Previously untested. | ||
'gradient' => 'pale-ocean', // Previously untested. | ||
'lock' => wp_json_encode( // Previously untested. | ||
[ | ||
'move' => true, | ||
'remove' => true, | ||
] | ||
), | ||
'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' => '<p>Sample Quote</p>', // Previously untested. | ||
], | ||
$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.5' ) ) { | ||
$this->markTestSkipped( 'This test requires WP 6.6 or higher.' ); | ||
} | ||
$block_content = ' | ||
<!-- wp:quote {"layout":"test-layout","textAlign":"center"} --> | ||
<blockquote class="wp-block-quote" id="test-anchor"><!-- wp:paragraph --> | ||
<p>Sample Quote</p> | ||
<!-- /wp:paragraph --><cite>Citation</cite></blockquote> | ||
<!-- /wp:quote --> | ||
'; | ||
|
||
// Update the post content with the block content. | ||
wp_update_post( | ||
[ | ||
'ID' => $this->post_id, | ||
'post_content' => $block_content, | ||
] | ||
); | ||
|
||
$query = $this->query(); | ||
justlevine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$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. | ||
justlevine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$this->assertEquals( | ||
[ | ||
'value' => '<p>Sample Quote</p>', | ||
'layout' => 'test-layout', // Previously untested. | ||
'textAlign' => 'test-align', // Previously untested. | ||
], | ||
$block['attributes'], | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this