/**
  * When handling the before collect totals event,
  * quote item quantities should be checked by checking
  * quote inventory via the quantity service model.
  */
 public function testHandleBeforeCollectTotals()
 {
     $quote = Mage::getModel('sales/quote');
     $this->_event->setQuote($quote);
     // Side-effect test: just need to make sure quote inventory
     // is checked via the quantity service model.
     $this->_quantityService->expects($this->once())->method('checkQuoteInventory')->with($this->identicalTo($quote))->will($this->returnSelf());
     $this->_inventoryObserver->handleBeforeCollectTotals($this->_eventObserver);
 }
 /**
  * Test voiding the redeemed gift cards.
  */
 public function testRedeemVoid()
 {
     // need to replace the checkout session to prevent errors when instantiating the gift card container
     $this->_replaceSession('checkout/session');
     $exceptionGiftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', ['void']);
     $exceptionGiftCard->setIsRedeemed(true)->setCardNumber('2222222222222222');
     // the void request may fail but processing should continue
     $exceptionGiftCard->expects($this->once())->method('void')->will($this->throwException(new EbayEnterprise_GiftCard_Exception(__METHOD__ . ': test exception')));
     $giftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', ['void']);
     $giftCard->setIsRedeemed(true)->setCardNumber('1111111111111111');
     // make sure the card redeem is voided
     $giftCard->expects($this->once())->method('void')->will($this->returnSelf());
     // The set of gift cards in the container that have been redeemed and
     // need to be voided.
     $redeemedGiftCards = new SplObjectStorage();
     $redeemedGiftCards->attach($giftCard);
     $redeemedGiftCards->attach($exceptionGiftCard);
     $container = $this->getModelMock('ebayenterprise_giftcard/container', ['getRedeemedGiftCards']);
     $container->method('getRedeemedGiftCards')->will($this->returnValue($redeemedGiftCards));
     $quote = Mage::getModel('sales/quote');
     $order = Mage::getModel('sales/order');
     $this->_event->setQuote($quote)->setOrder($order);
     $observer = Mage::getModel('ebayenterprise_giftcard/observer', ['gift_card_container' => $container]);
     // invoke the method, should void any redeemed card in the container
     $observer->redeemVoidGiftCards($this->_eventObserver);
 }
 /**
  * Test voiding the redeemed gift cards.
  */
 public function testRedeemVoid()
 {
     // need to replace the checkout session to prevent errors when instantiating the gift card container
     $this->_replaceSession('checkout/session');
     $container = Mage::getModel('ebayenterprise_giftcard/container');
     $exceptionGiftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('void'));
     $exceptionGiftCard->setIsRedeemed(true)->setCardNumber('2222222222222222');
     // the void request may fail but processing should continue
     $exceptionGiftCard->expects($this->once())->method('void')->will($this->throwException(new EbayEnterprise_GiftCard_Exception()));
     $container->updateGiftCard($exceptionGiftCard);
     $giftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('void'));
     $giftCard->setIsRedeemed(true)->setCardNumber('1111111111111111');
     // make sure the card redeem is voided
     $giftCard->expects($this->once())->method('void')->will($this->returnSelf());
     $container->updateGiftCard($giftCard);
     $unredeemedGiftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('void'));
     $unredeemedGiftCard->setIsRedeemed(false)->setCardNumber('2222222222222222');
     // cards that were not redeemed (getIsRedeemed === false) should not be voided
     $unredeemedGiftCard->expects($this->never())->method('void')->will($this->throwException(new EbayEnterprise_GiftCard_Exception()));
     $container->updateGiftCard($unredeemedGiftCard);
     $quote = Mage::getModel('sales/quote');
     $order = Mage::getModel('sales/order');
     $this->_event->setQuote($quote)->setOrder($order);
     $observer = Mage::getModel('ebayenterprise_giftcard/observer', array('gift_card_container' => $container));
     // invoke the method, should void any redeemed card in the container
     $observer->redeemVoidGiftCards($this->_eventObserver);
 }