Skip to content

Commit

Permalink
fix : checks for inner blocks, cssClassName issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ta5r committed Sep 23, 2024
1 parent e2ce653 commit ea33470
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions tests/unit/CoreQuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 = '
<!-- 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:heading -->
<h2 class="wp-block-heading">Quote, with heading color</h2>
<!-- /wp:heading --><cite>Citation</cite></blockquote>
<blockquote class="wp-block-quote" id="test-anchor"><!-- wp:paragraph -->
<p>Sample Quote</p>
<!-- /wp:paragraph --><cite>Citation</cite></blockquote>
<!-- /wp:quote -->
';

Expand All @@ -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' );
Expand Down Expand Up @@ -213,7 +236,7 @@ public function test_retrieve_core_quote_attributes(): void {
]
),
'textColor' => 'vivid-red', // Previously untested.
'value' => '',
'value' => '<p>Sample Quote</p>', // Previously untested.
],
$block['attributes'],
);
Expand Down

0 comments on commit ea33470

Please sign in to comment.