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 testFindProductInOrder() { $mgr = $this->createOrderManager(); $order = $mgr->createOrder('test'); $createItem = new \ReflectionMethod($mgr, 'createItem'); $createItem->setAccessible(true); $addItem = new \ReflectionMethod($order, 'addItem'); $addItem->setAccessible(true); $product = new Product(); $product->setName('test product'); $testItem = $createItem->invokeArgs($mgr, array($product)); $addItem->invokeArgs($order, array($testItem)); $item = $mgr->findProductInOrder($order, $product); $this->assertSame($product, $item->getProduct(), 'find the item that contains the product'); $newProduct = new Product(); $newProduct->setName('with options'); $optionsBlue = array('color' => 'blue', 'size' => 'small'); $blueItem = $createItem->invokeArgs($mgr, array($newProduct, $optionsBlue)); $addItem->invokeArgs($order, array($blueItem)); $foundBlueItem = $mgr->findProductInOrder($order, $newProduct, $optionsBlue); $this->assertSame($newProduct, $foundBlueItem->getProduct(), 'find the item that contains the product with the options'); $this->assertSame($optionsBlue, $foundBlueItem->getOptions(), 'find the item that contains the product with the options'); $optionsRed = array('color' => 'red', 'size' => 'large'); $redItem = $createItem->invokeArgs($mgr, array($newProduct, $optionsRed)); $addItem->invokeArgs($order, array($redItem)); $foundRedItem = $mgr->findProductInOrder($order, $newProduct, array('size' => 'large', 'color' => 'red')); $this->assertNotSame($redItem, $blueItem); $this->assertSame($newProduct, $foundRedItem->getProduct(), 'find the item that contains the product with the options'); $this->assertSame($optionsRed, $foundRedItem->getOptions(), 'find the item that contains the product with the options'); $this->markTestIncomplete('this needed to be revisited'); $this->assertNull($mgr->findProductInOrder($order, $product, $optionsRed), "product and options don't match, nothing returned"); $this->assertNull($mgr->findProductInOrder($order, $newProduct), 'this item has options, so nothing returned'); $this->assertNull($mgr->findProductInOrder($order, $newProduct, array('color' => 'yellow')), 'no yellow options set'); }