Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library: ensure merged fontFace data is enconded as an array instead of an object #54435

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function merge_fonts_data( $font1, $font2 ) {
$unique_faces = array_map( 'unserialize', $unique_serialized_faces );

$merged_font = array_merge( $font1, $font2 );
$merged_font['fontFace'] = $unique_faces;
$merged_font['fontFace'] = array_values( $unique_faces );

return $merged_font;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public function data_should_fail_merge() {
* @param array $expected_result Expected result.
*/
public function test_should_merge( array $font1, array $font2, array $expected_result ) {
$actual = WP_Font_Family_Utils::merge_fonts_data( $font1, $font2 );

$this->assertSame( $expected_result, $actual );
$result = WP_Font_Family_Utils::merge_fonts_data( $font1, $font2 );
$this->assertSame( $expected_result, $result, 'Merged font data should match expected result.' );
$json_result = wp_json_encode( $result );
$this->assertStringContainsString( '"fontFace":[', $json_result, 'fontFace data should be enconded as an array and not an object.' );
}

/**
Expand Down Expand Up @@ -229,6 +230,71 @@ public function data_should_merge() {
),
),
),
'repeated font faces with non consecutive index positions' => array(
'font1' => array(
'slug' => 'piazzolla',
'name' => 'Piazzolla',
'fontFamily' => 'Piazzolla',
'fontFace' => array(
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => 'http://example.com/fonts/piazzolla_400_italic.ttf',
),

),
),
'font2' => array(
'slug' => 'piazzolla',
'fontFamily' => 'Piazzolla',
'fontFace' => array(
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'normal',
'fontWeight' => '600',
'src' => 'http://example.com/fonts/piazzolla_600_normal.ttf',
),
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => 'http://example.com/fonts/piazzolla_400_italic.ttf',
),
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '500',
'src' => 'http://example.com/fonts/piazzolla_500_italic.ttf',
),
),
),
'expected_result' => array(
'slug' => 'piazzolla',
'name' => 'Piazzolla',
'fontFamily' => 'Piazzolla',
'fontFace' => array(
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => 'http://example.com/fonts/piazzolla_400_italic.ttf',
),
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'normal',
'fontWeight' => '600',
'src' => 'http://example.com/fonts/piazzolla_600_normal.ttf',
),
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '500',
'src' => 'http://example.com/fonts/piazzolla_500_italic.ttf',
),
),
),
),
);
}
}