Skip to content

Commit

Permalink
Update tests to be like the ones in Core
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Nov 2, 2023
1 parent 14c1de0 commit 59d098e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions phpunit/class-wp-duotone-test.php
Expand Up @@ -48,22 +48,39 @@ public function test_gutenberg_render_duotone_support_custom() {

/**
* Tests whether the CSS declarations are generated even if the block content is
* empty. We need this to make the CSS output stable across paginations for
* empty. This is needed to make the CSS output stable across paginations for
* features like the enhanced pagination of the Query block.
*
* @covers ::render_duotone_support
*/
public function test_gutenberg_css_declarations_are_generated_even_with_empty_block_content() {
$block = array(
$block = array(
'blockName' => 'core/image',
'attrs' => array( 'style' => array( 'color' => array( 'duotone' => 'var:preset|duotone|blue-orange' ) ) ),
);
$wp_block = new WP_Block( $block );
$wp_block = new WP_Block( $block );

/*
* Handling to access the static WP_Duotone::$block_css_declarations property.
*
* Why is an instance needed?
* WP_Duotone is a static class by design, meaning it only contains static properties and methods.
* In production, it should not be instantiated. However, as of PHP 8.3, ReflectionProperty::setValue()
* needs an object.
*/
$wp_duotone = new WP_Duotone_Gutenberg();
$block_css_declarations_property = new ReflectionProperty( 'WP_Duotone_Gutenberg', 'block_css_declarations' );
$block_css_declarations_property->setAccessible( true );
$block_css_declarations_property->setValue( array() );
$previous_value = $block_css_declarations_property->getValue();
$block_css_declarations_property->setValue( $wp_duotone, array() );
WP_Duotone_Gutenberg::render_duotone_support( '', $block, $wp_block );
$this->assertNotEmpty( $block_css_declarations_property->getValue() );
$actual = $block_css_declarations_property->getValue();

// Reset the property.
$block_css_declarations_property->setValue( $wp_duotone, $previous_value );
$block_css_declarations_property->setAccessible( false );

$this->assertNotEmpty( $actual );
}

public function data_get_slug_from_attribute() {
Expand Down

0 comments on commit 59d098e

Please sign in to comment.