Skip to content

Commit

Permalink
chore : comments and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ta5r committed Sep 27, 2024
1 parent 2e1a8d1 commit 3bf0950
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions tests/unit/CoreImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,22 @@ className
';
}

/**
* Test that the CoreImage block is retrieved correctly.
*
* Covers the following attributes:
* - apiVersion
* - blockEditorCategoryName
* - clientId
* - cssClassNames
* - innerBlocks
* - name
* - parentClientId
* - renderedHtml
* - attributes
*
*/
public function test_retrieve_core_image_fields_attributes(): void {

$block_content = '
<!-- wp:image {"align":"left","id":' . $this->attachment_id . ',"className":"test-css-class-name"} -->
<figure class="wp-block-image">
Expand All @@ -107,7 +121,7 @@ public function test_retrieve_core_image_fields_attributes(): void {

$query = $this->query();

// Set post content.
// Update the post content with the block content.
wp_update_post(
[
'ID' => $this->post_id,
Expand Down Expand Up @@ -175,6 +189,14 @@ public function test_retrieve_core_image_fields_attributes(): void {
);
}

/**
* Test that the CoreImage block mediaDetails are retrieved correctly.
*
* Covers the following attributes:
* - height
* - width
*
*/
public function test_retrieve_core_image_media_details(): void {
$block_content = '
<!-- wp:image {"lightbox":{"enabled":false},"align":"left","width":500,"height":500,"aspectRatio":"4/3","scale":"cover","sizeSlug":"full","linkDestination":"none", "id":' . $this->attachment_id . ',"className":"is-style-rounded", "style":{"color":{"duotone":"var:preset|duotone|purple-green"}},"borderColor":"vivid-red","lock":{"move":true,"remove":true},"className":"test-css-class-name"} -->
Expand Down Expand Up @@ -211,7 +233,7 @@ public function test_retrieve_core_image_media_details(): void {
}
';

// Set post content.
// Update the post content with the block content.
wp_update_post(
[
'ID' => $this->post_id,
Expand All @@ -234,13 +256,39 @@ public function test_retrieve_core_image_media_details(): void {

$this->assertEquals(
[
'width' => 50,
'height' => 50,
'width' => 50, // Previously untested.
'height' => 50, // Previously untested.
],
$block['mediaDetails']
);
}

/**
* Test that the CoreImage block attributes are retrieved correctly.
*
* Covers the following attributes:
* - width
* - height
* - alt
* - id
* - src
* - style
* - sizeSlug
* - linkClass
* - linkTarget
* - linkDestination
* - align
* - caption
* - className
* - url
* - borderColor
* - title
* - lock
* - anchor
* - rel
* - href
*
*/
public function test_retrieve_core_image_attributes(): void {

$block_content = '
Expand All @@ -254,7 +302,7 @@ public function test_retrieve_core_image_attributes(): void {

$query = $this->query();

// Set post content.
// Update the post content with the block content.
wp_update_post(
[
'ID' => $this->post_id,
Expand All @@ -269,7 +317,6 @@ public function test_retrieve_core_image_attributes(): void {

$actual = graphql( compact( 'query', 'variables' ) );

// error_log( print_r( $actual, true ) );
$node = $actual['data']['post'];

$this->assertArrayNotHasKey( 'errors', $actual, 'There should not be any errors' );
Expand All @@ -284,7 +331,7 @@ public function test_retrieve_core_image_attributes(): void {
$this->assertStringContainsString( 'is-resized', $block['attributes']['cssClassName'] );
unset( $block['attributes']['cssClassName'] );

$this->assertEquals(
$this->assertEquals( // Previously untested.
[
'width' => '500',
'height' => 500.0,
Expand Down

0 comments on commit 3bf0950

Please sign in to comment.