diff --git a/src/wp-includes/class-wp-duotone.php b/src/wp-includes/class-wp-duotone.php index 194b649843..40e9f7548b 100644 --- a/src/wp-includes/class-wp-duotone.php +++ b/src/wp-includes/class-wp-duotone.php @@ -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; } diff --git a/tests/phpunit/tests/block-supports/duotone.php b/tests/phpunit/tests/block-supports/duotone.php index faeeaa2b40..5a31dc9362 100644 --- a/tests/phpunit/tests/block-supports/duotone.php +++ b/tests/phpunit/tests/block-supports/duotone.php @@ -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 ), + ); + } }