diff --git a/tests/unit/CoreListTest.php b/tests/unit/CoreListTest.php
index 1e31deb0..68a3195f 100644
--- a/tests/unit/CoreListTest.php
+++ b/tests/unit/CoreListTest.php
@@ -103,9 +103,11 @@ className
/**
* Test case for retrieving core list block fields and attributes.
*
- * Covers : 'anchor', 'backgroundColor', 'className', 'cssClassName' and 'values'.
+ * Covers
+ * - CoreListAttributes: 'anchor', 'backgroundColor', 'className', 'cssClassName' and 'values'.
+ * - CoreListItemAttributes: 'content'.
*/
- public function test_retrieve_core_list_fields_and_attribute(): void {
+ public function test_retrieve_core_list_fields_and_attributes(): void {
$block_content = '
@@ -138,6 +140,7 @@ public function test_retrieve_core_list_fields_and_attribute(): void {
$this->assertEquals( 1, count( $actual['data']['post']['editorBlocks'] ) );
+ // Test the `CoreList` block.
$block = $actual['data']['post']['editorBlocks'][0];
$this->assertNotEmpty( $block['apiVersion'], 'The apiVersion should be present' );
@@ -145,7 +148,6 @@ public function test_retrieve_core_list_fields_and_attribute(): void {
$this->assertNotEmpty( $block['clientId'], 'The clientId should be present' );
$this->assertNotEmpty( $block['cssClassNames'], 'The cssClassNames should be present' );
- $this->assertNotEmpty( $block['innerBlocks'], 'There should be ListItem inner blocks' );
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
$this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
$this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
@@ -171,12 +173,46 @@ public function test_retrieve_core_list_fields_and_attribute(): void {
],
$block['attributes'],
);
+
+ // Test the inner blocks.
+ $this->assertNotEmpty( $block['innerBlocks'], 'There should be inner blocks' );
+ $this->assertCount( 2, $block['innerBlocks'] );
+
+ $block['innerBlocks'][0];
+ $this->assertNotEmpty( $block['innerBlocks'][0]['apiVersion'], 'The apiVersion should be present' );
+ $this->assertEquals( 'text', $block['innerBlocks'][0]['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' );
+ $this->assertEmpty( $block['innerBlocks'][0]['cssClassNames'], 'The cssClassNames should be present' );
+ $this->assertNotEmpty( $block['innerBlocks'][0]['clientId'], 'The clientId should be present' );
+ $this->assertEquals( 'core/list-item', $block['innerBlocks'][0]['name'], 'The block name should be core/list-item' );
+ $this->assertNotEmpty( $block['innerBlocks'][0]['renderedHtml'], 'The renderedHtml should be present' );
+
+ $this->assertEquals(
+ [
+ 'className' => null,
+ 'content' => 'Truck',
+ 'lock' => null,
+ 'placeholder' => null,
+ ],
+ $block['innerBlocks'][0]['attributes'],
+ 'The first inner block attributes should match'
+ );
+
+ $this->assertEquals(
+ [
+ 'className' => null,
+ 'content' => 'Train',
+ 'lock' => null,
+ 'placeholder' => null,
+ ],
+ $block['innerBlocks'][1]['attributes'],
+ 'The second inner block attributes should match'
+ );
}
/**
* Test case for retrieving core list block fields and attributes.
*
- * Covers : 'fontFamily', 'fontSize', 'gradient', and 'lock'.
+ * Covers CoreListAttributes: 'fontFamily', 'fontSize', 'gradient', and 'lock'.
*/
public function test_retrieve_core_list_attributes_typography_and_lock(): void {
$block_content = '
@@ -213,17 +249,6 @@ public function test_retrieve_core_list_attributes_typography_and_lock(): void {
$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 : his is not working.
- // $this->assertNotEmpty( $block['cssClassNames'], 'The cssClassNames should be present' );
-
- $this->assertNotEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
- $this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
- $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
-
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
$this->assertEquals(
@@ -252,7 +277,7 @@ public function test_retrieve_core_list_attributes_typography_and_lock(): void {
/**
* Test case for retrieving core list block fields and attributes.
*
- * Covers : 'ordered' and 'reversed'.
+ * Covers CoreListAttributes: 'ordered' and 'reversed'.
*
* @todo : The 'placeholder' attribute is not tested as it is getting returned as null.
*/
@@ -292,17 +317,7 @@ public function test_retrieve_core_list_attributes_ordered_and_reversed(): void
$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( $block['cssClassNames'], 'The cssClassNames should be present' );
-
- $this->assertNotEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
- $this->assertEmpty( $block['parentClientId'], 'There should be no parentClientId' );
- $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
$this->assertEquals(
[
@@ -330,7 +345,7 @@ public function test_retrieve_core_list_attributes_ordered_and_reversed(): void
/**
* Test case for retrieving core list block fields and attributes.
*
- * Covers : 'start', 'style', 'textColor' and 'type'.
+ * Covers CoreListAttributes: 'start', 'style', 'textColor' and 'type'.
*/
public function test_retrieve_core_list_attributes_start_and_styles(): void {
$block_content = '
@@ -367,18 +382,8 @@ public function test_retrieve_core_list_attributes_start_and_styles(): void {
$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['cssClassNames'], 'The cssClassNames should be present' );
- $this->assertNotEmpty( $block['innerBlocks'], 'There should be no inner blocks' );
$this->assertEquals( 'core/list', $block['name'], 'The block name should be core/list' );
- // @todo : The 'parentClientId' attribute is NULL in the response.
- // $this->assertNotEmpty( $block['parentClientId'], 'There should be no parentClientId' );
-
- $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
-
$this->assertEquals(
[
'anchor' => null,
@@ -417,16 +422,13 @@ public function test_retrieve_core_list_attributes_start_and_styles(): void {
}
/**
- * Test case for retrieving core list block fields and attributes.
+ * Tests the retrieval of CoreListItem attributes.
+ *
+ * `editorBlocks` is flat to test the `parentClientId` attribute.
*
- * Covers : 'className', 'content', 'fontSize', 'fontFamily' and 'lock' attributes.
+ * Covers : CoreListItemAttributes: 'className', 'lock'.
*/
- public function test_retrieve_core_list_item_fields_and_attribute(): void {
- // fontFamily, fontSize and style are only supported in WP 6.2+.
- if ( ! is_wp_version_compatible( '6.2' ) ) {
- $this->markTestSkipped( 'This test requires WP 6.2 or higher.' );
- }
-
+ public function test_retrieve_core_list_item_flat(): void {
$block_content = '
@@ -446,66 +448,32 @@ public function test_retrieve_core_list_item_fields_and_attribute(): void {
);
$query = '
- fragment CoreListBlockFragment on CoreList {
- attributes {
- anchor
- backgroundColor
- className
- cssClassName
- fontFamily
- fontSize
- gradient
- lock
- # metadata
- ordered
- placeholder
- reversed
- start
- style
- textColor
- type
- values
- }
- }
-
fragment CoreListItemBlockFragment on CoreListItem {
attributes {
className
content
- fontFamily
- fontSize
lock
# metadata
- placeholder
- style
}
}
-
query Post( $id: ID! ) {
post(id: $id, idType: DATABASE_ID) {
databaseId
- editorBlocks( flat: false ) {
- apiVersion
- blockEditorCategoryName
+ editorBlocks {
clientId
- cssClassNames
+ name
+ parentClientId
innerBlocks {
- apiVersion
- blockEditorCategoryName
- clientId
- cssClassNames
- name
- parentClientId
- renderedHtml
... on CoreListItem {
+ clientId
+ name
+ parentClientId
...CoreListItemBlockFragment
}
}
- isDynamic
- name
- parentClientId
- renderedHtml
- ...CoreListBlockFragment
+ ... on CoreListItem {
+ ...CoreListItemBlockFragment
+ }
}
}
}
@@ -521,46 +489,43 @@ className
$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'] ) );
+ $this->assertEquals( 2, count( $actual['data']['post']['editorBlocks'] ) );
- $block = $actual['data']['post']['editorBlocks'][0]['innerBlocks'][0];
+ $block = $actual['data']['post']['editorBlocks'][1];
- $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['cssClassNames'], 'The cssClassNames should be present' );
$this->assertEquals( 'core/list-item', $block['name'], 'The block name should be core/list' );
- // @todo : The 'parentClientId' attribute is NULL in the response.
- // $this->assertNotEmpty( $block['parentClientId'], 'There should be some parentClientId for the block' );
+ $this->assertNotEmpty( $block['parentClientId'], 'There should be some parentClientId for the block' );
+ $this->assertEquals( $actual['data']['post']['editorBlocks'][0]['clientId'], $block['parentClientId'], 'The parentClientId should match' );
+ $this->assertEquals( $block['clientId'], $actual['data']['post']['editorBlocks'][0]['innerBlocks'][0]['clientId'], 'The inner block clientId should match' );
- $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
$this->assertEquals(
[
- 'className' => 'test-css-class-item-1',
+ 'className' => 'test-css-class-item-1', // Previously untested.
'content' => 'List item 1',
- 'fontFamily' => 'heading',
- 'fontSize' => 'large',
- 'lock' => wp_json_encode(
+ 'lock' => wp_json_encode( // Previously untested.
[
'move' => true,
'remove' => true,
]
),
- 'placeholder' => null,
- 'style' => null,
],
$block['attributes'],
);
}
-
/**
- * Test case for retrieving parentClientId.
+ * Test case for retrieving core list block fields and attributes.
*
- * Covers : 'parentClientId' attribute.
+ * Covers CoreListItemAttributes: 'fontSize', 'fontFamily'
*/
- public function test_retrieve_core_list_item_parentClientId(): void {
+ public function test_retrieve_core_list_item_font_family_size(): void {
+ // fontFamily, fontSize and style are only supported in WP 6.2+.
+ if ( ! is_wp_version_compatible( '6.2' ) ) {
+ $this->markTestSkipped( 'This test requires WP 6.2 or higher.' );
+ }
+
$block_content = '
@@ -580,18 +545,29 @@ public function test_retrieve_core_list_item_parentClientId(): void {
);
$query = '
+ fragment CoreListItemBlockFragment on CoreListItem {
+ attributes {
+ className
+ content
+ lock
+ fontFamily
+ fontSize
+ style
+ }
+ }
query Post( $id: ID! ) {
post(id: $id, idType: DATABASE_ID) {
databaseId
- editorBlocks {
+ editorBlocks( flat: false ) {
clientId
+ name
+ parentClientId
innerBlocks {
... on CoreListItem {
name
+ ...CoreListItemBlockFragment
}
}
- name
- parentClientId
}
}
}
@@ -607,19 +583,34 @@ public function test_retrieve_core_list_item_parentClientId(): void {
$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( 2, count( $actual['data']['post']['editorBlocks'] ) );
-
- $block = $actual['data']['post']['editorBlocks'][1];
+ $this->assertEquals( 1, count( $actual['data']['post']['editorBlocks'] ) );
- $this->assertNotEmpty( $block['clientId'], 'The clientId should be present' );
+ $block = $actual['data']['post']['editorBlocks'][0]['innerBlocks'][0];
$this->assertEquals( 'core/list-item', $block['name'], 'The block name should be core/list' );
- $this->assertNotEmpty( $block['parentClientId'], 'There should be some parentClientId for the block' );
+
+ $this->assertEquals(
+ [
+ 'className' => 'test-css-class-item-1',
+ 'content' => 'List item 1',
+ 'fontFamily' => 'heading', // Previously untested.
+ 'fontSize' => 'large', // Previously untested.
+ 'lock' => wp_json_encode(
+ [
+ 'move' => true,
+ 'remove' => true,
+ ]
+ ),
+ 'style' => null,
+ ],
+ $block['attributes'],
+ );
}
+
/**
* Test case for retrieving core list item block fields and attributes.
*
- * Covers : 'style' attribute.
+ * Covers CoreListItemAttributes: 'style' attribute.
*/
public function test_retrieve_core_list_item_untested_attributes(): void {
// fontFamily, fontSize and style are only supported in WP 6.2+.
@@ -646,70 +637,34 @@ public function test_retrieve_core_list_item_untested_attributes(): void {
);
$query = '
- fragment CoreListBlockFragment on CoreList {
- attributes {
- anchor
- backgroundColor
- className
- cssClassName
- fontFamily
- fontSize
- gradient
- lock
- # metadata
- ordered
- placeholder
- reversed
- start
- style
- textColor
- type
- values
- }
- }
-
fragment CoreListItemBlockFragment on CoreListItem {
attributes {
className
content
+ lock
fontFamily
fontSize
- lock
- # metadata
- placeholder
style
}
}
-
query Post( $id: ID! ) {
post(id: $id, idType: DATABASE_ID) {
databaseId
editorBlocks( flat: false ) {
- apiVersion
- blockEditorCategoryName
clientId
- cssClassNames
+ name
+ parentClientId
innerBlocks {
- apiVersion
- blockEditorCategoryName
- clientId
- cssClassNames
- name
- parentClientId
- renderedHtml
... on CoreListItem {
+ name
...CoreListItemBlockFragment
}
}
- isDynamic
- name
- parentClientId
- renderedHtml
- ...CoreListBlockFragment
}
}
}
';
+
$variables = [
'id' => $this->post_id,
];
@@ -721,22 +676,11 @@ className
$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'] ) );
$block = $actual['data']['post']['editorBlocks'][0]['innerBlocks'][0];
-
- $this->assertNotEmpty( $block['apiVersion'], 'The apiVersion should be present' );
- $this->assertEquals( 'text', $block['blockEditorCategoryName'], 'The blockEditorCategoryName should be text' );
- $this->assertEmpty( $block['cssClassNames'], 'The cssClassNames should be present' );
- $this->assertNotEmpty( $block['clientId'], 'The clientId should be present' );
$this->assertEquals( 'core/list-item', $block['name'], 'The block name should be core/list' );
- // @todo : The 'parentClientId' attribute is NULL in the response.
- // $this->assertNotEmpty( $block['parentClientId'], 'There should be some parentClientId for the block' );
-
- $this->assertNotEmpty( $block['renderedHtml'], 'The renderedHtml should be present' );
-
$this->assertEquals(
[
'className' => null,
@@ -744,7 +688,6 @@ className
'fontFamily' => null,
'fontSize' => null,
'lock' => null,
- 'placeholder' => null,
'style' => wp_json_encode( [ 'typography' => [ 'textDecoration' => 'underline' ] ] ), // Previously untested.
],
$block['attributes'],