Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions tests/phpunit/tests/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,31 @@ public function data_get_slug_from_attribute() {
* @covers ::render_duotone_support
*/
public function test_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();
$block_css_declarations_property = new ReflectionProperty( 'WP_Duotone', 'block_css_declarations' );
$block_css_declarations_property->setAccessible( true );
$block_css_declarations_property->setValue( $wp_block, array() );
$previous_value = $block_css_declarations_property->getValue();
$block_css_declarations_property->setValue( $wp_duotone, array() );

WP_Duotone::render_duotone_support( '', $block, $wp_block );
$actual = $block_css_declarations_property->getValue();
// Reset the property's visibility.

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

$this->assertNotEmpty( $actual );
Expand Down