Skip to content

Commit 22621ae

Browse files
committed
fix tests
1 parent 09b8009 commit 22621ae

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

includes/API/Orders_Controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public function wcpos_order_response( WP_REST_Response $response, WC_Abstract_Or
574574
$pos_payment_url = add_query_arg(
575575
array(
576576
'pay_for_order' => true,
577-
'key' => $order->get_order_key(),
577+
'key' => method_exists( $order, 'get_order_key' ) ? $order->get_order_key() : '',
578578
),
579579
get_home_url( null, '/wcpos-checkout/order-pay/' . $order->get_id() )
580580
);
@@ -623,7 +623,7 @@ public function wcpos_order_get_items( array $items, WC_Abstract_Order $order, a
623623
* @throws WC_Data_Exception
624624
*/
625625
public function wcpos_before_order_object_save( WC_Abstract_Order $order ): void {
626-
if ( $this->is_creating ) {
626+
if ( $this->is_creating && method_exists( $order, 'set_created_via' ) ) {
627627
$order->set_created_via( PLUGIN_NAME );
628628
}
629629

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct() {
2727

2828
// Require composer dependencies.
2929
require_once $this->plugin_dir . '/vendor/autoload.php';
30-
// $this->initialize_code_hacker();
30+
$this->initialize_code_hacker();
3131

3232
// Bootstrap WP_Mock to initialize built-in features
3333
// NOTE: CodeHacker and WP_Mock are not compatible :(

tests/includes/API/Test_HPOS_Orders_Controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function test_order_api_get_all_ids(): void {
176176
$data = $response->get_data();
177177
$ids = wp_list_pluck( $data, 'id' );
178178

179-
$this->assertEquals( array( $order1->get_id(), $order2->get_id() ), $ids );
179+
$this->assertEqualsCanonicalizing( array( $order1->get_id(), $order2->get_id() ), $ids );
180180
}
181181

182182
/**
@@ -195,7 +195,7 @@ public function test_order_api_get_all_ids_with_date_modified_gmt(): void {
195195
$data = $response->get_data();
196196
$ids = wp_list_pluck( $data, 'id' );
197197

198-
$this->assertEquals( array( $order1->get_id(), $order2->get_id() ), $ids );
198+
$this->assertEqualsCanonicalizing( array( $order1->get_id(), $order2->get_id() ), $ids );
199199

200200
// Verify that date_modified_gmt is present for all products and correctly formatted.
201201
foreach ( $data as $d ) {
@@ -882,7 +882,7 @@ public function test_create_order_with_decimal_quantity() {
882882
}
883883

884884
/**
885-
*
885+
*
886886
*/
887887
public function test_filter_order_by_cashier() {
888888
$order1 = OrderHelper::create_order();
@@ -903,7 +903,7 @@ public function test_filter_order_by_cashier() {
903903
}
904904

905905
/**
906-
*
906+
*
907907
*/
908908
public function test_filter_order_by_store() {
909909
$order1 = OrderHelper::create_order();

tests/includes/API/Test_Order_Taxes.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function test_create_order_with_tax(): void {
131131

132132
// order taxes
133133
$this->assertEquals( 1, \count( $data['tax_lines'] ) );
134-
$this->assertEquals( '1.00', $data['tax_lines'][0]['tax_total'] );
134+
$this->assertEquals( '1.000000', $data['tax_lines'][0]['tax_total'] );
135135
$this->assertEquals( 'US', $data['tax_lines'][0]['label'] );
136136
$this->assertEquals( '10', $data['tax_lines'][0]['rate_percent'] );
137137
}
@@ -205,7 +205,7 @@ public function test_create_order_with_customer_billing_address_as_tax_location(
205205

206206
// order taxes
207207
$this->assertEquals( 1, \count( $data['tax_lines'] ) );
208-
$this->assertEquals( '2.00', $data['tax_lines'][0]['tax_total'] );
208+
$this->assertEquals( '2.000000', $data['tax_lines'][0]['tax_total'] );
209209
$this->assertEquals( 'VAT', $data['tax_lines'][0]['label'] );
210210
$this->assertEquals( '20', $data['tax_lines'][0]['rate_percent'] );
211211
}
@@ -273,22 +273,22 @@ public function test_create_order_with_customer_shipping_address_as_tax_location
273273

274274
// order taxes
275275
$this->assertEquals( 2, \count( $data['tax_lines'] ) );
276-
$this->assertEquals( '1.00', $data['tax_lines'][0]['tax_total'] );
276+
$this->assertEquals( '1.000000', $data['tax_lines'][0]['tax_total'] );
277277
$this->assertEquals( 'US', $data['tax_lines'][0]['label'] );
278278
$this->assertEquals( '10', $data['tax_lines'][0]['rate_percent'] );
279-
$this->assertEquals( '0.22', $data['tax_lines'][1]['tax_total'] );
279+
$this->assertEquals( '0.220000', $data['tax_lines'][1]['tax_total'] );
280280
$this->assertEquals( 'US AL', $data['tax_lines'][1]['label'] );
281281
$this->assertEquals( '2', $data['tax_lines'][1]['rate_percent'] );
282282

283283
// order total
284-
$this->assertEquals( '11.22', $data['total'] );
285-
$this->assertEquals( '1.22', $data['cart_tax'] );
286-
$this->assertEquals( '1.22', $data['total_tax'] );
284+
$this->assertEquals( '11.220000', $data['total'] );
285+
$this->assertEquals( '1.220000', $data['cart_tax'] );
286+
$this->assertEquals( '1.220000', $data['total_tax'] );
287287
}
288288

289-
/**
290-
*
291-
*/
289+
/**
290+
*
291+
*/
292292
public function test_fee_lines_should_respect_tax_status_when_negative() {
293293
$this->assertEquals( 'base', WC_Admin_Settings::get_option( 'woocommerce_tax_based_on' ) );
294294
$this->assertEquals( 'US:CA', WC_Admin_Settings::get_option( 'woocommerce_default_country' ) );

tests/includes/API/Test_Product_Variations_Controller.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,15 @@ public function get_expected_response_fields() {
9191
'attributes',
9292
'menu_order',
9393
'meta_data',
94+
'type',
9495
'_links',
9596
// Added by WCPOS.
9697
'barcode',
97-
// Added in WooCommerce 8.3.0 :/
98+
// Added in WooCommerce 8.3.0
9899
'name',
99100
'parent_id',
101+
// Added in WooCommerce 9.4.0
102+
'global_unique_id',
100103
);
101104
}
102105

@@ -498,7 +501,7 @@ public function test_variation_decimal_stock_quantity_schema(): void {
498501
$this->assertTrue( woocommerce_pos_get_settings( 'general', 'decimal_qty' ) );
499502

500503
$schema = $this->endpoint->get_item_schema();
501-
$this->assertEquals( 'string', $schema['properties']['stock_quantity']['type'] );
504+
$this->assertEquals( 'float', $schema['properties']['stock_quantity']['type'] );
502505
}
503506

504507
public function test_variation_response_with_decimal_quantities(): void {

tests/includes/API/Test_Products_Controller.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public function get_expected_response_fields() {
118118
'post_password',
119119
// Added by WCPOS.
120120
'barcode',
121+
// Added in WooCommerce 9.4.0
122+
'global_unique_id',
121123
);
122124
}
123125

@@ -454,7 +456,7 @@ public function test_product_decimal_stock_quantity_schema(): void {
454456
$this->assertTrue( woocommerce_pos_get_settings( 'general', 'decimal_qty' ) );
455457

456458
$schema = $this->endpoint->get_item_schema();
457-
$this->assertEquals( 'string', $schema['properties']['stock_quantity']['type'] );
459+
$this->assertEquals( 'float', $schema['properties']['stock_quantity']['type'] );
458460
}
459461

460462
public function test_product_response_with_decimal_quantities(): void {

tests/includes/API/Test_Stores_API.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public function get_expected_response_fields() {
5252
'store_address',
5353
'store_address_2',
5454
'store_city',
55+
'store_state',
56+
'store_country',
57+
'tax_address',
5558
'default_country',
5659
'store_postcode',
5760
'default_customer_address',

tests/includes/API/WCPOS_REST_Unit_Test_Case.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function setUp(): void {
3434
wp_set_current_user( $this->user );
3535
}
3636

37+
public function tearDown(): void {
38+
parent::tearDown();
39+
}
40+
3741
public function rest_api_init(): void {
3842
new API();
3943
}

tests/includes/Abstracts/Test_Store_Abstract.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function get_expected_data_props() {
3737
'store_address',
3838
'store_address_2',
3939
'store_city',
40+
'store_state',
41+
'store_country',
42+
'tax_address',
4043
'default_country',
4144
'store_postcode',
4245
'default_customer_address',

0 commit comments

Comments
 (0)