Skip to content

Conversation

@mikejolley
Copy link
Member

@mikejolley mikejolley commented Mar 30, 2023

All Submissions:

The contribution guidelines do not cover changelog entry creation—I had an error from a pre-commit hook when pushing.

Changes proposed in this Pull Request:

When working on woocommerce/woocommerce-blocks#8659 we realised several of the notices rendered by WooCommerce core across several frontend template files did not use the notice function helpers (wp_print_notice) or templates, and were instead hardcoded.

This PR replaces hardcoded notices with the correct functions and makes it possible to modify the notices via template overrides.

Additionally, a small modification to wp_print_notice was added so that the notice could be returned as a string instead of rendered. This was to make it more flexible. e.g.

$notice_html = wp_print_notice( 'Example', 'error', [], true );

How to test the changes in this Pull Request:

These instructions cover how to test notices that were changed.

  1. As a logged in customer with no orders, go to the My Account page
    • Click "orders" navigation item. Confirm the "no orders" notice is shown
    • Click "downloads" navigation item. Confirm the "no downloads" notice is shown
    • Navigate direct to "my-account/payment-methods". Confirm the "no methods" notice is shown
    • Navigate direct to "my-account/add-payment-method". Confirm the notice is shown.
  2. Go to the cart page (ensure there are no items in your cart). Confirm the "empty cart" notice is shown.
  3. Add an item to your cart.
  4. Go back to the cart page.
  5. Remove the item from your cart. Confirm you see both an "undo" notice, and an "empty cart" notice.
  6. Go to the shop page. Append ?s=noresults to the URL. Confirm you see the "No products were found matching your selection" notice.
  7. Add some items to your cart then place an order via the checkout
  8. Go back to the My Account Page
  9. Click the "orders" navigation item
  10. Click the button to view an order
  11. Change the URL and replace the order ID there with something invalid e.g. 123
  12. Confirm you see the invalid order notice

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?
  • Have you included testing instructions?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 30, 2023
@mikejolley mikejolley self-assigned this Mar 30, 2023
@mikejolley mikejolley requested review from a team and opr and removed request for a team March 30, 2023 13:51
@github-actions
Copy link
Contributor

github-actions bot commented Mar 30, 2023

Hi @coreymckrill,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@github-actions
Copy link
Contributor

github-actions bot commented Mar 30, 2023

Test Results Summary

Commit SHA: e8fcfbb

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 48s
E2E Tests1870010019713m 33s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@github-actions github-actions bot added the focus: e2e tests Issues related to e2e tests label Mar 31, 2023
opr
opr previously approved these changes Apr 4, 2023
Copy link
Contributor

@opr opr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and the notices work for me, and the code changes look mostly OK, I added some comments that might need action, but also might not so I will approve and let you decide whether to action them.

echo '<p class="cart-empty woocommerce-info">' . wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) ) . '</p>';
echo '<div class="cart-empty">' .
wc_print_notice(
wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need esc_html__ or is it safe to skip because it's wrapped in wp_kses_post?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escaping should come last so I think its ok to let KSES deal with this one. The filter could also return HTML.

@mikejolley
Copy link
Member Author

Thanks @opr I fixed up those template versions which would have been blocking. Escaping is left as it was before for the cart-empty message. KSES was used previously and should continue to be in place.

opr
opr previously approved these changes Apr 4, 2023
Copy link
Contributor

@opr opr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mikejolley that's great now.

@mikejolley mikejolley force-pushed the fix/remove-hardcoded-notices branch from e1a510f to e78e04f Compare April 5, 2023 12:47
@mikejolley mikejolley requested review from a team and coreymckrill and removed request for a team April 5, 2023 15:17
Copy link
Contributor

@coreymckrill coreymckrill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mikejolley, this all looks good! Testing instructions worked as expected, and it appears that no translation strings were changed 👍

Just one tweak needs to be made to some e2e tests (see below) and then this should be good to go.

Comment on lines 3676 to 3678
echo '<p class="cart-empty woocommerce-info">' . wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) ) . '</p>';
echo '<div class="cart-empty">';
wc_print_notice( wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) ), 'notice' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
echo '</div>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this change is causing some e2e tests to fail, because they assume the message container is p.cart-empty. Can probably just update the three tests: 1, 2, 3

@codecov
Copy link

codecov bot commented Apr 17, 2023

Codecov Report

Merging #37514 (e8fcfbb) into trunk (c226fa1) will decrease coverage by 0.0%.
The diff coverage is 4.0%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             trunk   #37514     +/-   ##
==========================================
- Coverage     51.6%    51.5%   -0.0%     
- Complexity   17260    17261      +1     
==========================================
  Files          429      429             
  Lines        79928    79957     +29     
==========================================
+ Hits         41213    41215      +2     
- Misses       38715    38742     +27     
Impacted Files Coverage Δ
...ocommerce/includes/admin/class-wc-admin-assets.php 0.0% <0.0%> (ø)
plugins/woocommerce/includes/class-wc-ajax.php 4.5% <0.0%> (-<0.1%) ⬇️
...ugins/woocommerce/includes/class-wc-post-types.php 1.1% <0.0%> (-<0.1%) ⬇️
...commerce/includes/class-wc-rest-authentication.php 3.4% <0.0%> (-<0.1%) ⬇️
plugins/woocommerce/includes/class-woocommerce.php 20.4% <ø> (ø)
...ncludes/shortcodes/class-wc-shortcode-checkout.php 0.0% <0.0%> (ø)
...ludes/shortcodes/class-wc-shortcode-my-account.php 0.0% <0.0%> (ø)
...ludes/tracks/events/class-wc-products-tracking.php 0.0% <ø> (ø)
...ins/woocommerce/includes/wc-template-functions.php 12.1% <0.0%> (-<0.1%) ⬇️
plugins/woocommerce/woocommerce.php 15.4% <ø> (ø)
... and 1 more

... and 1 file with indirect coverage changes

@mikejolley mikejolley requested a review from coreymckrill April 17, 2023 15:02
@mikejolley
Copy link
Member Author

@coreymckrill Those tests are updated but there are seemingly unrelated e2e fails. Can you take a look please?

@coreymckrill
Copy link
Contributor

🤔 @mikejolley I think the e2e's are still failing because of the three related empty cart tests (example). Given the following assertion:

await expect( page.locator( '.cart-empty' ) ).toContainText(
	'Your cart is currently empty.'
);

I suspect the reason this is failing may be because Playwright expects that the cart-empty container itself contains the given text, rather than containing another child container that contains that text. @lanej0 can hopefully confirm.

@mikejolley mikejolley force-pushed the fix/remove-hardcoded-notices branch from 06aad2c to b800a42 Compare April 18, 2023 11:59
@mikejolley
Copy link
Member Author

@coreymckrill I don't think its that because should display no item in the cart test is passing, and that uses the same selector and the same notice. So something else is preventing the message rendering I guess.

@mikejolley
Copy link
Member Author

update_wc_div in cart.js moves it out of the div into another wrapper. Ill find a workaround.

Copy link
Contributor

@coreymckrill coreymckrill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e tests passing now 👍

@coreymckrill coreymckrill merged commit 1650489 into trunk Apr 18, 2023
@coreymckrill coreymckrill deleted the fix/remove-hardcoded-notices branch April 18, 2023 19:07
@github-actions github-actions bot added this to the 7.8.0 milestone Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

focus: e2e tests Issues related to e2e tests plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants