Skip to content

Commit

Permalink
fix : add checks for layout and textAlign attrbiutes that are WP vers…
Browse files Browse the repository at this point in the history
…ion dependent.
  • Loading branch information
Ta5r committed Sep 24, 2024
1 parent 1df8f3b commit d02ddb2
Showing 1 changed file with 81 additions and 4 deletions.
85 changes: 81 additions & 4 deletions tests/unit/CoreQuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ className
fontFamily
fontSize
gradient
layout
lock
# metadata
style
textAlign
textColor
value
}
Expand Down Expand Up @@ -242,8 +240,87 @@ public function test_retrieve_core_quote_additional_attributes(): void {
),
'textColor' => 'vivid-red', // Previously untested.
'value' => '<p>Sample Quote</p>', // 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 = '
<!-- 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();
$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' => '<p>Sample Quote</p>',
'layout' => 'test-layout', // Previously untested.
'textAlign' => 'test-align', // Previously untested.
],
$block['attributes'],
);
Expand Down

0 comments on commit d02ddb2

Please sign in to comment.