Editor: Prevent PHP warning when parsing duotone hue values.

Props jacobcassidy, rahmohn, mukesh27.
Fixes #59496.

git-svn-id: https://develop.svn.wordpress.org/trunk@57652 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2024-02-18 14:57:23 +00:00
parent a1d6aa3644
commit ba644b94df
2 changed files with 30 additions and 5 deletions

View File

@ -209,10 +209,7 @@ class WP_Duotone {
'rad' => 360 / ( M_PI * 2 ),
);
$factor = $angle_units[ $unit ];
if ( ! $factor ) {
$factor = 1;
}
$factor = isset( $angle_units[ $unit ] ) ? $angle_units[ $unit ] : 1;
return (float) $value * $factor;
}

View File

@ -5,7 +5,7 @@
*
* @group block-supports
*
* @package WordPress
* @coversDefaultClass WP_Duotone
*/
class Tests_Block_Supports_Duotone extends WP_UnitTestCase {
@ -166,4 +166,32 @@ class Tests_Block_Supports_Duotone extends WP_UnitTestCase {
'invalid' => array( 'not a valid attribute', false ),
);
}
/**
* @dataProvider data_colord_parse_hue
* @ticket 59496
*/
public function test_colord_parse_hue( $value, $unit, $expected ) {
$reflection = new ReflectionMethod( 'WP_Duotone', 'colord_parse_hue' );
$reflection->setAccessible( true );
$this->assertSame( $expected, $reflection->invoke( null, $value, $unit ) );
}
/**
* Data provider.
*
* @return array[].
*/
public function data_colord_parse_hue() {
return array(
'deg-angle-unit' => array( 120, 'deg', 120.0 ),
'grad-angle-unit' => array( 120, 'grad', 108.0 ),
'turn-angle-unit' => array( 120, 'turn', 43200.0 ),
'rad-angle-unit' => array( 120, 'rad', 6875.493541569878 ),
'empty-angle-unit' => array( 120, '', 120.0 ),
'invalid-angle-unit' => array( 120, 'invalid', 120.0 ),
'negative-value-deg-angle-unit' => array( -120, 'deg', -120.0 ),
);
}
}