Shipping tests: when the selection changes
Author: linear[bot]Created Sep 29, 2026Updated Sep 29, 2026
LabelsShippingplugin: woocommercefocus: unit testsRubikblock: cartblock: checkout
What this covers
The shopper picks an option, then edits the cart or the address, and the selection has to stay coherent. PHP and client.
Expected behaviour
- The choice is stored and shown as selected
- An address change drops a choice that no longer applies and puts a sensible one in its place
- A free shipping coupon moves the selection, and removing it moves it back
- Adding or removing an item recalculates
- In a multi-package cart the choice lands on the right packages
Where it breaks
- Forcing an option that no longer exists must be refused at payment
- A request with no rate id
- A selection request while shipping is switched off
- A multi-package cart where the same rate id is applied to every package regardless of whether it exists there
- A lost session
- Two tabs choosing differently
Already covered
class-wc-cart-default-shipping-method-test.php covers how a default is chosen and that an already chosen pickup survives. Checkout.php::test_checkout_invalid_shipping_method covers refusal at checkout, returning 400 with woocommerce_rest_invalid_shipping_option.
Not covered
POST /cart/select-shipping-rate has no behavioural test anywhere; it appears only in the route-registration lists in ControllerTests.php:
- A choice being stored and reflected in
selected - An address change replacing a choice that no longer applies
- A free shipping coupon moving the selection, and removing it moving it back
- Adding or removing an item recalculating
- How a multi-package cart targets packages
- A request with no rate id
- A selection request while shipping is switched off
- A lost session, and two tabs choosing differently
- The multi-package case where one rate id is applied to every package regardless of whether it exists there
Conventions
The seam in scope is woocommerce_shipping_chosen_method. Pin that it is honoured, not that the outcome is fixed.
Integration and unit tests only, no E2E.
Source: woocommerce/woocommerce