Update notice templates display logic to show updated templates in block themes only (#44283)

* WIP

* Add e2e tests for regular and custom templates

* Allow theme *.zip files for testing purposes

* Bump template versions

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

* Update comments in bash script

* Remove child themes - they will be installed from the zip

* Fix lint error re spacing

* Bump template versions

* Update PHP unit tests for classic style notices

* Revert "Remove child themes - they will be installed from the zip"

This reverts commit 98b1036616.

* Remove classic cart check in test

* Revert "Add e2e tests for regular and custom templates"

This reverts commit ef531854f9.

* Revert test-related changes

* Remove report

* Prevent phpcs warning for not escaped output

It is escaped in the wc_get_notice_data_attr function

* Revert notice changes to core E2E tests

* Update shopper add to cart e2e test to use correct notice class

* Update checkout block E2E test to use correct notice class

* Fix typo

* Update test to check for correct notice classes

* Update notice comment

* Re-apply block template overrides

* Consistent notice check with other templates

---------

Co-authored-by: Niels Lange <info@nielslange.de>
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Thomas Roberts 2024-02-05 10:50:15 +00:00 committed by GitHub
parent 097bd5c8f5
commit 877a16096c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 215 additions and 80 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fixed an issue where the notices shown in classic themes were using the updated styles.

View File

@ -41,10 +41,14 @@ class Notices {
* Initialize notice hooks.
*/
public function init() {
if ( wp_is_block_theme() ) {
add_filter( 'woocommerce_kses_notice_allowed_tags', [ $this, 'add_kses_notice_allowed_tags' ] );
add_filter( 'wc_get_template', [ $this, 'get_notices_template' ], 10, 5 );
add_action( 'wp_head', [ $this, 'enqueue_notice_styles' ] );
}
}
/**
* Allow SVG icon in notices.
*
@ -68,6 +72,40 @@ class Notices {
return array_merge( $allowed_tags, $svg_args );
}
/**
* Replaces core notice templates with those from blocks.
*
* The new notice templates match block components with matching icons and styling. The differences are:
* 1. Core has notices for info, success, and error notices, blocks has notices for info, success, error,
* warning, and a default notice type.
* 2. The block notices use different CSS classes to the core notices. Core uses `woocommerce-message`, `is-info`
* and `is-error` classes, blocks uses `wc-block-components-notice-banner is-error`,
* `wc-block-components-notice-banner is-info`, and `wc-block-components-notice-banner is-success`.
* 3. The markup of the notices is different, with the block notices using SVG icons and a slightly different
* structure to accommodate this.
*
* @param string $template Located template path.
* @param string $template_name Template name.
* @param array $args Template arguments.
* @param string $template_path Template path.
* @param string $default_path Default path.
* @return string
*/
public function get_notices_template( $template, $template_name, $args, $template_path, $default_path ) {
$directory = get_stylesheet_directory();
$file = $directory . '/woocommerce/' . $template_name;
if ( file_exists( $file ) ) {
return $file;
}
if ( in_array( $template_name, $this->notice_templates, true ) ) {
$template = $this->package->get_path( 'templates/block-' . $template_name );
wp_enqueue_style( 'wc-blocks-style' );
}
return $template;
}
/**
* Replaces all notices with the new block based notices.
*

View File

@ -0,0 +1,50 @@
<?php
/**
* Show error messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/error.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! $notices ) {
return;
}
$multiple = count( $notices ) > 1;
?>
<div class="wc-block-components-notice-banner is-error" role="alert" <?php echo $multiple ? '' : wc_get_notice_data_attr( $notices[0] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
<?php if ( $multiple ) { ?>
<p class="wc-block-components-notice-banner__summary"><?php esc_html_e( 'The following problems were found:', 'woocommerce' ); ?></p>
<ul>
<?php foreach ( $notices as $notice ) : ?>
<li<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php echo wc_kses_notice( $notice['notice'] ); ?>
</li>
<?php endforeach; ?>
</ul>
<?php
} else {
echo wc_kses_notice( $notices[0]['notice'] );
}
?>
</div>
</div>
<?php

View File

@ -0,0 +1,37 @@
<?php
/**
* Show info messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/notice.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! $notices ) {
return;
}
?>
<?php foreach ( $notices as $notice ) : ?>
<div class="wc-block-components-notice-banner is-info"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> role="alert">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
<?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>

View File

@ -0,0 +1,37 @@
<?php
/**
* Show success messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/success.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! $notices ) {
return;
}
?>
<?php foreach ( $notices as $notice ) : ?>
<div class="wc-block-components-notice-banner is-success"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> role="alert">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
<?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>

View File

@ -10,41 +10,24 @@
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @see https://woo.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.5.0
* @version 8.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( empty( $notices ) || ! is_array( $notices ) ) {
if ( ! $notices ) {
return;
}
$multiple = count( $notices ) > 1;
?>
<div class="wc-block-components-notice-banner is-error" role="alert" <?php echo $multiple ? '' : wc_get_notice_data_attr( $notices[0] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
<?php if ( $multiple ) { ?>
<p class="wc-block-components-notice-banner__summary"><?php esc_html_e( 'The following problems were found:', 'woocommerce' ); ?></p>
<ul>
<ul class="woocommerce-error" role="alert">
<?php foreach ( $notices as $notice ) : ?>
<li<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php echo wc_kses_notice( $notice['notice'] ); ?>
</li>
<?php endforeach; ?>
</ul>
<?php
} else {
echo wc_kses_notice( $notices[0]['notice'] );
}
?>
</div>
</div>
<?php

View File

@ -1,6 +1,6 @@
<?php
/**
* Show info messages
* Show messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/notice.php.
*
@ -10,13 +10,13 @@
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @see https://woo.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.5.0
* @version 8.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
exit; // Exit if accessed directly.
}
if ( ! $notices ) {
@ -26,12 +26,7 @@ if ( ! $notices ) {
?>
<?php foreach ( $notices as $notice ) : ?>
<div class="wc-block-components-notice-banner is-info"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> role="alert">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
<div class="woocommerce-info"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>

View File

@ -1,6 +1,6 @@
<?php
/**
* Show success messages
* Show messages
*
* This template can be overridden by copying it to yourtheme/woocommerce/notices/success.php.
*
@ -10,28 +10,21 @@
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @see https://woo.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.5.0
* @version 8.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! $notices ) {
return;
}
?>
<?php foreach ( $notices as $notice ) : ?>
<div class="wc-block-components-notice-banner is-success"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> role="alert">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
<path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path>
</svg>
<div class="wc-block-components-notice-banner__content">
<div class="woocommerce-message"<?php echo wc_get_notice_data_attr( $notice ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> role="alert">
<?php echo wc_kses_notice( $notice['notice'] ); ?>
</div>
</div>
<?php endforeach; ?>

View File

@ -693,7 +693,7 @@ test.describe( 'Shopper Cart & Checkout Block Tax Levels', () => {
await page
.getByRole( 'button', { name: 'Update', exact: true } )
.click();
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'Shipping costs updated.'
);

View File

@ -146,7 +146,7 @@ test.describe( 'Cart page', () => {
await page.locator( 'a.remove' ).click();
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'Your cart is currently empty.'
);
} );
@ -197,7 +197,7 @@ test.describe( 'Cart page', () => {
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.waitForLoadState( 'networkidle' );
await expect(
page.locator( '.wc-block-components-notice-banner__content' )
page.locator( '.woocommerce-message' )
).toContainText(
`${ productName }” has been added to your cart.`
);
@ -206,9 +206,7 @@ test.describe( 'Cart page', () => {
// add the same product the third time
await page.goto( `/shop/?add-to-cart=${ productId }` );
await page.waitForLoadState( 'networkidle' );
await expect(
page.locator( '.wc-block-components-notice-banner__content' )
).toContainText(
await expect( page.locator( '.woocommerce-error' ) ).toContainText(
'You cannot add that amount to the cart — we have 2 in stock and you already have 2 in your cart.'
);
await page.goto( '/cart/' );
@ -245,14 +243,14 @@ test.describe( 'Cart page', () => {
.getByLabel( `Remove ${ productName } cross-sell 1 from cart` )
.click();
await expect(
page.locator( '.wc-block-components-notice-banner__content' )
page.locator( '.woocommerce-message' )
).toContainText( `${ productName } cross-sell 1” removed.` );
await page
.getByLabel( `Remove ${ productName } cross-sell 2 from cart` )
.click();
await expect(
page
.locator( '.wc-block-components-notice-banner__content' )
.locator( '.woocommerce-message' )
.first()
).toContainText( `${ productName } cross-sell 2” removed.` );

View File

@ -772,7 +772,7 @@ test.describe( 'Checkout Block page', () => {
// Now we are logged out, return to the confirmation page: we should be asked to log back in.
await expect(
page
.getByRole( 'alert' )
.locator( '.woocommerce-info' )
.getByText( 'Please log in to your account to view this order' )
).toBeVisible();

View File

@ -248,7 +248,7 @@ test.describe( 'Checkout page', () => {
await page.locator( '#billing_email' ).fill( customer.email );
await page.getByRole( 'button', { name: 'Place order' } ).click();
await expect( page.locator( '.is-error ul' ) ).toBeVisible();
await expect( page.locator( 'ul.woocommerce-error' ) ).toBeVisible();
await expect(
page.getByText( 'Shipping First name is a required field.' )
).toBeVisible();
@ -507,7 +507,7 @@ test.describe( 'Checkout page', () => {
await page.reload();
// Now we are logged out, return to the confirmation page: we should be asked to log back in.
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
/Please log in to your account to view this order/
);

View File

@ -271,7 +271,7 @@ test.describe( 'Mini Cart block page', () => {
await page
.getByRole( 'button', { name: 'Update', exact: true } )
.click();
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'Shipping costs updated.'
);

View File

@ -63,7 +63,7 @@ test.describe( 'Customer can manage addresses in My Account > Addresses page', (
await page.locator( 'text=Save address' ).click();
// verify billing address has been applied
await expect( page.locator( '.is-success' ) ).toContainText(
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'Address changed successfully.'
);
await expect(
@ -109,7 +109,7 @@ test.describe( 'Customer can manage addresses in My Account > Addresses page', (
await page.locator( 'text=Save address' ).click();
// verify shipping address has been applied
await expect( page.locator( '.is-success' ) ).toContainText(
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'Address changed successfully.'
);
await expect(

View File

@ -110,7 +110,7 @@ test.describe( 'Customer can manage downloadable file in My Account > Downloads
// click to simulate downloading and verify the file doesn't exist anymore in downloads
await page.locator( '.woocommerce-MyAccount-downloads-file' ).click();
await page.goto( 'my-account/downloads/' );
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.woocommerce-info' ) ).toContainText(
'No downloads available yet.'
);
await expect( page.locator( '.wc-forward' ) ).toContainText(

View File

@ -78,14 +78,14 @@ test.describe( 'Grouped Product Page', () => {
await page.goto( `product/${ slug }` );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.is-error' ) ).toContainText(
await expect( page.locator( '.woocommerce-error' ) ).toContainText(
'Please choose the quantity of items you wish to add to your cart…'
);
await page.locator( 'div.quantity input.qty >> nth=0' ).fill( '5' );
await page.locator( 'div.quantity input.qty >> nth=1' ).fill( '5' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.is-success' ) ).toContainText(
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
`${ simpleProduct1 }” and “${ simpleProduct2 }” have been added to your cart.`
);
@ -116,7 +116,7 @@ test.describe( 'Grouped Product Page', () => {
await page.locator( 'a.remove >> nth=1' ).click();
await page.locator( 'a.remove >> nth=0' ).click();
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.cart-empty' ) ).toContainText(
'Your cart is currently empty.'
);
} );

View File

@ -193,7 +193,7 @@ test.describe( 'Single Product Page', () => {
await page.locator( 'input.qty' ).fill( '5' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.is-success' ) ).toContainText(
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'have been added to your cart.'
);
@ -216,7 +216,7 @@ test.describe( 'Single Product Page', () => {
await page.goto( 'cart/' );
await page.locator( 'a.remove' ).click();
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.cart-empty' ) ).toContainText(
'Your cart is currently empty.'
);
} );

View File

@ -194,7 +194,7 @@ test.describe( 'Variable Product Page', () => {
.locator( '#size' )
.selectOption( attr.attributes[ 0 ].option );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect( page.locator( '.is-success' ) ).toContainText(
await expect( page.locator( '.woocommerce-message' ) ).toContainText(
'has been added to your cart.'
);
}
@ -228,7 +228,7 @@ test.describe( 'Variable Product Page', () => {
await page.goto( 'cart/' );
await page.locator( 'a.remove' ).click();
await expect( page.locator( '.is-info' ) ).toContainText(
await expect( page.locator( '.cart-empty' ) ).toContainText(
'Your cart is currently empty.'
);
} );

View File

@ -119,7 +119,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
wc_add_notice( 'One True Notice', 'notice' );
wc_add_notice( 'Second True Notice', 'notice', array( 'id' => 'second_notice' ) );
$this->expectOutputString( '<div class="wc-block-components-notice-banner is-info" role="alert"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path></svg><div class="wc-block-components-notice-banner__content">One True Notice</div></div><div class="wc-block-components-notice-banner is-info" data-id="second_notice" role="alert"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path></svg><div class="wc-block-components-notice-banner__content">Second True Notice</div></div>' );
$this->expectOutputString( '<div class="woocommerce-info">One True Notice</div><div class="woocommerce-info" data-id="second_notice">Second True Notice</div>' );
wc_print_notices();
@ -131,7 +131,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
* when first parameter is set to true.
*/
public function test_wc_print_notices_should_return_notices() {
$expected_return = '<div class="wc-block-components-notice-banner is-info" role="alert"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path></svg><div class="wc-block-components-notice-banner__content">One True Notice</div></div>';
$expected_return = "\n <div class=\"woocommerce-info\">\n One True Notice </div>\n";
wc_add_notice( 'One True Notice', 'notice' );
@ -149,7 +149,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
*/
public function test_wc_print_success_notice() {
$this->expectOutputString( '<div class="wc-block-components-notice-banner is-success" role="alert"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path></svg><div class="wc-block-components-notice-banner__content">Success!</div></div>' );
$this->expectOutputString( '<div class="woocommerce-message" role="alert">Success!</div>' );
wc_print_notice( 'Success!' );
}
@ -161,7 +161,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
*/
public function test_wc_print_info_notice() {
$this->expectOutputString( '<div class="wc-block-components-notice-banner is-info" role="alert"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path></svg><div class="wc-block-components-notice-banner__content">Info!</div></div>' );
$this->expectOutputString( '<div class="woocommerce-info">Info!</div>' );
wc_print_notice( 'Info!', 'notice' );
}
@ -174,7 +174,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
public function test_wc_print_error_notice() {
// Specific type.
$this->expectOutputString( '<div class="wc-block-components-notice-banner is-error" role="alert"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path></svg><div class="wc-block-components-notice-banner__content">Error!</div></div>' );
$this->expectOutputString( '<ul class="woocommerce-error" role="alert"><li>Error!</li></ul>' );
wc_print_notice( 'Error!', 'error' );
}
@ -187,7 +187,7 @@ class WC_Tests_Notice_Functions extends WC_Unit_Test_Case {
public function test_wc_print_notice_data() {
// Specific type.
$this->expectOutputString( '<div class="wc-block-components-notice-banner is-error" role="alert" data-id="billing_postcode"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path></svg><div class="wc-block-components-notice-banner__content">Error!</div></div>' );
$this->expectOutputString( '<ul class="woocommerce-error" role="alert"><li data-id="billing_postcode">Error!</li></ul>' );
wc_print_notice( 'Error!', 'error', array( 'id' => 'billing_postcode' ) );
}