protected function createRecurringOrder() { $order = new Order(); $customer = new Partner(); $order->setOwner($customer); $product1 = new Product(); $product1->setName('product1'); $context = new PricingContext(); $recurringElement = new RecurringElement(); $recurringElement->setCycles(-1); $recurringElement->setInterval('1 month'); $recurringElement->setRecurringCharge('30'); $pricingSet = new PricingSet(new TotalValueElement()); $pricingSet->addPricingElement($recurringElement); $pricingSet->setProcessingState(PricingSet::PROCESSING_FINISHED); $pricingSet1 = $pricingSet->process($context); $orderItem1 = new Item($product1); $rp = new \ReflectionProperty($orderItem1, 'pricingSet'); $rp->setAccessible(true); $rp->setValue($orderItem1, $pricingSet1); $rp->setAccessible(false); $rm = new \ReflectionMethod($order, 'addItem'); $rm->setAccessible(true); $rm->invokeArgs($order, array($orderItem1)); $rm->setAccessible(false); return $order; }
public function testIsValidOpenOrder() { $mgr = $this->createOrderManager(); $order = null; $this->assertFalse($mgr->isValidOpenOrder($order), 'a null for an order should return false'); $order = new Order(); $customer = new Partner(); $customer->setName('Valid Customer'); $order->setCustomer($customer); $wrongCustomer = new Partner(); $wrongCustomer->setName('Wrong Customer'); $this->assertFalse($mgr->isValidOpenOrder($order, $wrongCustomer), 'a passed customer must not matching the customer in the order should return false'); $order->setState(OrderState::LOCKED); $this->assertFalse($mgr->isValidOpenOrder($order), 'an order not in an open state should return false'); $order->setState(OrderState::OPEN); $this->assertTrue($mgr->isValidOpenOrder($order), 'an order meeting all of the conditions should return true'); $this->assertTrue($mgr->isValidOpenOrder($order, $customer), 'an order with customer meeting all of the conditions should return true'); }
public function testTotalPrice() { $order = new Order(); $this->assertSame(0, $order->getPrice(), 'the total price should start out as 0'); $this->assertSame(0, $order->getPrice('total'), 'the total price should start out as 0'); $this->assertSame(0, $order->getTotalPrice(), 'the total price should start out as 0'); $order->setPrice(35); $this->assertSame(35, $order->getTotalPrice('total'), 'the total should be set'); $this->assertSame(35, $order->getTotalPrice(), 'the total should be set if no price type is passed'); $this->assertSame(35, $order->getPrice(), 'if no type is set, the total should be returned'); $order->setTotalPrice(70); $this->assertSame(70, $order->getTotalPrice('total'), 'the total should be set'); $this->assertSame(70, $order->getTotalPrice(), 'it should match using get TotalPrice'); $this->assertSame(70, $order->getPrice(), 'if no type is set, the total should be returned'); $order->setPrice(105, 'something special'); $this->assertSame(70, $order->getTotalPrice(), 'the Total price should not have been changed'); $this->assertSame(70, $order->getPrice('total'), 'the Total price should not have been change'); $this->assertSame(70, $order->getPrice(), 'the Total price should not have been change'); }