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:
parent
9fbf143df9
commit
ef1a26e69c
|
@ -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
|
|
@ -5,7 +5,7 @@ use Automattic\WooCommerce\Admin\Features\Features;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the template_include hook to determine whether the current page needs
|
* 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 {
|
class ComingSoonRequestHandler {
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class ComingSoonRequestHandler {
|
||||||
foreach ( $fonts_to_add as $font_to_add ) {
|
foreach ( $fonts_to_add as $font_to_add ) {
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach ( $font_data as $font ) {
|
foreach ( $font_data as $font ) {
|
||||||
if ( $font['name'] === $font_to_add['name'] ) {
|
if ( isset( $font['name'] ) && $font['name'] === $font_to_add['name'] ) {
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,4 +70,62 @@ class ComingSoonRequestHandlerTest extends \WC_Unit_Test_Case {
|
||||||
|
|
||||||
$this->assertSame( $wp->query_vars['page_id'], null );
|
$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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue