/** * Test creating a draft order and upgrading it */ public function test_draft_order_creation() { $order = appthemes_new_order(); $this->assertNotEmpty($order); $draft_order = new APP_Draft_Order(); $draft_order->set_description('Draft'); $draft_order->set_gateway('paypal'); $draft_order->set_currency('EUR'); $draft_order->add_item('test', 5, $order->get_id()); $this->assertEquals('Draft', $draft_order->get_description()); $this->assertEquals('paypal', $draft_order->get_gateway()); $this->assertEquals('EUR', $draft_order->get_currency()); $this->assertEquals(5, $draft_order->get_total()); $this->assertCount(1, $draft_order->get_items()); $new_order = appthemes_new_order($draft_order); $this->assertEquals('Draft', $new_order->get_description()); $this->assertEquals('paypal', $new_order->get_gateway()); $this->assertEquals('EUR', $new_order->get_currency()); $this->assertEquals(5, $new_order->get_total()); $this->assertCount(1, $new_order->get_items()); }
/** * Checks that the total returns properly */ function test_get_total_basic() { $order = new APP_Draft_Order(); // By default, order's totals should be 0 $this->assertEquals(0, $order->get_total()); // Total should reflect added items prices $order->add_item('payment-test', 5, $order->get_id()); $this->assertCount(1, $order->get_items()); $this->assertEquals(5, $order->get_total()); // Adding another item should increase the price $order->add_item('payment-test', 5, $order->get_id()); $this->assertCount(2, $order->get_items()); $this->assertEquals(10, $order->get_total()); // Adding another item type should increase the price $order->add_item('payment-test1', 5, $order->get_id()); $this->assertCount(3, $order->get_items()); $this->assertEquals(15, $order->get_total()); // Adding a float value as a price should correctly calculate the total with cents $order->add_item('payment-test1', 5.99, $order->get_id()); $this->assertCount(4, $order->get_items()); $this->assertEquals(20.99, $order->get_total()); }