Fix the undefined array key "name" warning in ComingSoonRequestHandler.php when the font name is not set (#49795)

* Fix undefined array key "name" warning in ComingSoonRequestHandler.php when font name is not set

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chi-Hsuan Huang 2024-07-24 09:55:19 +08:00 committed by GitHub
parent 9fbf143df9
commit ef1a26e69c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 64 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix the undefined array key "name" warning in ComingSoonRequestHandler.php when the font name is not set

View File

@ -5,7 +5,7 @@ use Automattic\WooCommerce\Admin\Features\Features;
/**
* Handles the template_include hook to determine whether the current page needs
* to be replaced with a comiing soon screen.
* to be replaced with a coming soon screen.
*/
class ComingSoonRequestHandler {
@ -185,7 +185,7 @@ class ComingSoonRequestHandler {
foreach ( $fonts_to_add as $font_to_add ) {
$found = false;
foreach ( $font_data as $font ) {
if ( $font['name'] === $font_to_add['name'] ) {
if ( isset( $font['name'] ) && $font['name'] === $font_to_add['name'] ) {
$found = true;
break;
}

View File

@ -70,4 +70,62 @@ class ComingSoonRequestHandlerTest extends \WC_Unit_Test_Case {
$this->assertSame( $wp->query_vars['page_id'], null );
}
/**
* @testdox Tests that the method adds the 'Inter' and 'Cardo' fonts to the theme JSON data.
*/
public function test_experimental_filter_theme_json_theme() {
$theme_json = $this->createMock( \WP_Theme_JSON_Data::class );
$initial_data = array(
'settings' => array(
'typography' => array(
'fontFamilies' => array(
'theme' => array(
array(
'fontFamily' => 'Existing Font',
'name' => 'Existing Font',
'slug' => 'existing-font',
'fontFace' => array(
array(
'fontFamily' => 'Existing Font',
'fontStyle' => 'normal',
'fontWeight' => '400',
'src' => array( 'existing-font.woff2' ),
),
),
),
array(
'fontFamily' => 'Unnamed Font',
'slug' => 'unnamed-font',
'fontFace' => array(
array(
'fontFamily' => 'Unnamed Font',
'fontStyle' => 'normal',
'fontWeight' => '400',
'src' => array( 'unnamed-font.woff2' ),
),
),
),
),
),
),
),
);
$theme_json->method( 'get_data' )->willReturn( $initial_data );
$theme_json->expects( $this->once() )
->method( 'update_with' )
->with(
$this->callback(
function ( $new_data ) {
$fonts = $new_data['settings']['typography']['fontFamilies']['theme'];
$font_names = array_column( $fonts, 'name' );
return in_array( 'Inter', $font_names, true ) && in_array( 'Cardo', $font_names, true );
}
)
);
$this->sut->experimental_filter_theme_json_theme( $theme_json );
}
}