/** * Test that when a balance check fails, gift cards are not added to the cart/container. */ public function testAddGiftCardToOrderBalanceCheckFails() { // replace session used by the gift card container - prevents headers already sent error from session $session = $this->_replaceSession('checkout/session'); $cardNumber = '1111222233334444'; $card = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('checkBalance')); $card->setBalanceAmount(50.0)->setCardNumber($cardNumber); $card->expects($this->once())->method('checkBalance')->will($this->throwException(new EbayEnterprise_GiftCard_Exception())); // attempt to add the gift card to the order $this->giftCardHelper->addGiftCardToOrder($card); // gift card balance check failures should result in new error message $this->assertCount(1, $session->getMessages()->getErrors()); // card should not have been added to the container - get gift card with same number will return new gift card instance $this->assertNotSame($card, Mage::getModel('ebayenterprise_giftcard/container')->getGiftCard($cardNumber)); }
/** * Test that when a balance check fails, gift cards are not added to the cart/container. */ public function testAddGiftCardToOrderBalanceCheckFails() { // replace session used by the gift card container - prevents headers already sent error from session $this->_replaceSession('ebayenterprise_giftcard/session'); $cardNumber = '1111222233334444'; $pin = '1234'; $card = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('checkBalance')); $card->setBalanceAmount(50.0)->setCardNumber($cardNumber)->setPin($pin); $card->expects($this->once())->method('checkBalance')->will($this->throwException(new EbayEnterprise_GiftCard_Exception())); // Need custom exception testing: want to make sure that an expected // exception is thrown but also need to test some post conditions, // specifically that the gift cards wasn't added to the container. Catch // the exception thrown and validate that the expected exception was // thrown and caught in the test. $thrownException = null; try { // attempt to add the gift card to the order $this->giftCardHelper->addGiftCardToOrder($card, $this->giftCardContainer); } catch (EbayEnterprise_GiftCard_Exception $e) { $thrownException = $e; } $this->assertInstanceOf('EbayEnterprise_GiftCard_Exception', $thrownException); // card should not have been added to the container - get gift card with same number will return new gift card instance $this->assertNotSame($card->getPin(), $this->giftCardContainer->getGiftCard($cardNumber)->getPin()); }
/** * add a giftcard. * * @param string $cardNumber * @param string $pin * @return self */ protected function addGiftCard($cardNumber, $pin) { $giftcard = $this->container->getGiftCard($cardNumber)->setPin($pin); try { $this->helper->addGiftCardToOrder($giftcard, $this->container); $this->getSession()->addSuccess($this->helper->__(EbayEnterprise_GiftCard_Helper_Data::GIFT_CARD_ADD_SUCCESS, $cardNumber)); } catch (EbayEnterprise_GiftCard_Exception $e) { $this->getSession()->addError($this->helper->__($e->getMessage())); $this->logger->debug('Failed to add gift card to admin order. See exception log for more details.', $this->logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e)); } return $this; }