Skip to content

Commit 1d7d6a5

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents c408962 + 6794f59 commit 1d7d6a5

4 files changed

Lines changed: 80 additions & 10 deletions

File tree

‎src/wp-includes/block-supports/typography.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ function wp_render_typography_support( $block_content, $block ) {
311311
if ( ! empty( $block_content ) ) {
312312
$processor = new WP_HTML_Tag_Processor( $block_content );
313313
if ( $processor->next_tag() ) {
314+
$processor->add_class( 'has-fit-text' );
314315
if ( ! $processor->get_attribute( 'data-wp-interactive' ) ) {
315316
$processor->set_attribute( 'data-wp-interactive', true );
316317
}

‎src/wp-includes/class-wp-user.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
* @property string $display_name
3434
* @property string $spam
3535
* @property string $deleted
36+
* @property string $comment_shortcuts
37+
* @property string $infinite_scrolling
3638
* @property string $locale
3739
* @property string $rich_editing
3840
* @property string $syntax_highlighting

‎tests/phpstan/baselines/property.nonObject.neon‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,6 @@ parameters:
178178
identifier: property.nonObject
179179
count: 2
180180
path: ../../../src/wp-admin/update.php
181-
-
182-
message: '#^Cannot access property \$comment_shortcuts on WP_User\|false\.$#'
183-
identifier: property.nonObject
184-
count: 1
185-
path: ../../../src/wp-admin/user-edit.php
186-
-
187-
message: '#^Cannot access property \$infinite_scrolling on WP_User\|false\.$#'
188-
identifier: property.nonObject
189-
count: 1
190-
path: ../../../src/wp-admin/user-edit.php
191181
-
192182
message: '#^Cannot access property \$id on int\|string\|WP_Term\.$#'
193183
identifier: property.nonObject

‎tests/phpunit/tests/block-supports/typography.php‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public function tear_down() {
5858
unregister_block_type( $this->test_block_name );
5959
$this->test_block_name = null;
6060

61+
// Resets script modules enqueued while rendering fit text.
62+
$GLOBALS['wp_script_modules'] = null;
63+
6164
parent::tear_down();
6265
}
6366

@@ -1135,6 +1138,80 @@ public function data_generate_replace_inline_font_styles_with_fluid_values_fixtu
11351138
);
11361139
}
11371140

1141+
/**
1142+
* Tests that the `has-fit-text` class name is added to the block wrapper when the
1143+
* `fitText` attribute is set.
1144+
*
1145+
* @ticket 65973
1146+
*
1147+
* @covers ::wp_render_typography_support
1148+
*
1149+
* @dataProvider data_should_add_fit_text_class_name
1150+
*
1151+
* @param non-falsy-string $block_content HTML block content.
1152+
* @param non-falsy-string $expected_class Expected value of the class attribute on the block wrapper.
1153+
*/
1154+
public function test_should_add_fit_text_class_name( string $block_content, string $expected_class ) {
1155+
$block = array(
1156+
'blockName' => 'core/site-title',
1157+
'attrs' => array(
1158+
'fitText' => true,
1159+
),
1160+
);
1161+
1162+
$actual = wp_render_typography_support( $block_content, $block );
1163+
1164+
$processor = new WP_HTML_Tag_Processor( $actual );
1165+
$processor->next_tag();
1166+
1167+
$this->assertSame( $expected_class, $processor->get_attribute( 'class' ), 'The block wrapper does not have the expected class names.' );
1168+
$this->assertSame( 1, substr_count( $actual, 'has-fit-text' ), 'The class name should be added exactly once, to the outermost tag only.' );
1169+
}
1170+
1171+
/**
1172+
* Data provider for test_should_add_fit_text_class_name().
1173+
*
1174+
* @return array<non-falsy-string, array{ block_content: non-falsy-string, expected_class: non-falsy-string }>
1175+
*/
1176+
public function data_should_add_fit_text_class_name(): array {
1177+
return array(
1178+
'wrapper without a class attribute' => array(
1179+
'block_content' => '<h1>Site Title</h1>',
1180+
'expected_class' => 'has-fit-text',
1181+
),
1182+
'wrapper with existing class names' => array(
1183+
'block_content' => '<h1 class="wp-block-site-title"><a href="https://example.com">Site Title</a></h1>',
1184+
'expected_class' => 'wp-block-site-title has-fit-text',
1185+
),
1186+
'wrapper with an already serialized class name' => array(
1187+
'block_content' => '<p class="has-fit-text">A paragraph</p>',
1188+
'expected_class' => 'has-fit-text',
1189+
),
1190+
'wrapper with inner blocks' => array(
1191+
'block_content' => '<div class="wp-block-group"><p>A paragraph inside a group</p></div>',
1192+
'expected_class' => 'wp-block-group has-fit-text',
1193+
),
1194+
);
1195+
}
1196+
1197+
/**
1198+
* Tests that the `has-fit-text` class name is not added when the block does not
1199+
* opt in to the fit text support.
1200+
*
1201+
* @ticket 65973
1202+
*
1203+
* @covers ::wp_render_typography_support
1204+
*/
1205+
public function test_should_not_add_fit_text_class_name_without_fit_text_attribute() {
1206+
$block_content = '<h1 class="wp-block-site-title">Site Title</h1>';
1207+
$block = array(
1208+
'blockName' => 'core/site-title',
1209+
'attrs' => array(),
1210+
);
1211+
1212+
$this->assertSame( $block_content, wp_render_typography_support( $block_content, $block ) );
1213+
}
1214+
11381215
/**
11391216
* Tests that valid font size values are parsed.
11401217
*

0 commit comments

Comments
 (0)