Skip to content

Commit

Permalink
Tests packaging fix. Allow loading empty/missing shipping provider as…
Browse files Browse the repository at this point in the history
… placeholder to improve default shipping provider support.
  • Loading branch information
dennisnissle committed Nov 28, 2023
1 parent 365729f commit 3b27bb2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"require-dev": {
"phpunit/phpunit": "7.5.14",
"yoast/phpunit-polyfills": "^1.0",
"yoast/phpunit-polyfills": "^1.1.0",
"woocommerce/woocommerce-sniffs": "^0.1.3"
},
"config": {
Expand Down
5 changes: 3 additions & 2 deletions includes/wc-gzd-shipment-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,10 @@ function wc_gzd_get_order_shipping_provider( $order ) {
return false;
}

$provider = false;
$provider = false;
$method_id = wc_gzd_get_shipment_order_shipping_method_id( $order );

if ( $method = wc_gzd_get_shipping_provider_method( wc_gzd_get_shipment_order_shipping_method_id( $order ) ) ) {
if ( $method = wc_gzd_get_shipping_provider_method( $method_id ) ) {
$provider = $method->get_shipping_provider_instance();
}

Expand Down
4 changes: 0 additions & 4 deletions src/ShippingMethod/MethodHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ public static function get_provider_method( $maybe_method ) {
$instance_id = absint( $original_id );
}

if ( empty( $method_id ) && empty( $instance_id ) ) {
return false;
}

$method_key = $method_id . '_' . $instance_id;

if ( array_key_exists( $method_key, self::$methods ) ) {
Expand Down
22 changes: 18 additions & 4 deletions tests/unit-tests/Rest/ShipmentsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public function setUp(): void {
function test_get_shipment() {
wp_set_current_user( $this->user );

$shipment_initial = ShipmentHelper::create_simple_shipment( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
$shipment_initial = ShipmentHelper::create_simple_shipment();
$shipment_initial->set_packaging_id( 0 );
$shipment_initial->set_props( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
$shipment_initial->save();

$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipments/' . $shipment_initial->get_id() ) );
$shipment_response = $response->get_data();
Expand Down Expand Up @@ -178,9 +181,20 @@ public function test_delete_shipment() {
public function test_list_shipments() {
wp_set_current_user( $this->user );

ShipmentHelper::create_simple_shipment( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
ShipmentHelper::create_simple_shipment( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
ShipmentHelper::create_simple_shipment( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
$shipment = ShipmentHelper::create_simple_shipment();
$shipment->set_packaging_id( 0 );
$shipment->set_props( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
$shipment->save();

$shipment_1 = ShipmentHelper::create_simple_shipment();
$shipment_1->set_packaging_id( 0 );
$shipment_1->set_props( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
$shipment_1->save();

$shipment_2 = ShipmentHelper::create_simple_shipment();
$shipment_2->set_packaging_id( 0 );
$shipment_2->set_props( array( 'length' => 12, 'width' => 10, 'height' => 5 ) );
$shipment_2->save();

$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipments' ) );
$shipments_response = $response->get_data();
Expand Down

0 comments on commit 3b27bb2

Please sign in to comment.