@@ -328,6 +328,30 @@ public function data_generate_font_size_preset_fixtures() {
328328 'expected_output ' => '28px ' ,
329329 ),
330330
331+ 'size: int 0 ' => array (
332+ 'font_size_preset ' => array (
333+ 'size ' => 0 ,
334+ ),
335+ 'should_use_fluid_typography ' => true ,
336+ 'expected_output ' => 0 ,
337+ ),
338+
339+ 'size: string 0 ' => array (
340+ 'font_size_preset ' => array (
341+ 'size ' => '0 ' ,
342+ ),
343+ 'should_use_fluid_typography ' => true ,
344+ 'expected_output ' => '0 ' ,
345+ ),
346+
347+ 'default_return_value_when_size_is_undefined ' => array (
348+ 'font_size_preset ' => array (
349+ 'size ' => null ,
350+ ),
351+ 'should_use_fluid_typography ' => false ,
352+ 'expected_output ' => null ,
353+ ),
354+
331355 'default_return_value_when_fluid_is_false ' => array (
332356 'font_size_preset ' => array (
333357 'size ' => '28px ' ,
@@ -363,6 +387,30 @@ public function data_generate_font_size_preset_fixtures() {
363387 'expected_output ' => 'clamp(1.3125rem, 1.3125rem + ((1vw - 0.48rem) * 2.524), 2.625rem) ' ,
364388 ),
365389
390+ 'return_fluid_value_with_floats_with_units ' => array (
391+ 'font_size_preset ' => array (
392+ 'size ' => '100.175px ' ,
393+ ),
394+ 'should_use_fluid_typography ' => true ,
395+ 'expected_output ' => 'clamp(75.13125px, 4.695703125rem + ((1vw - 7.68px) * 9.03), 150.2625px) ' ,
396+ ),
397+
398+ 'return_fluid_value_with_integer_coerced_to_px ' => array (
399+ 'font_size_preset ' => array (
400+ 'size ' => 33 ,
401+ ),
402+ 'should_use_fluid_typography ' => true ,
403+ 'expected_output ' => 'clamp(24.75px, 1.546875rem + ((1vw - 7.68px) * 2.975), 49.5px) ' ,
404+ ),
405+
406+ 'return_fluid_value_with_float_coerced_to_px ' => array (
407+ 'font_size_preset ' => array (
408+ 'size ' => 100.23 ,
409+ ),
410+ 'should_use_fluid_typography ' => true ,
411+ 'expected_output ' => 'clamp(75.1725px, 4.69828125rem + ((1vw - 7.68px) * 9.035), 150.345px) ' ,
412+ ),
413+
366414 'return_default_fluid_values_with_empty_fluid_array ' => array (
367415 'font_size_preset ' => array (
368416 'size ' => '28px ' ,
@@ -583,4 +631,121 @@ public function data_generate_replace_inline_font_styles_with_fluid_values_fixtu
583631 ),
584632 );
585633 }
634+
635+ /**
636+ * Tests that valid font size values are parsed.
637+ *
638+ * @ticket 56467
639+ *
640+ * @covers ::wp_get_typography_value_and_unit
641+ *
642+ * @dataProvider data_valid_size_wp_get_typography_value_and_unit
643+ *
644+ * @param mixed $raw_value Raw size value to test.
645+ * @param mixed $expected An expected return value.
646+ */
647+ public function test_valid_size_wp_get_typography_value_and_unit ( $ raw_value , $ expected ) {
648+ $ this ->assertEquals ( $ expected , wp_get_typography_value_and_unit ( $ raw_value ) );
649+ }
650+
651+ /**
652+ * Data provider.
653+ *
654+ * @return array
655+ */
656+ public function data_valid_size_wp_get_typography_value_and_unit () {
657+ return array (
658+ 'size: 10vh with default units do not match ' => array (
659+ 'raw_value ' => '10vh ' ,
660+ 'expected ' => null ,
661+ ),
662+ 'size: calc() values do not match ' => array (
663+ 'raw_value ' => 'calc(2 * 10px) ' ,
664+ 'expected ' => null ,
665+ ),
666+ 'size: clamp() values do not match ' => array (
667+ 'raw_value ' => 'clamp(15px, 0.9375rem + ((1vw - 7.68px) * 5.409), 60px) ' ,
668+ 'expected ' => null ,
669+ ),
670+ 'size: `"10"` ' => array (
671+ 'raw_value ' => '10 ' ,
672+ 'expected ' => array (
673+ 'value ' => 10 ,
674+ 'unit ' => 'px ' ,
675+ ),
676+ ),
677+ 'size: `11` ' => array (
678+ 'raw_value ' => 11 ,
679+ 'expected ' => array (
680+ 'value ' => 11 ,
681+ 'unit ' => 'px ' ,
682+ ),
683+ ),
684+ 'size: `11.234` ' => array (
685+ 'raw_value ' => '11.234 ' ,
686+ 'expected ' => array (
687+ 'value ' => 11.234 ,
688+ 'unit ' => 'px ' ,
689+ ),
690+ ),
691+ 'size: `"12rem"` ' => array (
692+ 'raw_value ' => '12rem ' ,
693+ 'expected ' => array (
694+ 'value ' => 12 ,
695+ 'unit ' => 'rem ' ,
696+ ),
697+ ),
698+ 'size: `"12px"` ' => array (
699+ 'raw_value ' => '12px ' ,
700+ 'expected ' => array (
701+ 'value ' => 12 ,
702+ 'unit ' => 'px ' ,
703+ ),
704+ ),
705+ 'size: `"12em"` ' => array (
706+ 'raw_value ' => '12em ' ,
707+ 'expected ' => array (
708+ 'value ' => 12 ,
709+ 'unit ' => 'em ' ,
710+ ),
711+ ),
712+ 'size: `"12.74em"` ' => array (
713+ 'raw_value ' => '12.74em ' ,
714+ 'expected ' => array (
715+ 'value ' => 12.74 ,
716+ 'unit ' => 'em ' ,
717+ ),
718+ ),
719+ );
720+ }
721+
722+ /**
723+ * Tests that invalid font size values are not parsed and trigger incorrect usage.
724+ *
725+ * @ticket 56467
726+ *
727+ * @covers ::wp_get_typography_value_and_unit
728+ *
729+ * @dataProvider data_invalid_size_wp_get_typography_value_and_unit
730+ * @expectedIncorrectUsage wp_get_typography_value_and_unit
731+ *
732+ * @param mixed $raw_value Raw size value to test.
733+ */
734+ public function test_invalid_size_wp_get_typography_value_and_unit ( $ raw_value ) {
735+ $ this ->assertNull ( wp_get_typography_value_and_unit ( $ raw_value ) );
736+ }
737+
738+ /**
739+ * Data provider.
740+ *
741+ * @return array
742+ */
743+ public function data_invalid_size_wp_get_typography_value_and_unit () {
744+ return array (
745+ 'size: null ' => array ( null ),
746+ 'size: false ' => array ( false ),
747+ 'size: true ' => array ( true ),
748+ 'size: array ' => array ( array ( '10 ' ) ),
749+ );
750+ }
586751}
0 commit comments