使WordPress成为核心

变更集58171


忽略:
时间戳:
2024年5月18日下午11:16:09(5周(之前)
作者:
isabel_监狱
消息:

编辑器:将流体排版theme.json设置传递给wp_get_typography_font_size_value(获取打印字体大小值).

更新wp_get_typography_font_size_value(获取打印字体大小值)接受一个theme.json设置数组,而不是从全局状态派生的布尔值。

道具ramonopoly,audrasjb。
修复#61118.

位置:
大旅行箱
文件夹:
4已编辑

图例:

未修改
补充
远离的
  • 主干/src/wp-includes/block-supports/typeography.php

    57329兰特 r58171  
    499499*@自6.3.0起使用layout.wideSize作为最大视区宽度,使用对数比例因子计算最小字体比例。
    500500*@自6.4.0起,在typeography.fluid theme.json模式中添加了可配置的最小和最大视口宽度值。
    501  *
    502 *@param数组$preset{
     501*@自6.6.0以来已弃用bool参数$should_use_fluid_typography。
     502 *
     503*@param数组$preset{
    503504*必需。fontSizes预设值,如theme.json中所示。
    504505 *
     
    507508*@type string | int | float$size CSS font-size值,包括单位(如果适用)。
    508509 * }
    509 *@param bool$should_use_fluid_typrography将流体排版“打开”的覆盖。可用于单元测试.
    510  *                                          默认值为false。
     510*@param bool|array$settings可选主题JSON设置数组,覆盖任何全局主题设置.
     511 *                             默认值为false。
    511512*@return string | null Font-size值或null(如果$preset中未传递大小)。
    512513 */
    513 函数wp_get_typography_font_size_value($preset,$should_use_fluid_typrography=false){
     514
     515
     516函数wp_get_typography_font_size_value($preset,$settings=array()){
    514517if(!isset($preset['size']){
    515518返回null;
     
    524527    }
    525528
    526 //检查是否激活了流体字体大小。
    527 $global_settings=wp_get_global_settings();
    528 $typegraphy_settings=isset($global_settings[“打印”])$全局设置[“打印”]:数组();
    529 $layout_settings=设置($global_settings['layout'])$全局设置[布局]:数组();
    530 
    531 如果(
    532 isset($typegraphy_settings['fluid'])&&
    533 (true===$printing_settings['fluid']|| is_array($printing_settings['fluid']))
    534     ) {
    535 $should_use_fluid_typrography=true;
    536     }
     529    /*
     530*作为一个布尔值(自6.6以来已被弃用),$settings可以替代流体排版“on”(`true`)或“off”(`false`)。
     531     */
     532if(is_bool($settings)){
     533_deprecated_argument(__FUNCTION__,'6.6.0',__(第二个参数`$settings`的'boolean`类型已弃用。请改用`array()`。'));
     534$settings=数组(
     535“排版”=>数组(
     536“流体”=>$设置,
     537            ),
     538        );
     539    }
     540
     541//返回到默认的全局设置。
     542$global_settings=wp_get_global_settings();
     543$设置=wp_parse_args(
     544$设置,
     545$global_settings(全局设置)
     546    );
     547
     548$typeography_settings=设置($settings['typeographic'])$settings[“打印”]:数组();
     549$should_use_fluid_typrography=!空($typegraphy_settings['fluid']);
    537550
    538551if(!$应该使用流体排版){
     
    540553    }
    541554
    542    $fluid_settings=isset($typegraphy_settings['fluid'])&&is_array($typeraphy_settings['fluid'])
    543        ? $typegraphy_settings[“流体”]
    544       :数组();
     555   //$typeography_settings['fluid']可以是bool或数组。规格化为数组。
     556   $fluid_settings=是数组($typeography_settings['fluid'])$typeography_settings['fluid']:数组();
     557   $layout_settings=设置($settings['layout'])$设置['layout']:array();
    545558
    546559//默认值。
  • trunk/src/wp-includes/class-wp-theme-json.php

    58123兰特 r58171  
    18321832     *
    18331833*@自5.9.0起
     1834*@since 6.6.0将$settings传递给static::PRESETS_METADATA中定义的回调。
    18341835     *
    18351836*@param array$settings要处理的设置。
     
    18581859                ) {
    18591860$value_func=$preset_metadata['value_func'];
    1860 $value=call_user_func($value_func,$preset);
     1861$value=call_user_func($value_func,$preset,$设置);
    18611862}其他{
    18621863//如果没有值,则不要将其添加到结果中。
     
    20512052*@自6.1.0起添加了`$theme_json`、`$selector`和`$use_root_padding`参数。
    20522053*@since 6.5.0设置“aspect-ratio”时,输出“min-height:unset”规则。
     2054*@since 6.6.0将当前主题JSON设置传递给wp_get_typography_font_size_value()。
    20532055     *
    20542056*@param数组$styles要处理的样式。
     
    21182120*已有clamp()函数的值将无法通过测试,
    21192121*,因此将返回原始的$值。
     2122*传递当前的theme_json设置以覆盖任何全局设置。
    21202123                 */
    2121 $value=wp_get_typography_font_size_value(数组(“大小”=>$value));
     2124$value=wp_get_typography_font_size_value(数组(“大小”=>$value),$设置);
    21222125            }
    21232126
  • 主干/tests/phpunit/tests/block-supports/typeography.php

    57329卢比 r58171  
    295295*@门票57065
    296296*@票58523
     297*@票61118
    297298     *
    298299*@covers::wp_get_typography_font_size_value
     
    300301*@dataProvider data_generate_font_size_preset_fixtures
    301302     *
    302 *@param数组$font_size_preset           {
     303*@param数组$font_size_preset{
    303304*必需。fontSizes预设值,如theme.json中所示。
     305     *
     306*@type string$name字体大小预设的名称。
     307*@type string$slug Kebab-case字体大小预设的唯一标识符。
     308*@type string$size CSS font-size值,包括适用的单位。
     309     * }
     310*@param bool$settings覆盖任何全局主题设置的主题JSON设置数组。
     311*@param string$expected_output预期输出。
     312     */
     313公共函数test_wp_get_typography_font_size_value($font_size_preset,$settings,$expected_output){
     314$actual=wp_get_typography_font_size_value($font_size_preset,$settings);
     315
     316$this->assertSame($expected_output,$actual);
     317    }
     318
     319    /**
     320*数据提供商。
     321     *
     322*@return数组
     323     */
     324公共函数data_generate_font_size_preset_fixtures(){
     325返回数组(
     326'当流体排版被停用时返回值'=>数组(
     327“font_size_preset”=>数组(
     328“大小”=>“28px”,
     329                ),
     330“settings”=>空,
     331“expected_output”=>“28px”,
     332            ),
     333
     334'返回字体大小为0的值'=>数组(
     335“font_size_preset”=>数组(
     336“大小”=>0,
     337                ),
     338“settings”=>数组(
     339“排版”=>数组(
     340“流体”=>真,
     341                    ),
     342                ),
     343'预期输出'=>0,
     344            ),
     345
     346“返回字体大小为“0”的值”=>数组(
     347“font_size_preset”=>数组(
     348“大小”=>“0”,
     349                ),
     350“settings”=>数组(
     351“排版”=>数组(
     352“流体”=>真,
     353                    ),
     354                ),
     355“expected_output”=>“0”,
     356            ),
     357
     358'返回值,其中“size”为“null”=>数组(
     359“font_size_preset”=>数组(
     360“大小”=>空,
     361                ),
     362“settings”=>空,
     363“expected_output”=>空,
     364            ),
     365
     366'当流体为“false”=>数组时返回值(
     367“font_size_preset”=>数组(
     368“大小”=>“28px”,
     369“流体”=>错误,
     370                ),
     371“settings”=>数组(
     372“排版”=>数组(
     373“流体”=>假,
     374                    ),
     375                ),
     376“expected_output”=>“28px”,
     377            ),
     378'当流体为空数组时返回值'=>数组(
     379“font_size”=>数组(
     380“大小”=>“28px”,
     381                ),
     382“settings”=>数组(
     383“排版”=>数组(
     384“流体”=>阵列(),
     385                    ),
     386                ),
     387“expected_output”=>“28px”,
     388            ),
     389'返回带有minViewportWidth覆盖的钳制值'=>数组(
     390“font_size”=>数组(
     391'size'=>'28px',
     392                ),
     393“settings”=>数组(
     394“排版”=>数组(
     395“fluid”=>数组(
     396“minViewportWidth”=>“500px”,
     397                        ),
     398                    ),
     399                ),
     400“预期输出”=>“夹具(17.905px,1.119rem+((1vw-5px)*0.918),28px)”,
     401            ),
     402'使用maxViewportWidth覆盖返回clamp值'=>数组(
     403“font_size”=>数组(
     404“大小”=>“28px”,
     405                ),
     406“settings”=>数组(
     407“排版”=>数组(
     408“fluid”=>数组(
     409“maxViewportWidth”=>“500px”,
     410                        ),
     411                    ),
     412                ),
     413“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*5.608),28px)”,
     414            ),
     415
     416'返回带有layout.wideSize覆盖的clamp值'=>数组(
     417“font_size”=>数组(
     418“大小”=>“28px”,
     419                ),
     420“settings”=>数组(
     421“排版”=>数组(
     422“流体”=>真,
     423                    ),
     424“layout”=>数组(
     425“wideSize”=>“500px”,
     426                    ),
     427                ),
     428“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*5.608),28px)”,
     429            ),
     430“返回已被钳制的值”=>数组(
     431“font_size_preset”=>数组(
     432“尺寸”=>“夹钳(21px,1.313rem+((1vw-7.68px)*2.524),42px)”,
     433“流体”=>假,
     434                ),
     435“settings”=>数组(
     436“排版”=>数组(
     437“流体”=>真,
     438                    ),
     439                ),
     440“预期输出”=>“夹钳(21px,1.313rem+((1vw-7.68px)*2.524),42px)”,
     441            ),
     442
     443“返回带有不支持单位的值”=>数组(
     444“font_size_preset”=>数组(
     445“大小”=>“1000%”,
     446“流体”=>假,
     447                ),
     448“settings”=>数组(
     449“排版”=>数组(
     450“流体”=>真,
     451                    ),
     452                ),
     453“预期输出”=>“1000%”,
     454            ),
     455
     456'返回带有rem最小和最大单位的钳制值'=>数组(
     457“font_size_preset”=>数组(
     458“大小”=>“1.75rem”,
     459                ),
     460“settings”=>数组(
     461“排版”=>数组(
     462“流体”=>真,
     463                    ),
     464                ),
     465“预期输出”=>“夹具(1.119rem,1.119rem+((1vw-0.2rem)*0.789),1.75rem)”,
     466            ),
     467
     468'使用em最小和最大单位返回钳制值'=>数组(
     469“font_size”=>数组(
     470“大小”=>“1.75em”,
     471                ),
     472“settings”=>数组(
     473“排版”=>数组(
     474“流体”=>真,
     475                    ),
     476                ),
     477“预期输出”=>“夹具(1.119em,1.119rem+((1vw-0.2em)*0.789),1.75em)”,
     478            ),
     479
     480“返回浮点的钳制值”=>数组(
     481“font_size”=>数组(
     482“大小”=>“70.175px”,
     483                ),
     484“settings”=>数组(
     485“排版”=>数组(
     486“流体”=>真,
     487                    ),
     488                ),
     489“预期输出”=>“夹具(37.897px,2.369rem+((1vw-3.2px)*2.522),70.175px)”,
     490            ),
     491
     492'将整数强制为'px'并返回clamp value'=>数组(
     493“font_size_preset”=>数组(
     494“大小”=>33,
     495                ),
     496“settings”=>数组(
     497“排版”=>数组(
     498“流体”=>真,
     499                    ),
     500                ),
     501“预期输出”=>“夹钳(20.515px,1.282rem+((1vw-3.2px)*0.975),33px)”,
     502            ),
     503
     504'将float强制为`px'并返回clamp value'=>数组(
     505“font_size_preset”=>数组(
     506“大小”=>70.175,
     507                ),
     508“settings”=>数组(
     509“排版”=>数组(
     510“流体”=>真,
     511                    ),
     512                ),
     513“预期输出”=>“夹具(37.897px,2.369rem+((1vw-3.2px)*2.522),70.175px)”,
     514            ),
     515
     516'当'fluid'为空时返回箝位值array'=>array(
     517“font_size_preset”=>数组(
     518“大小”=>“28px”,
     519“流体”=>阵列(),
     520                ),
     521“settings”=>数组(
     522“排版”=>数组(
     523“流体”=>真,
     524                    ),
     525                ),
     526“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*0.789),28px)”,
     527            ),
     528
     529'在“fluid”为“null”=>数组时返回钳制值(
     530“font_size_preset”=>数组(
     531“大小”=>“28px”,
     532“fluid”=>空,
     533                ),
     534“settings”=>数组(
     535“排版”=>数组(
     536“流体”=>真,
     537                    ),
     538                ),
     539“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*0.789),28px)”,
     540            ),
     541
     542'返回定义了最小和最大流体值的钳制值'=>数组(
     543“font_size”=>数组(
     544“大小”=>“80px”,
     545“fluid”=>数组(
     546“最小值”=>“70px”,
     547“最大值”=>“125px”,
     548                    ),
     549                ),
     550“设置”=>数组(
     551“排版”=>数组(
     552“流体”=>真,
     553                    ),
     554                ),
     555“预期输出”=>“夹具(70px,4.375rem+((1vw-3.2px)*4.297),125px)”,
     556            ),
     557
     558'返回最大值等于大小的钳制值'=>数组(
     559“font_size”=>数组(
     560“大小”=>“7.8125rem”,
     561“fluid”=>数组(
     562“最小值”=>“4.375rem”,
     563“最大”=>“7.8125rem”,
     564                    ),
     565                ),
     566“settings”=>数组(
     567“排版”=>数组(
     568“流体”=>真,
     569                    ),
     570                ),
     571“预期输出”=>“夹具(4.375rem,4.375雷姆+((1vw-0.2rem)*4.298),7.8125rem)”,
     572            ),
     573
     574'如果最小字体大小大于最大字体大小,则返回钳制值'=>数组(
     575“font_size_preset”=>数组(
     576“大小”=>“3rem”,
     577“fluid”=>数组(
     578“最小值”=>“5rem”,
     579“最大值”=>“32px”,
     580                    ),
     581                ),
     582“settings”=>数组(
     583“排版”=>数组(
     584“流体”=>真,
     585                    ),
     586                ),
     587“预期输出”=>“夹具(5rem,5rem+((1vw-0.2rem)*-3.75),32px)”,
     588            ),
     589
     590“返回具有无效最小/最大流体单位的值”=>数组(
     591“font_size_preset”=>数组(
     592“大小”=>“10em”,
     593“fluid”=>数组(
     594“最小值”=>“20vw”,
     595“最大值”=>“50%”,
     596                    ),
     597                ),
     598“settings”=>数组(
     599“排版”=>数组(
     600“流体”=>真,
     601                    ),
     602                ),
     603“expected_output”=>“10em”,
     604            ),
     605
     606'当大小小于下限且未设置流体最小值/最大值时返回值'=>数组(
     607“font_size_preset”=>数组(
     608“大小”=>“3px”,
     609                ),
     610“settings”=>数组(
     611“排版”=>数组(
     612“流体”=>真,
     613                    ),
     614                ),
     615'预期输出'=>'3px',
     616            ),
     617
     618'当大小等于下限且未设置流体最小值/最大值时返回值'=>数组(
     619“font_size”=>数组(
     620“大小”=>“14px”,
     621                ),
     622“settings”=>数组(
     623“排版”=>数组(
     624“流体”=>真,
     625                    ),
     626                ),
     627“预期输出”=>“14px”,
     628            ),
     629
     630'返回具有不同最小最大单位的钳制值'=>数组(
     631“font_size_preset”=>数组(
     632“大小”=>“28px”,
     633“fluid”=>数组(
     634“最小值”=>“20px”,
     635“最大”=>“50rem”,
     636                    ),
     637                ),
     638“settings”=>数组(
     639“排版”=>数组(
     640“流体”=>真,
     641                    ),
     642                ),
     643“预期输出”=>“夹具(20px,1.25rem+((1vw-3.2px)*60.938),50rem)”,
     644            ),
     645
     646'返回未设置流体最大大小的钳制值'=>数组(
     647“font_size_preset”=>数组(
     648“大小”=>“50px”,
     649“fluid”=>数组(
     650“最小值”=>“2.6雷姆”,
     651                    ),
     652                ),
     653“settings”=>数组(
     654“排版”=>数组(
     655“流体”=>真,
     656                    ),
     657                ),
     658“预期输出”=>“夹具(2.6rem,2.6rem+((1vw-0.2rem)*0.656),50px)”,
     659            ),
     660
     661'返回未设置流体最小大小的钳制值'=>数组(
     662“font_size_preset”=>数组(
     663“大小”=>“28px”,
     664“fluid”=>数组(
     665“最大值”=>“80px”,
     666                    ),
     667                ),
     668“settings”=>数组(
     669“排版”=>数组(
     670“流体”=>真,
     671                    ),
     672                ),
     673“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*4.851),80px)”,
     674            ),
     675
     676“设置流体值时不应应用下限测试”=>数组(
     677“font_size_preset”=>数组(
     678“大小”=>“1.5rem”,
     679“fluid”=>数组(
     680“最小值”=>“0.5雷姆”,
     681“最大值”=>“5rem”,
     682                    ),
     683                ),
     684“settings”=>数组(
     685“排版”=>数组(
     686“流体”=>真,
     687                    ),
     688                ),
     689“预期输出”=>“夹具(0.5rem,0.5rem+((1vw-0.2rem)*5.625),5rem)”,
     690            ),
     691
     692“当仅设置流体最小值时,不应应用下限测试”=>数组(
     693“font_size”=>数组(
     694“大小”=>“20px”,
     695“fluid”=>数组(
     696“最小值”=>“12px”,
     697                    ),
     698                ),
     699“settings”=>数组(
     700“排版”=>数组(
     701“流体”=>真,
     702                    ),
     703                ),
     704“预期输出”=>“夹具(12px,0.75rem+((1vw-3.2px)*0.625),20px)”,
     705            ),
     706
     707“仅设置了fluid max时不应应用下限测试”=>数组(
     708“font_size”=>数组(
     709“大小”=>“0.875rem”,
     710“fluid”=>数组(
     711“最大值”=>“20rem”,
     712                    ),
     713                ),
     714“settings”=>数组(
     715“排版”=>数组(
     716“流体”=>真,
     717                    ),
     718                ),
     719“预期输出”=>“夹具(0.875rem,0.875rem+((1vw-0.2rem)*23.906),20rem)”,
     720            ),
     721
     722'当最小和最大字体大小相等时返回钳制值'=>数组(
     723“font_size_preset”=>数组(
     724“大小”=>“4rem”,
     725“fluid”=>数组(
     726“最小值”=>“30px”,
     727“最大值”=>“30px”,
     728                    ),
     729                ),
     730“settings”=>数组(
     731“排版”=>数组(
     732“流体”=>真,
     733                    ),
     734                ),
     735“预期输出”=>“夹具(30px,1.875rem+((1vw-3.2px)*1),30px)”,
     736            ),
     737
     738'当未设置自定义最小字体大小时,应为em值应用缩放的最小字体大小'=>数组(
     739“font_size”=>数组(
     740“大小”=>“12rem”,
     741                ),
     742“设置”=>数组(
     743“排版”=>数组(
     744“流体”=>真,
     745                    ),
     746                ),
     747“预期输出”=>“夹具(5.174rem,5.174rem+((1vw-0.2rem)*8.533),12rem)”,
     748            ),
     749
     750'当未设置自定义最小字体大小时,应为px值应用缩放的最小字体大小'=>数组(
     751“font_size”=>数组(
     752“大小”=>“200px”,
     753                ),
     754“设置”=>数组(
     755“排版”=>数组(
     756“流体”=>真,
     757                    ),
     758                ),
     759“预期输出”=>“夹具(85.342px,5.334rem+((1vw-3.2px)*8.958),200px)”,
     760            ),
     761
     762“当设置自定义最小字体大小时,不应将缩放的最小字体大小应用于最小字体大小”=>数组(
     763“font_size”=>数组(
     764“大小”=>“200px”,
     765“fluid”=>数组(
     766“最小值”=>“100px”,
     767                    ),
     768                ),
     769“设置”=>数组(
     770“排版”=>数组(
     771“流体”=>真,
     772                    ),
     773                ),
     774“预期输出”=>“夹具(100px,6.25rem+((1vw-3.2px)*7.813),200px)”,
     775            ),
     776        );
     777    }
     778
     779    /**
     780*测试弃用的第二个参数$should_use_fluid_typography的向后兼容性。
     781     *
     782*@票61118
     783     *
     784*@covers::wp_get_typography_font_size_value
     785     *
     786*@expected弃用wp_get_typography_font_size_value
     787     *
     788*@dataProvider data_generate_font_size_preset_should_use_fluid_typography_deprecated_fixtures
     789     *
     790*@param数组$font_size{
     791*必需。在theme.json中看到的fontSizes预设格式中表示的字体大小。
    304792     *
    305793*@type string$name字体大小预设的名称。
     
    308796     * }
    309797*@param bool$should_use_fluid_typrography将流体排版切换为“on”的覆盖。可用于单元测试。
    310 *@param字符串$expected_output预期输出.
    311      */
    312 公共函数test_wp_get_typography_font_size_value($font_size_preset,$should_use_fluid_typography,$expected_output){
    313 $actual=wp_get_typography_font_size_value($font_size_预设,$should_use_fluid_typrography);
     798*@param字符串$expected_outputwp_get_typography_font_size_value()的预期输出.
     799     */
     800公共函数test_wp_get_typography_font_size_value_should_use_fluid_typrography_不推荐($font_size,$should_use_fluid_typography,$expected_output){
     801$actual=wp_get_typography_font_size_value($font_size,$should_use_fluid_typrography);
    314802
    315803$this->assertSame($expected_output,$actual);
     
    317805
    318806    /**
    319 *数据提供商.
     807*数据提供商对于test_wp_get_typography_font_size_value_should_use_fluid_typograph_deprecated.
    320808     *
    321809*@return数组
    322810     */
    323 公共函数data_generate_font_size_preset_固定装置(){
     811公共函数data_generate_font_size_preset_应该使用流体排版不推荐使用_夹具(){
    324812返回数组(
    325813'当流体排版被停用时返回值'=>数组(
    326 '字体_大小_预设'=>数组(
     814'字体_大小'       =>数组(
    327815“大小”=>“28px”,
    328816                ),
     
    330818“expected_output”=>“28px”,
    331819            ),
    332 
    333 '返回字体大小为0的值'=>数组(
    334 “font_size_preset”=>数组(
    335 “大小”=>0,
    336                 ),
    337 “should_use_fluid_typography”=>true,
    338 '预期输出'=>0,
    339             ),
    340 
    341 “返回字体大小为“0”的值”=>数组(
    342 “font_size_preset”=>数组(
    343 “大小”=>“0”,
    344                 ),
    345 “should_use_fluid_typrography”=>true,
    346 “expected_output”=>“0”,
    347             ),
    348 
    349 '返回值,其中“size”为“null”=>数组(
    350 'font_size_preset'=>数组(
    351 “大小”=>空,
    352                 ),
    353 “should_use_fluid_typrography”=>错误,
    354 “expected_output”=>空,
    355             ),
    356 
    357 '当流体为“false”=>数组时返回值(
    358 “font_size_preset”=>数组(
    359 “大小”=>“28px”,
    360 “流体”=>假,
    361                 ),
    362 “should_use_fluid_typrography”=>true,
    363 'expected_output'=>'28px',
    364             ),
    365 
    366 “返回已被钳制的值”=>数组(
    367 “font_size_preset”=>数组(
    368 “尺寸”=>“夹钳(21px,1.313rem+((1vw-7.68px)*2.524),42px)”,
    369 “流体”=>假,
    370                 ),
    371 “should_use_fluid_typrography”=>true,
    372 “预期输出”=>“夹钳(21px,1.313rem+((1vw-7.68px)*2.524),42px)”,
    373             ),
    374 
    375 “返回带有不支持单位的值”=>数组(
    376 “font_size_preset”=>数组(
    377 “大小”=>“1000%”,
    378 “流体”=>假,
    379                 ),
    380 “should_use_fluid_typrography”=>true,
    381 “预期输出”=>“1000%”,
    382             ),
    383 
    384 '返回带有rem最小和最大单位的钳制值'=>数组(
    385 “font_size_preset”=>数组(
    386 “大小”=>“1.75rem”,
    387                 ),
    388 “should_use_fluid_typrography”=>true,
    389 “预期输出”=>“夹具(1.119rem,1.119rem+((1vw-0.2rem)*0.789),1.75rem)”,
    390             ),
    391 
    392 '使用em最小和最大单位返回钳制值'=>数组(
     820'当流体排版被激活时返回钳制值'=>数组(
    393821“font_size”=>数组(
    394 “大小”=>“1.75em”,
    395                 ),
    396 “should_use_fluid_typrography”=>true,
    397 ‘预期输出’=>‘夹钳(1.119em,1.119rem+((1vw-0.2em)*0.789),1.75em)’,
    398             ),
    399 
    400 “返回浮点的钳制值”=>数组(
    401 “font_size”=>数组(
    402 “大小”=>“70.175px”,
    403                 ),
    404 “should_use_fluid_typrography”=>true,
    405 “预期输出”=>“夹具(37.897px,2.369rem+((1vw-3.2px)*2.522),70.175px)”,
    406             ),
    407 
    408 '将整数强制为'px'并返回clamp value'=>数组(
    409 “font_size_preset”=>数组(
    410 “大小”=>33,
    411                 ),
    412 “should_use_fluid_typography”=>true,
    413 “预期输出”=>“夹钳(20.515px,1.282rem+((1vw-3.2px)*0.975),33px)”,
    414             ),
    415 
    416 '将float强制为`px'并返回clamp value'=>数组(
    417 “font_size_preset”=>数组(
    418 “大小”=>70.175,
    419                 ),
    420 “should_use_fluid_typrography”=>true,
    421 “预期输出”=>“夹具(37.897px,2.369rem+((1vw-3.2px)*2.522),70.175px)”,
    422             ),
    423 
    424 '当'fluid'为空数组'=>数组时返回钳制值(
    425 “font_size_preset”=>数组(
    426 “大小”=>“28px”,
    427 “流体”=>阵列(),
     822“大小”=>“28px”,
    428823                ),
    429824“should_use_fluid_typrography”=>true,
    430825“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*0.789),28px)”,
    431826            ),
    432 
    433 '在“fluid”为“null”=>数组时返回钳制值(
    434 “font_size_preset”=>数组(
    435 'size'=>'28px',
    436 “fluid”=>空,
    437                 ),
    438 “should_use_fluid_typrography”=>true,
    439 “预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*0.789),28px)”,
    440             ),
    441 
    442 '返回定义了最小和最大流体值的钳制值'=>数组(
    443 “font_size”=>数组(
    444 “大小”=>“80px”,
    445 “fluid”=>数组(
    446 “最小”=>“70像素”,
    447 “最大值”=>“125px”,
    448                     ),
    449                 ),
    450 “should_use_fluid_typrography”=>true,
    451 “预期输出”=>“夹具(70px,4.375rem+((1vw-3.2px)*4.297),125px)”,
    452             ),
    453 
    454 '返回最大值等于大小的钳制值'=>数组(
    455 “font_size”=>数组(
    456 “大小”=>“7.8125rem”,
    457 “fluid”=>数组(
    458 “最小值”=>“4.375rem”,
    459 “最大”=>“7.8125rem”,
    460                     ),
    461                 ),
    462 “should_use_fluid_typrography”=>true,
    463 “预期输出”=>“夹具(4.375rem,4.375雷姆+((1vw-0.2rem)*4.298),7.8125rem)”,
    464             ),
    465 
    466 '如果最小字体大小大于最大字体大小,则返回钳制值'=>数组(
    467 “font_size_preset”=>数组(
    468 “大小”=>“3rem”,
    469 “fluid”=>数组(
    470 “最小值”=>“5rem”,
    471 “最大值”=>“32px”,
    472                     ),
    473                 ),
    474 “should_use_fluid_typrography”=>true,
    475 “预期输出”=>“夹具(5rem,5rem+((1vw-0.2rem)*-3.75),32px)”,
    476             ),
    477 
    478 “返回最小/最大流体单位无效的值”=>数组(
    479 “font_size_preset”=>数组(
    480 “大小”=>“10em”,
    481 “fluid”=>数组(
    482 “最小值”=>“20vw”,
    483 “最大值”=>“50%”,
    484                     ),
    485                 ),
    486 “should_use_fluid_typrography”=>true,
    487 “expected_output”=>“10em”,
    488             ),
    489 
    490 '当大小小于下限且未设置流体最小值/最大值时返回值'=>数组(
    491 “font_size_preset”=>数组(
    492 “大小”=>“3px”,
    493                 ),
    494 “should_use_fluid_typrography”=>true,
    495 “预期输出”=>“3px”,
    496             ),
    497 
    498 '当大小等于下限并且没有流体最小值/最大值集时返回值'=>数组(
    499 “font_size”=>数组(
    500 “大小”=>“14px”,
    501                 ),
    502 “should_use_fluid_typrography”=>true,
    503 “预期输出”=>“14px”,
    504             ),
    505 
    506 '返回具有不同最小最大单位的钳制值'=>数组(
    507 “font_size_preset”=>数组(
    508 “大小”=>“28px”,
    509 “fluid”=>数组(
    510 “最小值”=>“20px”,
    511 “最大值”=>“50雷姆”,
    512                     ),
    513                 ),
    514 “should_use_fluid_typrography”=>true,
    515 “预期输出”=>“夹具(20px,1.25rem+((1vw-3.2px)*60.938),50rem)”,
    516             ),
    517 
    518 '返回未设置流体最大大小的钳制值'=>数组(
    519 “font_size_preset”=>数组(
    520 “大小”=>“50px”,
    521 “fluid”=>数组(
    522 “最小值”=>“2.6rem”,
    523                     ),
    524                 ),
    525 “should_use_fluid_typrography”=>true,
    526 “预期输出”=>“夹具(2.6rem,2.6rem+((1vw-0.2rem)*0.656),50px)”,
    527             ),
    528 
    529 '返回未设置流体最小大小的钳制值'=>数组(
    530 “font_size_preset”=>数组(
    531 “大小”=>“28px”,
    532 “fluid”=>数组(
    533 “最大值”=>“80px”,
    534                     ),
    535                 ),
    536 “should_use_fluid_typography”=>true,
    537 “预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*4.851),80px)”,
    538             ),
    539 
    540 “设置流体值时不应应用下限测试”=>数组(
    541 “font_size_preset”=>数组(
    542 “大小”=>“1.5rem”,
    543 “fluid”=>数组(
    544 “最小值”=>“0.5雷姆”,
    545 “最大值”=>“5rem”,
    546                     ),
    547                 ),
    548 “should_use_fluid_typography”=>true,
    549 “预期输出”=>“夹具(0.5rem,0.5rem+((1vw-0.2rem)*5.625),5rem)”,
    550             ),
    551 
    552 “仅设置了fluid min时不应应用下限测试”=>数组(
    553 “font_size”=>数组(
    554 “大小”=>“20px”,
    555 “fluid”=>数组(
    556 “最小值”=>“12px”,
    557                     ),
    558                 ),
    559 “should_use_fluid_typrography”=>true,
    560 “预期输出”=>“夹具(12px,0.75rem+((1vw-3.2px)*0.625),20px)”,
    561             ),
    562 
    563 “仅设置了fluid max时不应应用下限测试”=>数组(
    564 'font_size'=>数组(
    565 “大小”=>“0.875rem”,
    566 “fluid”=>数组(
    567 “最大值”=>“20rem”,
    568                     ),
    569                 ),
    570 “should_use_fluid_typrography”=>true,
    571 “预期输出”=>“夹具(0.875rem,0.875rem+((1vw-0.2rem)*23.906),20rem)”,
    572             ),
    573 
    574 '当最小和最大字体大小相等时返回钳制值'=>数组(
    575 “font_size_preset”=>数组(
    576 “大小”=>“4rem”,
    577 “fluid”=>数组(
    578 “最小值”=>“30px”,
    579 “最大值”=>“30px”,
    580                     ),
    581                 ),
    582 “should_use_fluid_typrography”=>true,
    583 “预期输出”=>“夹具(30px,1.875rem+((1vw-3.2px)*1),30px)”,
    584             ),
    585 
    586 '当未设置自定义最小字体大小时,应为em值应用缩放的最小字体大小'=>数组(
    587 “font_size”=>数组(
    588 “尺寸”=>“12rem”,
    589                 ),
    590 “should_use_fluid_typrography”=>true,
    591 “预期输出”=>“夹具(5.174rem,5.174rem+((1vw-0.2rem)*8.533),12rem)”,
    592             ),
    593 
    594 '当未设置自定义最小字体大小时,应为px值应用缩放的最小字体大小'=>数组(
    595 “font_size”=>数组(
    596 “大小”=>“200px”,
    597                 ),
    598 “should_use_fluid_typrography”=>true,
    599 'expected_output'=>'clamp(85.342px,5.334rem+((1vw-3.2px)*8.958),200px)',
    600             ),
    601 
    602 “当设置自定义最小字体大小时,不应将缩放的最小字体大小应用于最小字体大小”=>数组(
    603 “font_size”=>数组(
    604 “大小”=>“200px”,
    605 “fluid”=>数组(
    606 “最小值”=>“100px”,
    607                     ),
    608                 ),
    609 “should_use_fluid_typrography”=>true,
    610 “预期输出”=>“夹具(100px,6.25rem+((1vw-3.2px)*7.813),200px)”,
     827        );
     828    }
     829
     830    /**
     831*测试主题json设置传递给wp_get_typography_font_size_value
     832*覆盖全局主题设置。
     833     *
     834*@票61118
     835     *
     836*@covers::wp_get_typography_font_size_value
     837     *
     838*@dataProvider data_generate_should_override_theme_settings_fixtures
     839     *
     840*@param数组$font_size{
     841*必需。在theme.json中看到的fontSizes预设格式中表示的字体大小。
     842     *
     843*@type string$name字体大小预设的名称。
     844*@type string$slug Kebab-case字体大小预设的唯一标识符。
     845*@type string$size CSS font-size值,包括适用的单位。
     846     * }
     847*@param bool$settings覆盖任何全局主题设置的主题JSON设置数组。
     848*@param string$expected_output wp_get_typography_font_size_value()的预期输出。
     849     */
     850公共函数test_should_override_theme_settings($font_size,$settings,$expected_output){
     851switch_theme(“block-theme-child-with-fluid-prinography”);
     852$actual=wp_get_typography_font_size_value($font_size,$settings);
     853
     854$this->assertSame($expected_output,$actual);
     855    }
     856
     857    /**
     858*test_wp_get_typography_font_size_value_should_use_fluid_typograph_deprecated的数据提供程序。
     859     *
     860*@return数组
     861     */
     862公共函数data_generate_sshould _override_theme_settings_fixtures(){
     863返回数组(
     864'当主题激活流体排版时返回钳制值'=>数组(
     865“font_size”=>数组(
     866“大小”=>“28px”,
     867                ),
     868“settings”=>空,
     869“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*0.789),28px)”,
     870            ),
     871'当设置参数停用流体排版时返回值'=>数组(
     872“font_size”=>数组(
     873'size'=>'28px',
     874                ),
     875“settings”=>数组(
     876“排版”=>数组(
     877“流体”=>假,
     878                    ),
     879                ),
     880“expected_output”=>“28px”,
     881            ),
     882
     883'当settings参数设置fluid.minViewportWidth值时返回clamp值'=>数组(
     884“font_size”=>数组(
     885“大小”=>“28px”,
     886                ),
     887“设置”=>数组(
     888“排版”=>数组(
     889“fluid”=>数组(
     890“minViewportWidth”=>“500px”,
     891                        ),
     892                    ),
     893                ),
     894“预期输出”=>“夹具(17.905px,1.119rem+((1vw-5px)*0.918),28px)”,
     895            ),
     896
     897'当settings参数设置layout.wideSize值时返回clamp值'=>数组(
     898“font_size”=>数组(
     899“大小”=>“28px”,
     900                ),
     901“settings”=>数组(
     902“layout”=>数组(
     903“wideSize”=>“500px”,
     904                    ),
     905                ),
     906“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*5.608),28px)”,
     907            ),
     908
     909'返回maxViewportWidth优先于备用layout.wideSize值的钳制值'=>数组(
     910“font_size”=>数组(
     911'size'=>'28px',
     912                ),
     913“settings”=>数组(
     914“排版”=>数组(
     915“fluid”=>数组(
     916“maxViewportWidth”=>“1000px”,
     917                        ),
     918                    ),
     919“layout”=>数组(
     920“wideSize”=>“500px”,
     921                    ),
     922                ),
     923“预期输出”=>“夹具(17.905px,1.119rem+((1vw-3.2px)*1.485),28px)”,
    611924            ),
    612925        );
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    58123兰特 r58171  
    14181418    }
    14191419
     1420    /*
     1421*测试传递给WP_Theme_JSON的设置是否覆盖合并的主题数据。
     1422     *
     1423*@票61118
     1424     */
     1425公共函数test_get_stylesheet_generates_fluid_typography_values(){
     1426寄存器块类型(
     1427“测试/夹紧”,
     1428阵列(
     1429“api版本”=>3,
     1430            )
     1431        );
     1432$theme_json=新WP_theme_json(
     1433阵列(
     1434“版本”=>WP_Theme_JSON::LATEST_SCHEMA,
     1435“settings”=>数组(
     1436“排版”=>数组(
     1437“流体”=>真,
     1438'fontSizes'=>数组(
     1439阵列(
     1440“大小”=>“16px”,
     1441“slug”=>“pickles”,
     1442“name”=>“Pickles”,
     1443                            ),
     1444阵列(
     1445“大小”=>“22px”,
     1446“slug”=>“toast”,
     1447“name”=>“Toast”,
     1448                            ),
     1449                        ),
     1450                    ),
     1451                ),
     1452“styles”=>数组(
     1453“排版”=>数组(
     1454'fontSize'=>'1em',
     1455                    ),
     1456“elements”=>数组(
     1457“h1”=>数组(
     1458“排版”=>数组(
     1459“fontSize”=>“100px”,
     1460                            ),
     1461                        ),
     1462                    ),
     1463“块”=>数组(
     1464“test/clamp-me”=>数组(
     1465“排版”=>数组(
     1466“fontSize”=>“48px”,
     1467                            ),
     1468                        ),
     1469                    ),
     1470                ),
     1471            ),
     1472“默认”
     1473        );
     1474
     1475unregister_block_type('test/clamp-me');
     1476
     1477//结果还包括根站点块样式。
     1478$this->资产相同(
     1479'body{-wp--预设--font-size--pickles:clamp(14px,0.875rem+((1vw-3.2px)*0.156),16px);--wp--预置--font-sise--toast:clamp;}.wp-site-blocks>.alightcenter{justify-content:中心;margin-left:自动;margin-right:自动;}:其中(.is-layout-flex){gap:0.5em;}:其中(.is-layout-grid){gap2:0.5ems;}body.is-layout-flow>.alignleft{float:left;margin-inline-start:0;margin-inline-end:2em;{body.is-layt-float:right;margin.inline-sart:2em;边距-inline-end:0;}body.is-layout-flow>.alightcenter{margin-left:auto!important;margin-right:auto!重要;}body.is-layout-constrained>.alignleft{float:left;margin-inline-start:0;margin-inline-end:2em;}body.is-layout-contrained>.alignright{float:right;margin.inline-sart:2em;martin-inline-end:0;}body.is-layout-constrained>.alightcenter{margin-left:自动!important;margin-right:自动!重要;}body.is-layout-onstrained>:其中(:not(.alightleft):notbody.is-layout-flex>*{margin:0;}body.is-layout-grid{display:grid;}body.is-loyout-grid>*{magin:0,}body{font-size:clamp(0.875em,0.875rem+((1vw-0.2em)*0.156),1em);}h1{font-sise:claim(50.171px,3.136rem+(1vw-3.2px)*3.893),100px);}.wp-block-test-clamp-me{font-sige:clamber(27.894px,1.743px雷姆+((1vw-3.2px)*1.571),48px);}.has-pickles-font-size{font-size:var(--wp-预置--font-size--pickles)!important;}.has-toast-font-sise{font-size:val(-wp-预置--font-size--toast)!impact;}',
     1480$theme_json->获取样式表()
     1481        );
     1482    }
     1483
    14201484公共函数test_allow_indirect_properties(){
    14211485$actual=WP_Theme_JSON::remove_insecure_properties(
注:请参见TracChangeset(跟踪变更集)获取有关使用变更集查看器的帮助。