Make WordPress Core

Changeset 57652


Ignore:
Timestamp:
02/18/2024 02:57:23 PM (3 years ago)
Author:
swissspidy
Message:

Editor: Prevent PHP warning when parsing duotone hue values.

Props jacobcassidy, rahmohn, mukesh27.
Fixes #59496.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-duotone.php

    r57135 r57652  
    210210                );
    211211
    212                 $factor = $angle_units[ $unit ];
    213                 if ( ! $factor ) {
    214                         $factor = 1;
    215                 }
     212                $factor = isset( $angle_units[ $unit ] ) ? $angle_units[ $unit ] : 1;
    216213
    217214                return (float) $value * $factor;
  • trunk/tests/phpunit/tests/block-supports/duotone.php

    r57062 r57652  
    66 * @group block-supports
    77 *
    8  * @package WordPress
     8 * @coversDefaultClass WP_Duotone
    99 */
    1010
     
    167167                );
    168168        }
     169
     170        /**
     171         * @dataProvider data_colord_parse_hue
     172         * @ticket 59496
     173         */
     174        public function test_colord_parse_hue( $value, $unit, $expected ) {
     175                $reflection = new ReflectionMethod( 'WP_Duotone', 'colord_parse_hue' );
     176                $reflection->setAccessible( true );
     177
     178                $this->assertSame( $expected, $reflection->invoke( null, $value, $unit ) );
     179        }
     180
     181        /**
     182         * Data provider.
     183         *
     184         * @return array[].
     185         */
     186        public function data_colord_parse_hue() {
     187                return array(
     188                        'deg-angle-unit'                => array( 120, 'deg', 120.0 ),
     189                        'grad-angle-unit'               => array( 120, 'grad', 108.0 ),
     190                        'turn-angle-unit'               => array( 120, 'turn', 43200.0 ),
     191                        'rad-angle-unit'                => array( 120, 'rad', 6875.493541569878 ),
     192                        'empty-angle-unit'              => array( 120, '', 120.0 ),
     193                        'invalid-angle-unit'            => array( 120, 'invalid', 120.0 ),
     194                        'negative-value-deg-angle-unit' => array( -120, 'deg', -120.0 ),
     195                );
     196        }
    169197}
Note: See TracChangeset for help on using the changeset viewer.