2016-06-22 11:29:23 +00:00
|
|
|
<?php
|
2017-12-13 14:19:51 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Tests_CRUD_Orders file.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tests\CRUD
|
|
|
|
*/
|
2016-06-22 11:29:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Meta
|
2017-12-13 14:11:47 +00:00
|
|
|
*
|
2016-06-22 11:29:23 +00:00
|
|
|
* @package WooCommerce\Tests\CRUD
|
|
|
|
*/
|
|
|
|
class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_type
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_type() {
|
2016-06-22 11:29:23 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 'shop_order', $object->get_type() );
|
|
|
|
}
|
|
|
|
|
2016-06-22 16:02:22 +00:00
|
|
|
/**
|
|
|
|
* Test: get_data
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_data() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertInternalType( 'array', $object->get_data() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_id
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_id() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
2017-12-13 14:11:47 +00:00
|
|
|
$id = $object->save();
|
2016-06-22 16:02:22 +00:00
|
|
|
$this->assertEquals( $id, $object->get_id() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_parent_id
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_parent_id() {
|
2016-08-23 17:48:48 +00:00
|
|
|
$object1 = new WC_Order();
|
|
|
|
$parent_id = $object1->save();
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
2016-08-23 17:48:48 +00:00
|
|
|
$object->set_parent_id( $parent_id );
|
|
|
|
$this->assertEquals( $parent_id, $object->get_parent_id() );
|
2016-06-22 16:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_order_number
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_order_number() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$id = $object->save();
|
|
|
|
$this->assertEquals( $id, $object->get_order_number() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_order_key
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_order_key() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'some_key';
|
|
|
|
$object->set_order_key( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_order_key() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_currency
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_currency() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'USD';
|
|
|
|
$object->set_currency( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_currency() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_version
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_version() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
2017-03-15 16:36:53 +00:00
|
|
|
$set_to = '3.0.0';
|
2016-06-22 16:02:22 +00:00
|
|
|
$object->set_version( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_version() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_prices_include_tax
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_prices_include_tax() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_prices_include_tax( 1 );
|
2016-12-20 22:33:35 +00:00
|
|
|
$this->assertTrue( $object->get_prices_include_tax() );
|
2016-06-22 16:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_date_created
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_date_created() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_date_created( '2016-12-12' );
|
2017-03-08 16:52:21 +00:00
|
|
|
$this->assertEquals( '1481500800', $object->get_date_created()->getOffsetTimestamp() );
|
2016-06-22 16:02:22 +00:00
|
|
|
|
|
|
|
$object->set_date_created( '1481500800' );
|
2017-03-08 16:52:21 +00:00
|
|
|
$this->assertEquals( 1481500800, $object->get_date_created()->getTimestamp() );
|
2016-06-22 16:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_date_modified
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_date_modified() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_date_modified( '2016-12-12' );
|
2017-03-08 16:52:21 +00:00
|
|
|
$this->assertEquals( '1481500800', $object->get_date_modified()->getOffsetTimestamp() );
|
2016-06-22 16:02:22 +00:00
|
|
|
|
|
|
|
$object->set_date_modified( '1481500800' );
|
2017-03-08 16:52:21 +00:00
|
|
|
$this->assertEquals( 1481500800, $object->get_date_modified()->getTimestamp() );
|
2016-06-22 16:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_customer_id
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_customer_id() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 10;
|
|
|
|
$object->set_customer_id( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_customer_id() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_user
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_user() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
2016-12-20 22:33:35 +00:00
|
|
|
$this->assertFalse( $object->get_user() );
|
2016-06-22 16:02:22 +00:00
|
|
|
$set_to = '1';
|
|
|
|
$object->set_customer_id( $set_to );
|
|
|
|
$this->assertInstanceOf( 'WP_User', $object->get_user() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_discount_total
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_discount_total() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_discount_total( 50 );
|
|
|
|
$this->assertEquals( 50, $object->get_discount_total() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_discount_tax
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_discount_tax() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_discount_tax( 5 );
|
|
|
|
$this->assertEquals( 5, $object->get_discount_tax() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_total
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_total() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_shipping_total( 5 );
|
|
|
|
$this->assertEquals( 5, $object->get_shipping_total() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_tax
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_tax() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_shipping_tax( 5 );
|
|
|
|
$this->assertEquals( 5, $object->get_shipping_tax() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_cart_tax
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_cart_tax() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_cart_tax( 5 );
|
|
|
|
$this->assertEquals( 5, $object->get_cart_tax() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_total( 5 );
|
|
|
|
$this->assertEquals( 5, $object->get_total() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_tax
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_tax() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_cart_tax( 5 );
|
|
|
|
$object->set_shipping_tax( 5 );
|
|
|
|
$this->assertEquals( 10, $object->get_total_tax() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_discount
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_discount() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_discount_total( 50 );
|
|
|
|
$object->set_discount_tax( 5 );
|
|
|
|
$this->assertEquals( 50, $object->get_total_discount() );
|
|
|
|
$this->assertEquals( 55, $object->get_total_discount( false ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_subtotal
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_subtotal() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = WC_Helper_Order::create_order();
|
|
|
|
$this->assertEquals( 40, $object->get_subtotal() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_tax_totals
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_tax_totals() {
|
2016-06-22 16:02:22 +00:00
|
|
|
$object = WC_Helper_Order::create_order();
|
|
|
|
$this->assertEquals( array(), $object->get_tax_totals() );
|
|
|
|
}
|
|
|
|
|
2016-06-23 14:52:12 +00:00
|
|
|
/**
|
|
|
|
* Test: remove_order_items
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_remove_order_items() {
|
2016-06-23 14:52:12 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$object = new WC_Order();
|
2016-11-17 21:30:34 +00:00
|
|
|
$item_1 = new WC_Order_Item_Product();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item_1->set_props(
|
|
|
|
array(
|
|
|
|
'product' => $product,
|
|
|
|
'quantity' => 4,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$item_2 = new WC_Order_Item_Product();
|
|
|
|
$item_2->set_props(
|
|
|
|
array(
|
|
|
|
'product' => $product,
|
|
|
|
'quantity' => 2,
|
|
|
|
)
|
|
|
|
);
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item_1 );
|
|
|
|
$object->add_item( $item_2 );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$this->assertCount( 2, $object->get_items() );
|
|
|
|
$object->remove_order_items();
|
|
|
|
$this->assertCount( 0, $object->get_items() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_items
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_items() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$item_1 = new WC_Order_Item_Product();
|
|
|
|
$item_1->set_props(
|
|
|
|
array(
|
|
|
|
'product' => WC_Helper_Product::create_simple_product(),
|
|
|
|
'quantity' => 4,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$item_2 = new WC_Order_Item_Product();
|
|
|
|
$item_2->set_props(
|
|
|
|
array(
|
|
|
|
'product' => WC_Helper_Product::create_simple_product(),
|
|
|
|
'quantity' => 2,
|
|
|
|
)
|
|
|
|
);
|
2016-08-22 15:48:19 +00:00
|
|
|
|
|
|
|
$object->add_item( $item_1 );
|
|
|
|
$object->add_item( $item_2 );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$this->assertCount( 2, $object->get_items() );
|
|
|
|
}
|
2017-07-06 18:12:02 +00:00
|
|
|
|
2017-05-04 09:47:43 +00:00
|
|
|
/**
|
|
|
|
* Test: get_different_items
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_different_items() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$item_1 = new WC_Order_Item_Product();
|
|
|
|
$item_1->set_props(
|
|
|
|
array(
|
|
|
|
'product' => WC_Helper_Product::create_simple_product(),
|
|
|
|
'quantity' => 4,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$item_2 = new WC_Order_Item_Fee();
|
|
|
|
$item_2->set_props(
|
|
|
|
array(
|
|
|
|
'name' => 'Some Fee',
|
|
|
|
'tax_status' => 'taxable',
|
|
|
|
'total' => '100',
|
|
|
|
'tax_class' => '',
|
|
|
|
)
|
|
|
|
);
|
2017-05-04 09:47:43 +00:00
|
|
|
$object->add_item( $item_1 );
|
|
|
|
$object->add_item( $item_2 );
|
|
|
|
$this->assertCount( 2, $object->get_items( array( 'line_item', 'fee' ) ) );
|
|
|
|
}
|
2016-06-23 14:52:12 +00:00
|
|
|
|
|
|
|
/**
|
2019-05-09 04:58:47 +00:00
|
|
|
* Test: get_coupons
|
|
|
|
*/
|
|
|
|
public function test_get_coupons() {
|
|
|
|
$object = new WC_Order();
|
|
|
|
$item = new WC_Order_Item_Coupon();
|
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'code' => '12345',
|
|
|
|
'discount' => 10,
|
|
|
|
'discount_tax' => 5,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$object->add_item( $item );
|
|
|
|
$object->save();
|
|
|
|
$this->assertCount( 1, $object->get_coupons() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-23 14:52:12 +00:00
|
|
|
* Test: get_fees
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_fees() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$item = new WC_Order_Item_Fee();
|
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'name' => 'Some Fee',
|
|
|
|
'tax_status' => 'taxable',
|
|
|
|
'total' => '100',
|
|
|
|
'tax_class' => '',
|
|
|
|
)
|
|
|
|
);
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
2016-06-23 14:52:12 +00:00
|
|
|
$this->assertCount( 1, $object->get_fees() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_taxes
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_taxes() {
|
2016-06-23 14:52:12 +00:00
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
2016-08-27 01:46:45 +00:00
|
|
|
'tax_rate_class' => '',
|
2016-06-23 14:52:12 +00:00
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$item_1 = new WC_Order_Item_Product();
|
|
|
|
$item_1->set_props(
|
|
|
|
array(
|
|
|
|
'product' => WC_Helper_Product::create_simple_product(),
|
|
|
|
'quantity' => 4,
|
|
|
|
)
|
|
|
|
);
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item_1 );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->calculate_totals();
|
|
|
|
$this->assertCount( 1, $object->get_taxes() );
|
|
|
|
|
2016-08-22 15:48:19 +00:00
|
|
|
$item = new WC_Order_Item_Tax();
|
|
|
|
$item->set_rate( 100 );
|
|
|
|
$item->set_tax_total( 100 );
|
|
|
|
$item->set_shipping_tax_total( 100 );
|
|
|
|
$object->add_item( $item );
|
|
|
|
$object->save();
|
2016-06-23 14:52:12 +00:00
|
|
|
|
|
|
|
$this->assertCount( 2, $object->get_taxes() );
|
|
|
|
}
|
|
|
|
|
2017-02-23 19:14:42 +00:00
|
|
|
/**
|
2017-02-24 20:30:41 +00:00
|
|
|
* Test mapping from old tax array keys to CRUD functions.
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_tax_legacy_arrayaccess() {
|
2017-02-23 19:14:42 +00:00
|
|
|
$tax = new WC_Order_item_Tax();
|
|
|
|
$tax->set_rate_id( 5 );
|
|
|
|
$tax->set_compound( true );
|
|
|
|
$tax->set_tax_total( 2.00 );
|
|
|
|
$tax->set_shipping_tax_total( 1.50 );
|
|
|
|
|
|
|
|
$this->assertEquals( $tax->get_rate_id(), $tax['rate_id'] );
|
|
|
|
$this->assertEquals( $tax->get_compound(), $tax['compound'] );
|
|
|
|
$this->assertEquals( $tax->get_tax_total(), $tax['tax_total'] );
|
|
|
|
$this->assertEquals( $tax->get_tax_total(), $tax['tax_amount'] );
|
|
|
|
$this->assertEquals( $tax->get_shipping_tax_total(), $tax['shipping_tax_total'] );
|
|
|
|
$this->assertEquals( $tax->get_shipping_tax_total(), $tax['shipping_tax_amount'] );
|
|
|
|
}
|
|
|
|
|
2016-06-23 14:52:12 +00:00
|
|
|
/**
|
|
|
|
* Test: get_shipping_methods
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_methods() {
|
2016-08-22 15:48:19 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', array(), 'flat_rate' );
|
2016-11-17 21:30:34 +00:00
|
|
|
$item = new WC_Order_Item_Shipping();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$this->assertCount( 1, $object->get_shipping_methods() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_method
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_method() {
|
2016-08-22 15:48:19 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', array(), 'flat_rate' );
|
2016-11-17 21:30:34 +00:00
|
|
|
$item = new WC_Order_Item_Shipping();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$this->assertEquals( 'Flat rate shipping', $object->get_shipping_method() );
|
2016-08-22 15:48:19 +00:00
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping 2', '10', array(), 'flat_rate' );
|
|
|
|
$item = new WC_Order_Item_Shipping();
|
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
|
|
|
$object->save();
|
2016-06-23 14:52:12 +00:00
|
|
|
$this->assertEquals( 'Flat rate shipping, Flat rate shipping 2', $object->get_shipping_method() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-14 09:21:27 +00:00
|
|
|
* Test: get_coupon_codes
|
2016-06-23 14:52:12 +00:00
|
|
|
*/
|
2019-05-14 09:21:27 +00:00
|
|
|
public function test_get_coupon_codes() {
|
2016-08-22 15:48:19 +00:00
|
|
|
$object = new WC_Order();
|
2016-11-17 21:30:34 +00:00
|
|
|
$item = new WC_Order_Item_Coupon();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'code' => '12345',
|
|
|
|
'discount' => 10,
|
|
|
|
'discount_tax' => 5,
|
|
|
|
)
|
|
|
|
);
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
2019-05-14 09:21:27 +00:00
|
|
|
$this->assertCount( 1, $object->get_coupon_codes() );
|
2016-06-23 14:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_item_count
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_item_count() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$item_1 = new WC_Order_Item_Product();
|
|
|
|
$item_1->set_props(
|
|
|
|
array(
|
|
|
|
'product' => WC_Helper_Product::create_simple_product(),
|
|
|
|
'quantity' => 4,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$item_2 = new WC_Order_Item_Product();
|
|
|
|
$item_2->set_props(
|
|
|
|
array(
|
|
|
|
'product' => WC_Helper_Product::create_simple_product(),
|
|
|
|
'quantity' => 2,
|
|
|
|
)
|
|
|
|
);
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item_1 );
|
|
|
|
$object->add_item( $item_2 );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$this->assertEquals( 6, $object->get_item_count() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_item
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_item() {
|
2016-08-22 17:00:52 +00:00
|
|
|
$object = new WC_Order();
|
2016-11-17 21:30:34 +00:00
|
|
|
$item = new WC_Order_Item_Product();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'product' => WC_Helper_Product::create_simple_product(),
|
|
|
|
'quantity' => 4,
|
|
|
|
)
|
|
|
|
);
|
2017-06-28 05:28:23 +00:00
|
|
|
$item->save();
|
|
|
|
$object->add_item( $item->get_id() );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
2017-12-13 14:11:47 +00:00
|
|
|
$this->assertTrue( $object->get_item( $item->get_id() ) instanceof WC_Order_Item_Product );
|
2016-06-23 14:52:12 +00:00
|
|
|
|
2016-08-22 15:48:19 +00:00
|
|
|
$object = new WC_Order();
|
2016-11-17 21:30:34 +00:00
|
|
|
$item = new WC_Order_Item_Coupon();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'code' => '12345',
|
|
|
|
'discount' => 10,
|
|
|
|
'discount_tax' => 5,
|
|
|
|
)
|
|
|
|
);
|
2016-08-22 15:48:19 +00:00
|
|
|
$item_id = $item->save();
|
|
|
|
$object->add_item( $item );
|
|
|
|
$object->save();
|
2017-12-13 14:11:47 +00:00
|
|
|
$this->assertTrue( $object->get_item( $item_id ) instanceof WC_Order_Item_Coupon );
|
2016-06-23 14:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: add_payment_token
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_add_payment_token() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$this->assertFalse( $object->add_payment_token( 'fish' ) );
|
|
|
|
$token = new WC_Payment_Token_Stub();
|
|
|
|
$token->set_extra( __FUNCTION__ );
|
|
|
|
$token->set_token( time() );
|
2016-11-23 16:27:18 +00:00
|
|
|
$token->save();
|
2016-06-23 14:52:12 +00:00
|
|
|
$this->assertTrue( 0 < $object->add_payment_token( $token ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_payment_tokens
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_payment_tokens() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$token = new WC_Payment_Token_Stub();
|
|
|
|
$token->set_extra( __FUNCTION__ );
|
|
|
|
$token->set_token( time() );
|
2016-11-23 16:27:18 +00:00
|
|
|
$token->save();
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->add_payment_token( $token );
|
|
|
|
$this->assertCount( 1, $object->get_payment_tokens() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: calculate_shipping
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_calculate_shipping() {
|
2016-06-23 14:52:12 +00:00
|
|
|
$object = new WC_Order();
|
2016-08-22 15:48:19 +00:00
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', array(), 'flat_rate' );
|
2016-11-17 21:30:34 +00:00
|
|
|
$item_1 = new WC_Order_Item_Shipping();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item_1->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item_1->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-11-17 21:30:34 +00:00
|
|
|
$item_2 = new WC_Order_Item_Shipping();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item_2->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-08-22 17:00:52 +00:00
|
|
|
$object->add_item( $item_1 );
|
|
|
|
$object->add_item( $item_2 );
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
|
|
|
$object->calculate_shipping();
|
|
|
|
$this->assertEquals( 20, $object->get_shipping_total() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: calculate_taxes
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_calculate_taxes() {
|
2016-06-23 14:52:12 +00:00
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
2016-08-27 01:46:45 +00:00
|
|
|
'tax_rate_class' => '',
|
2016-06-23 14:52:12 +00:00
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
2016-08-22 17:00:52 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->add_product( WC_Helper_Product::create_simple_product(), 4 );
|
2016-08-22 15:48:19 +00:00
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', array(), 'flat_rate' );
|
|
|
|
$item = new WC_Order_Item_Shipping();
|
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
|
|
|
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->calculate_taxes();
|
|
|
|
$this->assertEquals( 5, $object->get_total_tax() );
|
2017-10-31 13:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: calculate_taxes_is_vat_excempt
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_calculate_taxes_is_vat_excempt() {
|
2017-10-31 13:51:06 +00:00
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
|
|
|
$object = new WC_Order();
|
|
|
|
$object->add_product( WC_Helper_Product::create_simple_product(), 4 );
|
2017-12-13 14:11:47 +00:00
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', array(), 'flat_rate' );
|
|
|
|
$item = new WC_Order_Item_Shipping();
|
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-10-31 13:51:06 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
|
|
|
$object->add_item( $item );
|
|
|
|
|
|
|
|
$object->calculate_taxes();
|
|
|
|
$this->assertEquals( 5, $object->get_total_tax() );
|
|
|
|
|
|
|
|
// Add VAT except meta.
|
|
|
|
$object->add_meta_data( 'is_vat_exempt', 'yes', true );
|
|
|
|
$object->save();
|
|
|
|
$object->calculate_taxes();
|
|
|
|
$this->assertEquals( 0, $object->get_total_tax() );
|
2016-06-23 14:52:12 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 14:19:51 +00:00
|
|
|
/**
|
|
|
|
* Test: calculate_taxes_issue_with_addresses
|
|
|
|
*/
|
|
|
|
public function test_calculate_taxes_issue_with_addresses() {
|
2017-06-01 19:51:55 +00:00
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
|
|
|
|
$taxes = array();
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$taxes[] = WC_Tax::_insert_tax_rate(
|
|
|
|
array(
|
|
|
|
'tax_rate_country' => 'US',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '20.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$taxes[] = WC_Tax::_insert_tax_rate(
|
|
|
|
array(
|
|
|
|
'tax_rate_country' => 'PY',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
|
|
|
'tax_rate_class' => '',
|
|
|
|
)
|
|
|
|
);
|
2017-06-01 19:51:55 +00:00
|
|
|
|
|
|
|
update_option( 'woocommerce_default_country', 'PY:Central' );
|
|
|
|
update_option( 'woocommerce_tax_based_on', 'shipping' );
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$order = new WC_Order();
|
2017-06-01 19:51:55 +00:00
|
|
|
$order->set_billing_country( 'US' );
|
|
|
|
$order->set_billing_state( 'CA' );
|
|
|
|
$order->add_product( WC_Helper_Product::create_simple_product(), 4 );
|
|
|
|
$order->calculate_taxes();
|
|
|
|
|
|
|
|
$tax = $order->get_taxes();
|
|
|
|
$this->assertEquals( 1, count( $tax ) );
|
|
|
|
$this->assertEquals( 'US-TAX-1', current( $tax )->get_name() );
|
|
|
|
}
|
|
|
|
|
2016-06-23 14:52:12 +00:00
|
|
|
/**
|
|
|
|
* Test: calculate_totals
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_calculate_totals() {
|
2016-06-23 14:52:12 +00:00
|
|
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
|
|
|
$tax_rate = array(
|
|
|
|
'tax_rate_country' => '',
|
|
|
|
'tax_rate_state' => '',
|
|
|
|
'tax_rate' => '10.0000',
|
|
|
|
'tax_rate_name' => 'TAX',
|
|
|
|
'tax_rate_priority' => '1',
|
|
|
|
'tax_rate_compound' => '0',
|
|
|
|
'tax_rate_shipping' => '1',
|
|
|
|
'tax_rate_order' => '1',
|
2016-08-27 01:46:45 +00:00
|
|
|
'tax_rate_class' => '',
|
2016-06-23 14:52:12 +00:00
|
|
|
);
|
|
|
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
2016-08-22 17:00:52 +00:00
|
|
|
$object->add_product( WC_Helper_Product::create_simple_product(), 4 );
|
2016-08-22 15:48:19 +00:00
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', array(), 'flat_rate' );
|
|
|
|
$item = new WC_Order_Item_Shipping();
|
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
|
|
|
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->calculate_totals();
|
|
|
|
$this->assertEquals( 55, $object->get_total() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: has_status
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_has_status() {
|
2016-06-23 14:52:12 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertFalse( $object->has_status( 'completed' ) );
|
|
|
|
$this->assertFalse( $object->has_status( array( 'processing', 'completed' ) ) );
|
|
|
|
$this->assertTrue( $object->has_status( 'pending' ) );
|
|
|
|
$this->assertTrue( $object->has_status( array( 'processing', 'pending' ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: has_shipping_method
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_has_shipping_method() {
|
2016-08-22 15:48:19 +00:00
|
|
|
$object = new WC_Order();
|
2016-06-23 14:52:12 +00:00
|
|
|
$object->save();
|
2016-08-22 15:48:19 +00:00
|
|
|
|
2016-06-23 14:52:12 +00:00
|
|
|
$this->assertFalse( $object->has_shipping_method( 'flat_rate_shipping' ) );
|
2016-08-22 15:48:19 +00:00
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$rate = new WC_Shipping_Rate( 'flat_rate_shipping:1', 'Flat rate shipping', '10', array(), 'flat_rate' );
|
|
|
|
$item = new WC_Order_Item_Shipping();
|
|
|
|
$item->set_props(
|
|
|
|
array(
|
|
|
|
'method_title' => $rate->label,
|
|
|
|
'method_id' => $rate->id,
|
|
|
|
'total' => wc_format_decimal( $rate->cost ),
|
|
|
|
'taxes' => $rate->taxes,
|
|
|
|
)
|
|
|
|
);
|
2017-01-23 11:30:53 +00:00
|
|
|
foreach ( $rate->get_meta_data() as $key => $value ) {
|
|
|
|
$item->add_meta_data( $key, $value, true );
|
|
|
|
}
|
2016-08-22 15:48:19 +00:00
|
|
|
$object->add_item( $item );
|
|
|
|
$object->save();
|
|
|
|
|
2016-06-23 14:52:12 +00:00
|
|
|
$this->assertTrue( $object->has_shipping_method( 'flat_rate_shipping' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: key_is_valid
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_key_is_valid() {
|
2016-06-23 14:52:12 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->save();
|
|
|
|
$this->assertFalse( $object->key_is_valid( '1234' ) );
|
|
|
|
$object->set_order_key( '1234' );
|
|
|
|
$this->assertTrue( $object->key_is_valid( '1234' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: has_free_item
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_has_free_item() {
|
2016-08-22 17:00:52 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->add_product( WC_Helper_Product::create_simple_product(), 4 );
|
2016-06-23 14:52:12 +00:00
|
|
|
$this->assertFalse( $object->has_free_item() );
|
|
|
|
|
|
|
|
$free_product = WC_Helper_Product::create_simple_product();
|
|
|
|
$free_product->set_price( 0 );
|
2016-08-22 17:00:52 +00:00
|
|
|
$object->add_product( $free_product, 4 );
|
2016-06-23 14:52:12 +00:00
|
|
|
$this->assertTrue( $object->has_free_item() );
|
|
|
|
}
|
|
|
|
|
2016-06-22 11:29:23 +00:00
|
|
|
/**
|
|
|
|
* Test: CRUD
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_CRUD() {
|
2016-06-22 11:29:23 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
|
2017-12-13 14:19:51 +00:00
|
|
|
// Save + create.
|
2016-06-22 11:29:23 +00:00
|
|
|
$save_id = $object->save();
|
|
|
|
$post = get_post( $save_id );
|
|
|
|
$this->assertEquals( 'shop_order', $post->post_type );
|
|
|
|
$this->assertEquals( 'shop_order', $post->post_type );
|
|
|
|
|
2017-12-13 14:19:51 +00:00
|
|
|
// Update.
|
2016-06-22 11:29:23 +00:00
|
|
|
$update_id = $object->save();
|
|
|
|
$this->assertEquals( $update_id, $save_id );
|
|
|
|
|
2017-12-13 14:19:51 +00:00
|
|
|
// Delete.
|
2016-11-18 11:14:09 +00:00
|
|
|
$object->delete( true );
|
2016-06-22 11:29:23 +00:00
|
|
|
$post = get_post( $save_id );
|
|
|
|
$this->assertNull( $post );
|
|
|
|
}
|
|
|
|
|
2016-06-22 13:07:42 +00:00
|
|
|
/**
|
|
|
|
* Test: payment_complete
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_payment_complete() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertFalse( $object->payment_complete() );
|
|
|
|
$object->save();
|
|
|
|
$this->assertTrue( $object->payment_complete( '12345' ) );
|
|
|
|
$this->assertEquals( 'completed', $object->get_status() );
|
|
|
|
$this->assertEquals( '12345', $object->get_transaction_id() );
|
|
|
|
}
|
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
/**
|
|
|
|
* Test that exceptions thrown during payment_complete are handled.
|
|
|
|
* Note: This can't actually test the transaction rollbacks since WC transactions are disabled in unit tests.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
public function test_payment_complete_error() {
|
|
|
|
$object = new WC_Order();
|
|
|
|
$object->save();
|
2018-01-04 18:31:28 +00:00
|
|
|
|
|
|
|
add_action( 'woocommerce_payment_complete', array( $this, 'throwAnException' ) );
|
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
$this->assertFalse( $object->payment_complete( '12345' ) );
|
2018-05-08 14:55:32 +00:00
|
|
|
$note = current(
|
|
|
|
wc_get_order_notes(
|
|
|
|
array(
|
|
|
|
'order_id' => $object->get_id(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2018-01-04 18:28:52 +00:00
|
|
|
$this->assertContains( 'Payment complete event failed', $note->content );
|
2018-01-04 18:31:28 +00:00
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
remove_action( 'woocommerce_payment_complete', array( $this, 'throwAnException' ) );
|
|
|
|
}
|
|
|
|
|
2016-06-22 13:07:42 +00:00
|
|
|
/**
|
|
|
|
* Test: get_formatted_order_total
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_formatted_order_total() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_total( 100 );
|
|
|
|
$object->set_currency( 'USD' );
|
2018-01-12 14:20:39 +00:00
|
|
|
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>100.00</span>', $object->get_formatted_order_total() );
|
2016-06-22 13:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: set_status
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_set_status() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_status( 'on-hold' );
|
|
|
|
$this->assertEquals( 'on-hold', $object->get_status() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: update_status
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_update_status() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertFalse( $object->update_status( 'on-hold' ) );
|
|
|
|
$object->save();
|
|
|
|
$this->assertTrue( $object->update_status( 'on-hold' ) );
|
|
|
|
$this->assertEquals( 'on-hold', $object->get_status() );
|
|
|
|
}
|
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
/**
|
|
|
|
* Test that exceptions thrown during update_status are handled.
|
|
|
|
* Note: This can't actually test the transaction rollbacks since WC transactions are disabled in unit tests.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
public function test_update_status_error() {
|
|
|
|
$object = new WC_Order();
|
|
|
|
$object->save();
|
2018-01-04 18:31:28 +00:00
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'throwAnException' ) );
|
2018-01-04 18:31:28 +00:00
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
$this->assertFalse( $object->update_status( 'on-hold' ) );
|
2018-05-08 14:55:32 +00:00
|
|
|
$note = current(
|
|
|
|
wc_get_order_notes(
|
|
|
|
array(
|
|
|
|
'order_id' => $object->get_id(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2018-01-04 18:28:52 +00:00
|
|
|
$this->assertContains( 'Update status event failed', $note->content );
|
2018-01-04 18:31:28 +00:00
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
remove_filter( 'woocommerce_payment_complete_order_status', array( $this, 'throwAnException' ) );
|
|
|
|
}
|
|
|
|
|
2018-10-06 18:05:34 +00:00
|
|
|
/**
|
|
|
|
* Test: status_transition
|
|
|
|
*/
|
|
|
|
public function test_status_transition_handles_transition_errors() {
|
|
|
|
$object = new WC_Order();
|
|
|
|
$object->save();
|
|
|
|
|
|
|
|
add_filter( 'woocommerce_order_status_on-hold', array( $this, 'throwAnException' ) );
|
|
|
|
$object->update_status( 'on-hold' );
|
|
|
|
remove_filter( 'woocommerce_order_status_on-hold', array( $this, 'throwAnException' ) );
|
|
|
|
|
|
|
|
$note = current(
|
|
|
|
wc_get_order_notes(
|
|
|
|
array(
|
|
|
|
'order_id' => $object->get_id(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertContains( __( 'Error during status transition.', 'woocommerce' ), $note->content );
|
|
|
|
}
|
|
|
|
|
2016-06-22 13:07:42 +00:00
|
|
|
/**
|
|
|
|
* Test: get_billing_first_name
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_first_name() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Fred';
|
|
|
|
$object->set_billing_first_name( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_first_name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_last_name
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_last_name() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Flintstone';
|
|
|
|
$object->set_billing_last_name( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_last_name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_company
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_company() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Bedrock Ltd.';
|
|
|
|
$object->set_billing_company( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_company() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_address_1
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_address_1() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '34 Stonepants avenue';
|
|
|
|
$object->set_billing_address_1( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_address_1() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_address_2
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_address_2() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Rockville';
|
|
|
|
$object->set_billing_address_2( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_address_2() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_city
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_city() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Bedrock';
|
|
|
|
$object->set_billing_city( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_city() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_state
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_state() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
2017-03-08 19:51:38 +00:00
|
|
|
$set_to = 'Oregon';
|
2016-06-22 13:07:42 +00:00
|
|
|
$object->set_billing_state( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_state() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_postcode
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_postcode() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '00001';
|
|
|
|
$object->set_billing_postcode( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_postcode() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_country
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_country() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'US';
|
|
|
|
$object->set_billing_country( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_country() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_email
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_email() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'test@test.com';
|
|
|
|
$object->set_billing_email( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_email() );
|
|
|
|
|
|
|
|
$set_to = 'not an email';
|
2017-12-13 14:20:18 +00:00
|
|
|
$this->setExpectedException( 'WC_Data_Exception', 'Invalid billing email address' );
|
2016-06-22 13:07:42 +00:00
|
|
|
$object->set_billing_email( $set_to );
|
2016-08-23 17:48:48 +00:00
|
|
|
$this->assertEquals( 'test@test.com', $object->get_billing_email() );
|
2016-06-22 13:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_billing_phone
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_billing_phone() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '123456678';
|
|
|
|
$object->set_billing_phone( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_billing_phone() );
|
|
|
|
}
|
|
|
|
|
2017-03-08 20:02:14 +00:00
|
|
|
/**
|
|
|
|
* Test: Setting/getting billing settings after an order is saved
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_set_billing_after_save() {
|
2017-03-08 19:51:38 +00:00
|
|
|
$object = new WC_Order();
|
2017-12-13 14:11:47 +00:00
|
|
|
$phone = '123456678';
|
2017-03-08 19:51:38 +00:00
|
|
|
$object->set_billing_phone( $phone );
|
|
|
|
$object->save();
|
|
|
|
$state = 'Oregon';
|
|
|
|
$object->set_billing_state( $state );
|
|
|
|
|
|
|
|
$this->assertEquals( $phone, $object->get_billing_phone() );
|
|
|
|
$this->assertEquals( $state, $object->get_billing_state() );
|
|
|
|
}
|
|
|
|
|
2016-06-22 13:07:42 +00:00
|
|
|
/**
|
|
|
|
* Test: get_shipping_first_name
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_first_name() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Fred';
|
|
|
|
$object->set_shipping_first_name( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_first_name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_last_name
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_last_name() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Flintstone';
|
|
|
|
$object->set_shipping_last_name( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_last_name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_company
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_company() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Bedrock Ltd.';
|
|
|
|
$object->set_shipping_company( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_company() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_address_1
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_address_1() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '34 Stonepants avenue';
|
|
|
|
$object->set_shipping_address_1( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_address_1() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_address_2
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_address_2() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Rockville';
|
|
|
|
$object->set_shipping_address_2( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_address_2() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_city
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_city() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Bedrock';
|
|
|
|
$object->set_shipping_city( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_city() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_state
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_state() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
2017-03-08 19:51:38 +00:00
|
|
|
$set_to = 'Oregon';
|
2016-06-22 13:07:42 +00:00
|
|
|
$object->set_shipping_state( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_state() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_postcode
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_postcode() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '00001';
|
|
|
|
$object->set_shipping_postcode( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_postcode() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_country
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_country() {
|
2016-06-22 13:07:42 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'US';
|
|
|
|
$object->set_shipping_country( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_shipping_country() );
|
|
|
|
}
|
2016-06-22 13:28:00 +00:00
|
|
|
|
2017-10-27 20:37:00 +00:00
|
|
|
/**
|
|
|
|
* Test get_formatted_billing_address and has_billing_address.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_has_formatted_billing_address() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$order = new WC_Order();
|
2017-10-27 20:37:00 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 'none', $order->get_formatted_billing_address( 'none' ) );
|
|
|
|
|
|
|
|
$order->set_billing_address_1( '123 Test St.' );
|
|
|
|
$order->set_billing_country( 'US' );
|
|
|
|
$order->set_billing_city( 'Portland' );
|
|
|
|
$order->set_billing_postcode( '97266' );
|
|
|
|
$this->assertEquals( '123 Test St.<br/>Portland, 97266<br/>United States (US)', $order->get_formatted_billing_address( 'none' ) );
|
|
|
|
|
|
|
|
$this->assertTrue( $order->has_billing_address() );
|
|
|
|
$this->assertFalse( $order->has_shipping_address() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test get_formatted_shipping_address and has_shipping_address.
|
|
|
|
*
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_has_formatted_shipping_address() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$order = new WC_Order();
|
2017-10-27 20:37:00 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 'none', $order->get_formatted_shipping_address( 'none' ) );
|
|
|
|
|
|
|
|
$order->set_shipping_address_1( '123 Test St.' );
|
|
|
|
$order->set_shipping_country( 'US' );
|
|
|
|
$order->set_shipping_city( 'Portland' );
|
|
|
|
$order->set_shipping_postcode( '97266' );
|
|
|
|
$this->assertEquals( '123 Test St.<br/>Portland, 97266<br/>United States (US)', $order->get_formatted_shipping_address( 'none' ) );
|
|
|
|
|
|
|
|
$this->assertFalse( $order->has_billing_address() );
|
|
|
|
$this->assertTrue( $order->has_shipping_address() );
|
|
|
|
}
|
|
|
|
|
2017-03-08 20:02:14 +00:00
|
|
|
/**
|
|
|
|
* Test: Setting/getting shipping settings after an order is saved
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_set_shipping_after_save() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
2017-03-08 19:51:38 +00:00
|
|
|
$country = 'US';
|
|
|
|
$object->set_shipping_country( $country );
|
|
|
|
$object->save();
|
|
|
|
$state = 'Oregon';
|
|
|
|
$object->set_shipping_state( $state );
|
|
|
|
|
|
|
|
$this->assertEquals( $country, $object->get_shipping_country() );
|
|
|
|
$this->assertEquals( $state, $object->get_shipping_state() );
|
|
|
|
}
|
|
|
|
|
2016-06-22 13:28:00 +00:00
|
|
|
/**
|
|
|
|
* Test: get_payment_method
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_payment_method() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'paypal';
|
|
|
|
$object->set_payment_method( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_payment_method() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_payment_method_title
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_payment_method_title() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'PayPal';
|
|
|
|
$object->set_payment_method_title( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_payment_method_title() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_transaction_id
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_transaction_id() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '12345';
|
|
|
|
$object->set_transaction_id( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_transaction_id() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_customer_ip_address
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_customer_ip_address() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '192.168.1.1';
|
|
|
|
$object->set_customer_ip_address( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_customer_ip_address() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_customer_user_agent
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_customer_user_agent() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'UAstring';
|
|
|
|
$object->set_customer_user_agent( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_customer_user_agent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_created_via
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_created_via() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'WooCommerce';
|
|
|
|
$object->set_created_via( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_created_via() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_customer_note
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_customer_note() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'Leave on porch.';
|
|
|
|
$object->set_customer_note( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_customer_note() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_date_completed
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_date_completed() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_date_completed( '2016-12-12' );
|
2017-03-10 14:52:41 +00:00
|
|
|
$this->assertEquals( '1481500800', $object->get_date_completed()->getOffsetTimestamp() );
|
2016-06-22 13:28:00 +00:00
|
|
|
|
|
|
|
$object->set_date_completed( '1481500800' );
|
2017-03-10 14:52:41 +00:00
|
|
|
$this->assertEquals( 1481500800, $object->get_date_completed()->getTimestamp() );
|
2016-06-22 13:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_date_paid
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_date_paid() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = 'PayPal';
|
|
|
|
$object->set_date_paid( '2016-12-12' );
|
2017-03-10 14:52:41 +00:00
|
|
|
$this->assertEquals( 1481500800, $object->get_date_paid()->getOffsetTimestamp() );
|
2016-06-22 13:28:00 +00:00
|
|
|
|
|
|
|
$object->set_date_paid( '1481500800' );
|
2017-03-10 14:52:41 +00:00
|
|
|
$this->assertEquals( 1481500800, $object->get_date_paid()->getTimestamp() );
|
2016-06-22 13:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_cart_hash
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_cart_hash() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$set_to = '12345';
|
|
|
|
$object->set_cart_hash( $set_to );
|
|
|
|
$this->assertEquals( $set_to, $object->get_cart_hash() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_address
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_address() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
|
|
|
|
$billing = array(
|
|
|
|
'first_name' => 'Fred',
|
|
|
|
'last_name' => 'Flintstone',
|
|
|
|
'company' => 'Bedrock Ltd.',
|
|
|
|
'address_1' => '34 Stonepants avenue',
|
|
|
|
'address_2' => 'Rockville',
|
|
|
|
'city' => 'Bedrock',
|
|
|
|
'state' => 'Boulder',
|
|
|
|
'postcode' => '00001',
|
|
|
|
'country' => 'US',
|
|
|
|
'email' => '',
|
|
|
|
'phone' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
$shipping = array(
|
|
|
|
'first_name' => 'Barney',
|
|
|
|
'last_name' => 'Rubble',
|
|
|
|
'company' => 'Bedrock Ltd.',
|
|
|
|
'address_1' => '34 Stonepants avenue',
|
|
|
|
'address_2' => 'Rockville',
|
|
|
|
'city' => 'Bedrock',
|
|
|
|
'state' => 'Boulder',
|
|
|
|
'postcode' => '00001',
|
|
|
|
'country' => 'US',
|
|
|
|
);
|
|
|
|
|
|
|
|
$object->set_billing_first_name( 'Fred' );
|
|
|
|
$object->set_billing_last_name( 'Flintstone' );
|
|
|
|
$object->set_billing_company( 'Bedrock Ltd.' );
|
|
|
|
$object->set_billing_address_1( '34 Stonepants avenue' );
|
|
|
|
$object->set_billing_address_2( 'Rockville' );
|
|
|
|
$object->set_billing_city( 'Bedrock' );
|
|
|
|
$object->set_billing_state( 'Boulder' );
|
|
|
|
$object->set_billing_postcode( '00001' );
|
|
|
|
$object->set_billing_country( 'US' );
|
|
|
|
|
|
|
|
$object->set_shipping_first_name( 'Barney' );
|
|
|
|
$object->set_shipping_last_name( 'Rubble' );
|
|
|
|
$object->set_shipping_company( 'Bedrock Ltd.' );
|
|
|
|
$object->set_shipping_address_1( '34 Stonepants avenue' );
|
|
|
|
$object->set_shipping_address_2( 'Rockville' );
|
|
|
|
$object->set_shipping_city( 'Bedrock' );
|
|
|
|
$object->set_shipping_state( 'Boulder' );
|
|
|
|
$object->set_shipping_postcode( '00001' );
|
|
|
|
$object->set_shipping_country( 'US' );
|
|
|
|
|
|
|
|
$this->assertEquals( $billing, $object->get_address() );
|
|
|
|
$this->assertEquals( $shipping, $object->get_address( 'shipping' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_shipping_address_map_url
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_shipping_address_map_url() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_shipping_first_name( 'Barney' );
|
|
|
|
$object->set_shipping_last_name( 'Rubble' );
|
|
|
|
$object->set_shipping_company( 'Bedrock Ltd.' );
|
|
|
|
$object->set_shipping_address_1( '34 Stonepants avenue' );
|
|
|
|
$object->set_shipping_address_2( 'Rockville' );
|
|
|
|
$object->set_shipping_city( 'Bedrock' );
|
|
|
|
$object->set_shipping_state( 'Boulder' );
|
|
|
|
$object->set_shipping_postcode( '00001' );
|
|
|
|
$object->set_shipping_country( 'US' );
|
2017-11-29 12:32:35 +00:00
|
|
|
$this->assertEquals( 'https://maps.google.com/maps?&q=34%20Stonepants%20avenue%2C%20Rockville%2C%20Bedrock%2C%20Boulder%2C%2000001%2C%20US&z=16', $object->get_shipping_address_map_url() );
|
2016-06-22 13:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_formatted_billing_full_name
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_formatted_billing_full_name() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_billing_first_name( 'Fred' );
|
|
|
|
$object->set_billing_last_name( 'Flintstone' );
|
|
|
|
$this->assertEquals( 'Fred Flintstone', $object->get_formatted_billing_full_name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_formatted_shipping_full_name
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_formatted_shipping_full_name() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_shipping_first_name( 'Barney' );
|
|
|
|
$object->set_shipping_last_name( 'Rubble' );
|
|
|
|
$this->assertEquals( 'Barney Rubble', $object->get_formatted_shipping_full_name() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_formatted_billing_address
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_formatted_billing_address() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_billing_first_name( 'Fred' );
|
|
|
|
$object->set_billing_last_name( 'Flintstone' );
|
|
|
|
$object->set_billing_company( 'Bedrock Ltd.' );
|
|
|
|
$object->set_billing_address_1( '34 Stonepants avenue' );
|
|
|
|
$object->set_billing_address_2( 'Rockville' );
|
|
|
|
$object->set_billing_city( 'Bedrock' );
|
|
|
|
$object->set_billing_state( 'Boulder' );
|
|
|
|
$object->set_billing_postcode( '00001' );
|
|
|
|
$object->set_billing_country( 'US' );
|
|
|
|
$this->assertEquals( 'Fred Flintstone<br/>Bedrock Ltd.<br/>34 Stonepants avenue<br/>Rockville<br/>Bedrock, BOULDER 00001<br/>United States (US)', $object->get_formatted_billing_address() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_formatted_shipping_address
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_formatted_shipping_address() {
|
2016-06-22 13:28:00 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_shipping_first_name( 'Barney' );
|
|
|
|
$object->set_shipping_last_name( 'Rubble' );
|
|
|
|
$object->set_shipping_company( 'Bedrock Ltd.' );
|
|
|
|
$object->set_shipping_address_1( '34 Stonepants avenue' );
|
|
|
|
$object->set_shipping_address_2( 'Rockville' );
|
|
|
|
$object->set_shipping_city( 'Bedrock' );
|
|
|
|
$object->set_shipping_state( 'Boulder' );
|
|
|
|
$object->set_shipping_postcode( '00001' );
|
|
|
|
$object->set_shipping_country( 'US' );
|
|
|
|
$this->assertEquals( 'Barney Rubble<br/>Bedrock Ltd.<br/>34 Stonepants avenue<br/>Rockville<br/>Bedrock, BOULDER 00001<br/>United States (US)', $object->get_formatted_shipping_address() );
|
|
|
|
}
|
2016-06-22 14:38:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: has_cart_hash
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_has_cart_hash() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertFalse( $object->has_cart_hash( '12345' ) );
|
|
|
|
$set_to = '12345';
|
|
|
|
$object->set_cart_hash( $set_to );
|
|
|
|
$this->assertTrue( $object->has_cart_hash( '12345' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: is_editable
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_is_editable() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_status( 'pending' );
|
|
|
|
$this->assertTrue( $object->is_editable() );
|
|
|
|
$object->set_status( 'processing' );
|
|
|
|
$this->assertFalse( $object->is_editable() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: is_paid
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_is_paid() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_status( 'pending' );
|
|
|
|
$this->assertFalse( $object->is_paid() );
|
|
|
|
$object->set_status( 'processing' );
|
|
|
|
$this->assertTrue( $object->is_paid() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: is_download_permitted
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_is_download_permitted() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_status( 'pending' );
|
|
|
|
$this->assertFalse( $object->is_download_permitted() );
|
|
|
|
$object->set_status( 'completed' );
|
|
|
|
$this->assertTrue( $object->is_download_permitted() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: needs_shipping_address
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_needs_shipping_address() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertFalse( $object->needs_shipping_address() );
|
|
|
|
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = WC_Helper_Order::create_order();
|
|
|
|
$this->assertTrue( $object->needs_shipping_address() );
|
2016-06-22 14:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: has_downloadable_item
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_has_downloadable_item() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertFalse( $object->has_downloadable_item() );
|
|
|
|
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = WC_Helper_Order::create_order();
|
|
|
|
$this->assertFalse( $object->has_downloadable_item() );
|
2016-06-22 14:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: needs_payment
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_needs_payment() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
|
|
|
|
$object->set_status( 'pending' );
|
|
|
|
$this->assertFalse( $object->needs_payment() );
|
|
|
|
|
|
|
|
$object->set_total( 100 );
|
|
|
|
$this->assertTrue( $object->needs_payment() );
|
|
|
|
|
|
|
|
$object->set_status( 'processing' );
|
|
|
|
$this->assertFalse( $object->needs_payment() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_checkout_payment_url
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_checkout_payment_url() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$id = $object->save();
|
2016-08-04 16:24:23 +00:00
|
|
|
$this->assertEquals( 'http://example.org?order-pay=' . $id . '&pay_for_order=true&key=' . $object->get_order_key(), $object->get_checkout_payment_url() );
|
2016-06-22 14:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_checkout_order_received_url
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_checkout_order_received_url() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_order_key( 'xxx' );
|
2017-12-13 14:11:47 +00:00
|
|
|
$id = $object->save();
|
2016-08-04 16:24:23 +00:00
|
|
|
$this->assertEquals( 'http://example.org?order-received=' . $id . '&key=' . $object->get_order_key(), $object->get_checkout_order_received_url() );
|
2016-06-22 14:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_cancel_order_url
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_cancel_order_url() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertInternalType( 'string', $object->get_cancel_order_url() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_cancel_order_url_raw
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_cancel_order_url_raw() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertInternalType( 'string', $object->get_cancel_order_url_raw() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_cancel_endpoint
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_cancel_endpoint() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 'http://example.org/', $object->get_cancel_endpoint() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_view_order_url
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_view_order_url() {
|
2016-06-22 14:38:28 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$id = $object->save();
|
2016-08-04 16:24:23 +00:00
|
|
|
$this->assertEquals( 'http://example.org?view-order=' . $id, $object->get_view_order_url() );
|
2016-06-22 14:38:28 +00:00
|
|
|
}
|
2016-06-22 15:31:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: add_order_note
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_add_order_note() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$id = $object->save();
|
2017-12-13 14:11:47 +00:00
|
|
|
$comment_id = $object->add_order_note( 'Hello, I am a fish' );
|
2016-06-22 15:31:05 +00:00
|
|
|
$this->assertTrue( $comment_id > 0 );
|
|
|
|
|
|
|
|
$comment = get_comment( $comment_id );
|
2017-12-13 14:11:47 +00:00
|
|
|
$this->assertEquals( 'Hello, I am a fish', $comment->comment_content );
|
2016-06-22 15:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_customer_order_notes
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_customer_order_notes() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$id = $object->save();
|
2016-06-22 15:31:05 +00:00
|
|
|
|
|
|
|
$this->assertCount( 0, $object->get_customer_order_notes() );
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$object->add_order_note( 'Hello, I am a fish', true );
|
|
|
|
$object->add_order_note( 'Hello, I am a fish', false );
|
|
|
|
$object->add_order_note( 'Hello, I am a fish', true );
|
2016-06-22 15:31:05 +00:00
|
|
|
|
|
|
|
$this->assertCount( 2, $object->get_customer_order_notes() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_refunds
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_refunds() {
|
2017-12-13 14:11:47 +00:00
|
|
|
$object = new WC_Order();
|
2017-02-09 12:04:44 +00:00
|
|
|
$object->set_total( 100 );
|
2017-12-13 14:11:47 +00:00
|
|
|
$id = $object->save();
|
2016-06-22 15:31:05 +00:00
|
|
|
|
|
|
|
$this->assertCount( 0, $object->get_refunds() );
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
wc_create_refund(
|
|
|
|
array(
|
|
|
|
'order_id' => $id,
|
|
|
|
'amount' => '100',
|
|
|
|
'line_items' => array(),
|
|
|
|
)
|
|
|
|
);
|
2016-06-22 15:31:05 +00:00
|
|
|
|
|
|
|
$this->assertCount( 1, $object->get_refunds() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_refunded
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_refunded() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_total( 400 );
|
2017-12-13 14:11:47 +00:00
|
|
|
$id = $object->save();
|
|
|
|
wc_create_refund(
|
|
|
|
array(
|
|
|
|
'order_id' => $id,
|
|
|
|
'amount' => '100',
|
|
|
|
'line_items' => array(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
wc_create_refund(
|
|
|
|
array(
|
|
|
|
'order_id' => $id,
|
|
|
|
'amount' => '100',
|
|
|
|
'line_items' => array(),
|
|
|
|
)
|
|
|
|
);
|
2016-06-22 15:31:05 +00:00
|
|
|
$this->assertEquals( 200, $object->get_total_refunded() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_tax_refunded
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_tax_refunded() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 0, $object->get_total_tax_refunded() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_shipping_refunded
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_shipping_refunded() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 0, $object->get_total_shipping_refunded() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_shipping_refunded
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_qty_refunded() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 0, $object->get_total_shipping_refunded() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_qty_refunded_for_item
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_qty_refunded_for_item() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 0, $object->get_qty_refunded_for_item( 2 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: test_get_total_refunded_for_item
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_refunded_for_item() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 0, $object->get_total_refunded_for_item( 2 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_tax_refunded_for_item
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_tax_refunded_for_item() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 0, $object->get_tax_refunded_for_item( 1, 1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_tax_refunded_by_rate_id
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_total_tax_refunded_by_rate_id() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$this->assertEquals( 0, $object->get_total_tax_refunded_by_rate_id( 2 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_remaining_refund_amount
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_remaining_refund_amount() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = new WC_Order();
|
|
|
|
$object->set_total( 400 );
|
2017-12-13 14:11:47 +00:00
|
|
|
$id = $object->save();
|
|
|
|
wc_create_refund(
|
|
|
|
array(
|
|
|
|
'order_id' => $id,
|
|
|
|
'amount' => '100',
|
|
|
|
'line_items' => array(),
|
|
|
|
)
|
|
|
|
);
|
2016-06-22 15:31:05 +00:00
|
|
|
$this->assertEquals( 300, $object->get_remaining_refund_amount() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: get_total_tax_refunded_by_rate_id
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_get_remaining_refund_items() {
|
2016-06-22 15:31:05 +00:00
|
|
|
$object = WC_Helper_Order::create_order();
|
|
|
|
$this->assertEquals( 4, $object->get_remaining_refund_items() );
|
|
|
|
}
|
2017-08-10 20:37:05 +00:00
|
|
|
|
2017-11-22 16:03:58 +00:00
|
|
|
/**
|
|
|
|
* Test that if an exception is thrown when creating a refund, the refund is deleted from database.
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_refund_exception() {
|
2017-11-22 16:03:58 +00:00
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
add_action( 'woocommerce_create_refund', array( $this, 'throwAnException' ) );
|
2017-12-13 14:11:47 +00:00
|
|
|
$refund = wc_create_refund(
|
|
|
|
array(
|
|
|
|
'order_id' => $order->get_id(),
|
|
|
|
'amount' => $order->get_total(),
|
|
|
|
'line_items' => array(),
|
|
|
|
)
|
|
|
|
);
|
2017-11-22 16:03:58 +00:00
|
|
|
remove_action( 'woocommerce_create_refund', array( $this, 'throwAnException' ) );
|
|
|
|
$this->assertEmpty( $order->get_refunds() );
|
|
|
|
}
|
|
|
|
|
2017-08-10 20:37:05 +00:00
|
|
|
/**
|
2017-08-18 09:36:10 +00:00
|
|
|
* Test apply_coupon and remove_coupon with a fixed discount coupon.
|
2017-12-13 14:11:47 +00:00
|
|
|
*
|
2017-08-10 20:37:05 +00:00
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_add_remove_coupon_fixed() {
|
2017-08-10 20:37:05 +00:00
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$coupon = new WC_Coupon();
|
2017-08-10 20:37:05 +00:00
|
|
|
$coupon->set_code( 'test' );
|
|
|
|
$coupon->set_discount_type( 'fixed_cart' );
|
|
|
|
$coupon->set_amount( 10 );
|
|
|
|
$coupon->save();
|
|
|
|
|
2017-08-18 09:36:10 +00:00
|
|
|
$order->apply_coupon( 'test' );
|
2017-08-10 21:37:40 +00:00
|
|
|
$this->assertEquals( 40, $order->get_total() );
|
|
|
|
|
|
|
|
$order->remove_coupon( 'test' );
|
2017-08-10 20:37:05 +00:00
|
|
|
$this->assertEquals( 50, $order->get_total() );
|
2017-08-10 21:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-18 09:36:10 +00:00
|
|
|
* Test apply_coupon and remove_coupon with a percent discount coupon.
|
2017-12-13 14:11:47 +00:00
|
|
|
*
|
2017-08-10 21:37:40 +00:00
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_add_remove_coupon_percent() {
|
2017-08-10 21:37:40 +00:00
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
|
2017-12-13 14:11:47 +00:00
|
|
|
$coupon = new WC_Coupon();
|
2017-08-10 21:37:40 +00:00
|
|
|
$coupon->set_code( 'test' );
|
|
|
|
$coupon->set_discount_type( 'percent' );
|
|
|
|
$coupon->set_amount( 50 );
|
|
|
|
$coupon->save();
|
|
|
|
|
2017-08-18 09:36:10 +00:00
|
|
|
$order->apply_coupon( 'test' );
|
2017-08-10 21:37:40 +00:00
|
|
|
$this->assertEquals( 30, $order->get_total() );
|
2017-08-10 20:37:05 +00:00
|
|
|
|
|
|
|
$order->remove_coupon( 'test' );
|
|
|
|
$this->assertEquals( 50, $order->get_total() );
|
|
|
|
}
|
2017-11-08 12:16:22 +00:00
|
|
|
|
2019-05-27 14:45:29 +00:00
|
|
|
/**
|
|
|
|
* Test the coupon usage limit based on guest orders with emails only.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_coupon_email_usage_limit() {
|
|
|
|
// Orders.
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
|
|
|
|
|
|
|
// Setup coupon.
|
|
|
|
$coupon = new WC_Coupon();
|
|
|
|
$coupon->set_code( 'usage-limit-coupon' );
|
|
|
|
$coupon->set_amount( 100 );
|
|
|
|
$coupon->set_discount_type( 'percent' );
|
|
|
|
$coupon->set_usage_limit_per_user( 1 );
|
|
|
|
$coupon->save();
|
|
|
|
|
|
|
|
// Set as guest users with the same email.
|
|
|
|
$order1->set_customer_id( 0 );
|
|
|
|
$order1->set_billing_email( 'coupontest@example.com' );
|
|
|
|
$order2->set_customer_id( 0 );
|
|
|
|
$order2->set_billing_email( 'coupontest@example.com' );
|
|
|
|
|
|
|
|
$order1->apply_coupon( 'usage-limit-coupon' );
|
|
|
|
$this->assertEquals( 1, count( $order1->get_coupons() ) );
|
|
|
|
|
|
|
|
$order2->apply_coupon( 'usage-limit-coupon' );
|
|
|
|
$this->assertEquals( 0, count( $order2->get_coupons() ) );
|
|
|
|
}
|
|
|
|
|
2017-11-08 12:16:22 +00:00
|
|
|
/**
|
|
|
|
* Test removing and adding items + recalculation.
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2017-12-13 14:19:51 +00:00
|
|
|
public function test_add_remove_items() {
|
2017-11-08 12:16:22 +00:00
|
|
|
$product = WC_Helper_Product::create_simple_product();
|
|
|
|
$object = new WC_Order();
|
|
|
|
$item_1 = new WC_Order_Item_Product();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item_1->set_props(
|
|
|
|
array(
|
|
|
|
'product' => $product,
|
|
|
|
'quantity' => 4,
|
|
|
|
'total' => 100,
|
|
|
|
)
|
|
|
|
);
|
2017-11-08 12:16:22 +00:00
|
|
|
$item_1_id = $item_1->save();
|
2017-12-13 14:11:47 +00:00
|
|
|
$item_2 = new WC_Order_Item_Product();
|
|
|
|
$item_2->set_props(
|
|
|
|
array(
|
|
|
|
'product' => $product,
|
|
|
|
'quantity' => 2,
|
|
|
|
'total' => 100,
|
|
|
|
)
|
|
|
|
);
|
2017-11-08 12:16:22 +00:00
|
|
|
$item_2_id = $item_2->save();
|
|
|
|
$object->add_item( $item_1 );
|
|
|
|
$object->add_item( $item_2 );
|
|
|
|
$object->save();
|
|
|
|
$object->calculate_totals();
|
|
|
|
|
|
|
|
$this->assertEquals( 200, $object->get_total() );
|
|
|
|
|
|
|
|
// remove an item and add an item, then compare totals.
|
2017-11-08 12:32:08 +00:00
|
|
|
$object->remove_item( $item_1_id );
|
2017-12-13 14:11:47 +00:00
|
|
|
$item_3 = new WC_Order_Item_Product();
|
|
|
|
$item_3->set_props(
|
|
|
|
array(
|
|
|
|
'product' => $product,
|
|
|
|
'quantity' => 1,
|
|
|
|
'total' => 100,
|
|
|
|
)
|
|
|
|
);
|
2017-11-08 12:16:22 +00:00
|
|
|
$object->add_item( $item_3 );
|
|
|
|
$object->save();
|
|
|
|
$object->calculate_totals();
|
|
|
|
|
|
|
|
$this->assertEquals( 200, $object->get_total() );
|
|
|
|
}
|
2018-01-04 18:28:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that exceptions thrown during save are handled.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
public function test_save_exception() {
|
|
|
|
$object = new WC_Order();
|
|
|
|
$object->save();
|
2018-01-04 18:31:28 +00:00
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
add_action( 'woocommerce_before_order_object_save', array( $this, 'throwAnException' ) );
|
2018-01-04 18:31:28 +00:00
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
$object->save();
|
2018-05-08 14:55:32 +00:00
|
|
|
$note = current(
|
|
|
|
wc_get_order_notes(
|
|
|
|
array(
|
|
|
|
'order_id' => $object->get_id(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2018-01-04 18:28:52 +00:00
|
|
|
$this->assertContains( 'Error saving order', $note->content );
|
2018-01-04 18:31:28 +00:00
|
|
|
|
2018-01-04 18:28:52 +00:00
|
|
|
remove_action( 'woocommerce_before_order_object_save', array( $this, 'throwAnException' ) );
|
|
|
|
}
|
2020-02-04 18:13:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic test for WC_Order::get_total_fees().
|
|
|
|
*/
|
|
|
|
public function test_get_total_fees_should_return_total_fees() {
|
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
$fee_totals = array( 25, 50.50, 34.56 );
|
|
|
|
|
|
|
|
foreach ( $fee_totals as $total ) {
|
|
|
|
$fee = new WC_Order_Item_Fee();
|
|
|
|
$fee->set_props(
|
|
|
|
array(
|
|
|
|
'name' => 'Some Fee',
|
|
|
|
'tax_status' => 'taxable',
|
|
|
|
'total' => $total,
|
|
|
|
'tax_class' => '',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$order->add_item( $fee );
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals( 110.06, $order->get_total_fees() );
|
|
|
|
}
|
2016-06-22 11:29:23 +00:00
|
|
|
}
|