/**
  * When adding gift pricing to an item, amount should be wrap price * qty
  * (handled by the helper method) and unit price should be just the gift
  * wrapping price.
  */
 public function testAddGiftPricingItem()
 {
     $wrapPrice = 10.0;
     $qty = 2;
     $giftPrice = $qty * $wrapPrice;
     // Assume this method will return the proper amount for for the total
     // amount for gift pricing.
     $this->_helperMock->expects($this->any())->method('calculateGwItemRowTotal')->with($this->identicalTo($this->_item))->will($this->returnValue($giftPrice));
     $this->_item->addData(array('gw_price' => $wrapPrice, 'qty' => $qty));
     $payload = $this->_orderCreateRequest->getShipGroups()->getEmptyShipGroup();
     $gifting = Mage::getModel('eb2cgiftwrap/order_create_gifting', array('helper' => $this->_helperMock));
     $gifting->injectGifting($this->_item, $payload);
     $this->assertSame($giftPrice, $payload->getGiftPricing()->getAmount());
     $this->assertSame($wrapPrice, $payload->getGiftPricing()->getUnitPrice());
 }
 /**
  * For each item given, a new order item payload should be created,
  * dispatched in an event with the Magento order item, and added to an
  * item reference payload in the order item reference container.
  */
 public function testAddOrderItemReferences()
 {
     // stub the event observer so the orderitem handler doesn't interfere with the test
     $this->replaceByMock('model', 'ebayenterprise_order/observer', $this->_observerStub);
     $itemRefContainer = $this->_request->getShipGroups()->getEmptyShipGroup();
     $items = [Mage::getModel('sales/order_item'), Mage::getModel('sales/order_item')];
     $orderItems = $this->_request->getOrderItems();
     $constructorArgs = ['api' => $this->_httpApi, 'config' => $this->_config, 'order' => $this->_order, 'payload' => $this->_requestStub];
     $handler = $this->getModelMockBuilder('ebayenterprise_order/create_orderitem')->disableOriginalConstructor()->getMock();
     $create = Mage::getModel('ebayenterprise_order/create', $constructorArgs);
     EcomDev_Utils_Reflection::setRestrictedPropertyValue($create, '_defaultItemHandler', $handler);
     $references = EcomDev_Utils_Reflection::invokeRestrictedMethod($create, '_addOrderItemReferences', [$itemRefContainer, $items, $orderItems, $this->_shipAddress, $this->_order]);
     // Should be one item reference and one event dispatched for each item.
     $expectedCount = count($items);
     $this->assertCount($expectedCount, $references->getItemReferences());
     $this->assertEventDispatchedExactly('ebayenterprise_order_create_item', $expectedCount);
 }