/** * Test getting tokens associated with an order. * @since 2.6.0 */ function test_wc_payment_tokens_get_order_tokens() { $order = WC_Helper_Order::create_order(); $this->assertEmpty(WC_Payment_Tokens::get_order_tokens($order->id)); $token = WC_Helper_Payment_Token::create_cc_token(); update_post_meta($order->id, '_payment_tokens', array($token->get_id())); $this->assertCount(1, WC_Payment_Tokens::get_order_tokens($order->id)); }
/** * Test: get_total_tax_refunded_by_rate_id */ function test_get_remaining_refund_items() { $object = WC_Helper_Order::create_order(); $this->assertEquals(4, $object->get_remaining_refund_items()); }
/** * Test getting a customer's total amount spent from DB. * @since 2.7.0 */ public function test_customer_get_total_spent_read() { $customer = WC_Helper_Customer::create_customer(); $customer_id = $customer->get_id(); $order = WC_Helper_Order::create_order($customer_id); $customer->read($customer_id); $this->assertEquals(0, $customer->get_total_spent()); $order->update_status('wc-completed'); $customer->read($customer_id); $this->assertEquals(40, $customer->get_total_spent()); $order->delete(); }
/** * Test adding a payment token to an order * * @since 2.6 */ public function test_wc_order_add_payment_token() { $order = WC_Helper_Order::create_order(); $this->assertEmpty($order->get_payment_tokens()); $token = WC_Helper_Payment_Token::create_cc_token(); $order->add_payment_token($token); $this->assertCount(1, $order->get_payment_tokens()); }
/** * Test the order schema. * @since 2.7.0 */ public function test_order_schema() { wp_set_current_user($this->user); $order = WC_Helper_Order::create_order(); $request = new WP_REST_Request('OPTIONS', '/wc/v1/orders/' . $order->get_id()); $response = $this->server->dispatch($request); $data = $response->get_data(); $properties = $data['schema']['properties']; $this->assertEquals(38, count($properties)); $this->assertArrayHasKey('id', $properties); wp_delete_post($order->get_id(), true); }
/** * Test wc_get_order() * * @since 2.4.0 * @group test */ public function test_wc_get_order() { $order = \WC_Helper_Order::create_order(); // Assert that $order is a WC_Order object $this->assertInstanceOf('WC_Order', $order); // Assert that wc_get_order() accepts a WC_Order object $this->assertInstanceOf('WC_Order', wc_get_order($order)); // Assert that wc_get_order() accepts a order post id. $this->assertInstanceOf('WC_Order', wc_get_order($order->id)); // Assert that a non-shop_order post returns false $post = $this->factory->post->create_and_get(array('post_type' => 'post')); $this->assertFalse(wc_get_order($post->ID)); // Assert the return when $the_order args is false $this->assertFalse(wc_get_order(false)); // Assert the return when $the_order args is a random (incorrect) id. $this->assertFalse(wc_get_order(123456)); }