Skip to content

Commit

Permalink
fix: Update new tests so assertEquals()
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshgautams committed Sep 18, 2024
1 parent eaf44ca commit 9be31c6
Showing 1 changed file with 156 additions and 28 deletions.
184 changes: 156 additions & 28 deletions tests/unit/CoreHeadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ public function test_retrieve_core_heading_attributes() {
'fontStyle' => 'normal',
'fontWeight' => '700',
],
],
]
),
'textAlign' => 'center',
'textColor' => null,
],
$attributes,
$attributes
);
}

Expand Down Expand Up @@ -172,14 +172,31 @@ public function test_retrieve_core_heading_with_colors_and_alignment() {
$block = $actual['data']['post']['editorBlocks'][0];
$attributes = $block['attributes'];

$this->assertEquals( 'Colored Heading', $attributes['content'] );
$this->assertEquals( 3.0, $attributes['level'] );
$this->assertEquals( 'right', $attributes['textAlign'] );
$this->assertEquals( 'wide', $attributes['align'] );

$style = json_decode( $attributes['style'], true );
$this->assertEquals( '#cf2e2e', $style['color']['background'] );
$this->assertEquals( '#ffffff', $style['color']['text'] );
$this->assertEquals(
[
'align' => 'wide', // Previously untested
'anchor' => null,
'backgroundColor' => null,
'className' => null,
'content' => 'Colored Heading',
'cssClassName' => 'wp-block-heading has-text-align-right has-text-color has-background alignwide',
'fontFamily' => null,
'fontSize' => null,
'gradient' => null,
'level' => 3.0,
'lock' => null,
'placeholder' => null,
'style' => wp_json_encode([
'color' => [
'background' => '#cf2e2e',
'text' => '#ffffff',
],
]),
'textAlign' => 'right',
'textColor' => null,
],
$attributes
);
}

public function test_retrieve_core_heading_with_font_and_anchor() {
Expand All @@ -206,12 +223,31 @@ public function test_retrieve_core_heading_with_font_and_anchor() {
$block = $actual['data']['post']['editorBlocks'][0];
$attributes = $block['attributes'];

$this->assertEquals( 'Custom Font Heading', $attributes['content'] );
$this->assertEquals( 'custom-id', $attributes['anchor'] );

$style = json_decode( $attributes['style'], true );
$this->assertEquals( 'Arial', $style['typography']['fontFamily'] );
$this->assertEquals( '32px', $style['typography']['fontSize'] );
$this->assertEquals(
[
'align' => null,
'anchor' => 'custom-id',
'backgroundColor' => null,
'className' => null,
'content' => 'Custom Font Heading',
'cssClassName' => 'wp-block-heading',
'fontFamily' => null, // Previously untested
'fontSize' => null,
'gradient' => null,
'level' => 2.0,
'lock' => null,
'placeholder' => null,
'style' => wp_json_encode([
'typography' => [
'fontFamily' => 'Arial',
'fontSize' => '32px',
],
]),
'textAlign' => null,
'textColor' => null,
],
$attributes
);
}

public function test_retrieve_core_heading_with_gradient() {
Expand All @@ -238,10 +274,30 @@ public function test_retrieve_core_heading_with_gradient() {
$block = $actual['data']['post']['editorBlocks'][0];
$attributes = $block['attributes'];

$this->assertEquals( 'Gradient Heading', $attributes['content'] );

$style = json_decode( $attributes['style'], true );
$this->assertEquals( 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)', $style['color']['gradient'] );
$this->assertEquals(
[
'align' => null,
'anchor' => null,
'backgroundColor' => null,
'className' => null,
'content' => 'Gradient Heading',
'cssClassName' => 'wp-block-heading has-background',
'fontFamily' => null,
'fontSize' => null,
'gradient' => null, // Previously untested
'level' => 2.0,
'lock' => null,
'placeholder' => null,
'style' => wp_json_encode([
'color' => [
'gradient' => 'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(155,81,224) 100%)',
],
]),
'textAlign' => null,
'textColor' => null,
],
$attributes
);
}

public function test_retrieve_core_heading_with_background_color() {
Expand All @@ -268,8 +324,26 @@ public function test_retrieve_core_heading_with_background_color() {
$block = $actual['data']['post']['editorBlocks'][0];
$attributes = $block['attributes'];

$this->assertEquals( 'Heading with Background Color', $attributes['content'] );
$this->assertEquals( 'vivid-red-background-color', $attributes['backgroundColor'] );
$this->assertEquals(
[
'align' => null,
'anchor' => null,
'backgroundColor' => 'vivid-red-background-color',
'className' => null,
'content' => 'Heading with Background Color',
'cssClassName' => 'wp-block-heading has-vivid-red-background-color has-background',
'fontFamily' => null,
'fontSize' => null,
'gradient' => null,
'level' => 2.0,
'lock' => null,
'placeholder' => null,
'style' => null,
'textAlign' => null,
'textColor' => null,
],
$attributes
);
}

public function test_retrieve_core_heading_with_text_color() {
Expand All @@ -296,8 +370,26 @@ public function test_retrieve_core_heading_with_text_color() {
$block = $actual['data']['post']['editorBlocks'][0];
$attributes = $block['attributes'];

$this->assertEquals( 'Heading with Text Color', $attributes['content'] );
$this->assertEquals( 'vivid-red', $attributes['textColor'] );
$this->assertEquals(
[
'align' => null,
'anchor' => null,
'backgroundColor' => null,
'className' => null,
'content' => 'Heading with Text Color',
'cssClassName' => 'wp-block-heading has-vivid-red-color has-text-color',
'fontFamily' => null,
'fontSize' => null,
'gradient' => null,
'level' => 2.0,
'lock' => null,
'placeholder' => null,
'style' => null,
'textAlign' => null,
'textColor' => 'vivid-red',
],
$attributes
);
}

public function test_retrieve_core_heading_with_font_size() {
Expand All @@ -324,8 +416,26 @@ public function test_retrieve_core_heading_with_font_size() {
$block = $actual['data']['post']['editorBlocks'][0];
$attributes = $block['attributes'];

$this->assertEquals( 'Heading with Font Size', $attributes['content'] );
$this->assertEquals( 'large', $attributes['fontSize'] );
$this->assertEquals(
[
'align' => null,
'anchor' => null,
'backgroundColor' => null,
'className' => null,
'content' => 'Heading with Font Size',
'cssClassName' => 'wp-block-heading has-large-font-size',
'fontFamily' => null,
'fontSize' => 'large',
'gradient' => null,
'level' => 2.0,
'lock' => null,
'placeholder' => null,
'style' => null,
'textAlign' => null,
'textColor' => null,
],
$attributes
);
}

public function test_retrieve_core_heading_with_class_name() {
Expand All @@ -352,7 +462,25 @@ public function test_retrieve_core_heading_with_class_name() {
$block = $actual['data']['post']['editorBlocks'][0];
$attributes = $block['attributes'];

$this->assertEquals( 'Heading with Custom Class', $attributes['content'] );
$this->assertEquals( 'custom-class', $attributes['className'] );
$this->assertEquals(
[
'align' => null,
'anchor' => null,
'backgroundColor' => null,
'className' => 'custom-class',
'content' => 'Heading with Custom Class',
'cssClassName' => 'wp-block-heading custom-class',
'fontFamily' => null,
'fontSize' => null,
'gradient' => null,
'level' => 2.0,
'lock' => null,
'placeholder' => null,
'style' => null,
'textAlign' => null,
'textColor' => null,
],
$attributes
);
}
}

0 comments on commit 9be31c6

Please sign in to comment.