Esempio n. 1
0
 public function testSetNotVirtualQuotePaymentSuccess()
 {
     $cartId = 11;
     $storeId = 12;
     $paymentId = 13;
     $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
     $paymentsCollectionMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], [], '', false);
     $quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', ['setTotalsCollectedFlag', '__wakeup', 'getPaymentsCollection', 'getPayment', 'getItemsCollection', 'isVirtual', 'getShippingAddress', 'collectTotals'], [], '', false);
     $quoteMock->expects($this->any())->method('getPaymentsCollection')->will($this->returnValue($paymentsCollectionMock));
     $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue(false));
     $shippingAddressMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', ['getCountryId', '__wakeup'], [], '', false);
     $shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(1));
     $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock));
     $quoteMock->expects($this->once())->method('setTotalsCollectedFlag')->will($this->returnSelf());
     $quoteMock->expects($this->once())->method('collectTotals')->will($this->returnSelf());
     $paymentMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Payment', [], [], '', false);
     $paymentMock->expects($this->once())->method('getId')->will($this->returnValue($paymentId));
     $methodMock = $this->getMockForAbstractClass('\\Magento\\Payment\\Model\\Method\\AbstractMethod', [], '', false, false);
     $paymentMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodMock));
     $this->validatorMock->expects($this->once())->method('isApplicable')->with($methodMock, $quoteMock)->will($this->returnValue(true));
     $quoteMock->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
     $this->quoteLoaderMock->expects($this->once())->method('load')->with($cartId, $storeId)->will($this->returnValue($quoteMock));
     $paymentMethodMock = $this->getMock('\\Magento\\Checkout\\Service\\V1\\Data\\Cart\\PaymentMethod', [], [], '', false);
     $this->paymentMethodBuilderMock->expects($this->once())->method('build')->with($paymentMethodMock, $quoteMock)->will($this->returnValue($paymentMock));
     $this->assertEquals($paymentId, $this->service->set($paymentMethodMock, $cartId));
 }
Esempio n. 2
0
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage There is no downloadable link with provided ID.
  */
 public function testDeleteThrowsExceptionIfLinkIdIsNotValid()
 {
     $linkId = 1;
     $linkMock = $this->getMock('\\Magento\\Downloadable\\Model\\Link', array(), array(), '', false);
     $this->linkFactoryMock->expects($this->once())->method('create')->will($this->returnValue($linkMock));
     $linkMock->expects($this->once())->method('load')->with($linkId)->will($this->returnSelf());
     $linkMock->expects($this->once())->method('getId');
     $linkMock->expects($this->never())->method('delete');
     $this->service->delete($linkId);
 }
Esempio n. 3
0
 public function testRemoveItem()
 {
     $cartId = 11;
     $itemId = 5;
     $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock));
     $this->quoteMock->expects($this->once())->method('removeItem');
     $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('save')->will($this->returnValue($this->quoteMock));
     $this->assertTrue($this->service->removeItem($cartId, $itemId, $this->dataMock));
 }
Esempio n. 4
0
 public function testDelete()
 {
     $cartId = 65;
     $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
     $this->quoteAddressMock->expects($this->once())->method('setCollectShippingRates')->with(true);
     $this->quoteMock->expects($this->once())->method('setCouponCode')->with('');
     $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('save');
     $this->quoteMock->expects($this->once())->method('getCouponCode')->will($this->returnValue(''));
     $this->assertTrue($this->service->delete($cartId));
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testRemoveChildInvalidChildSku()
 {
     $this->productRepositoryMock->expects($this->any())->method('get')->will($this->returnValue($this->product));
     $productSku = 'productSku';
     $optionId = 1;
     $childSku = 'childSku';
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $this->getOptions();
     $selection = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Selection')->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku . '_invalid'));
     $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId));
     $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55));
     $selection->expects($this->any())->method('getProductId')->will($this->returnValue(1));
     $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection]));
     $this->service->removeChild($productSku, $optionId, $childSku);
 }
Esempio n. 6
0
 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage Unable to save address. Please, check input data.
  */
 public function testSetAddressWithInabilityToSaveQuote()
 {
     $quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', [], [], '', false);
     $this->quoteRepositoryMock->expects($this->once())->method('get')->with('cart867')->will($this->returnValue($quoteMock));
     $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false));
     $builder = $this->getMock('\\Magento\\Checkout\\Service\\V1\\Data\\Cart\\Address\\RegionBuilder', ['create'], [], '', false);
     /** @var \Magento\Checkout\Service\V1\Data\Cart\AddressBuilder $addressDataBuilder */
     $addressDataBuilder = $this->objectManager->getObject('Magento\\Checkout\\Service\\V1\\Data\\Cart\\AddressBuilder', ['regionBuilder' => $builder]);
     /** @var \Magento\Checkout\Service\V1\Data\Cart\Address $addressData */
     $addressData = $addressDataBuilder->setId(356)->create();
     $this->validatorMock->expects($this->once())->method('validate')->with($addressData)->will($this->returnValue(true));
     $this->converterMock->expects($this->once())->method('convertDataObjectToModel')->with($addressData, $this->quoteAddressMock)->will($this->returnValue($this->quoteAddressMock));
     $quoteMock->expects($this->once())->method('setShippingAddress')->with($this->quoteAddressMock);
     $quoteMock->expects($this->once())->method('setDataChanges')->with(true);
     $quoteMock->expects($this->once())->method('save')->willThrowException(new \Exception('Some DB Error'));
     $this->service->setAddress('cart867', $addressData);
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable
  */
 public function testSetAddressForVirtualProduct()
 {
     $storeId = 323;
     $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
     $quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', [], [], '', false);
     $this->quoteLoaderMock->expects($this->once())->method('load')->with('cart867', $storeId)->will($this->returnValue($quoteMock));
     $quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(true));
     /** @var \Magento\Checkout\Service\V1\Data\Cart\AddressBuilder $addressDataBuilder */
     $addressDataBuilder = $this->objectManager->getObject('Magento\\Checkout\\Service\\V1\\Data\\Cart\\AddressBuilder');
     /** @var \Magento\Checkout\Service\V1\Data\Cart\Address $addressData */
     $addressData = $addressDataBuilder->setId(356)->create();
     $this->validatorMock->expects($this->never())->method('validate');
     $quoteMock->expects($this->never())->method('setShippingAddress');
     $quoteMock->expects($this->never())->method('save');
     $this->service->setAddress('cart867', $addressData);
 }
 /**
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  * @expectedExceptionMessage Could not add gift message to shopping cart
  */
 public function testSetMessageCouldNotAddGiftMessageException()
 {
     $cartId = 665;
     $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1));
     $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false));
     $this->quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($this->billingAddressMock));
     $this->billingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(12));
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock));
     $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(13));
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock));
     $this->helperMock->expects($this->once())->method('getIsMessagesAvailable')->with('', $this->quoteMock, $this->storeMock)->will($this->returnValue(true));
     $this->giftMessageMock->expects($this->once())->method('getSender')->will($this->returnValue('sender'));
     $this->giftMessageMock->expects($this->once())->method('getRecipient')->will($this->returnValue('recipient'));
     $this->giftMessageMock->expects($this->once())->method('getMessage')->will($this->returnValue('Message'));
     $message['quote'][null] = ['from' => 'sender', 'to' => 'recipient', 'message' => 'Message'];
     $exception = new \Magento\Framework\Exception\CouldNotSaveException('Could not add gift message to shopping cart');
     $this->giftMessageManagerMock->expects($this->once())->method('add')->with($message, $this->quoteMock)->will($this->throwException($exception));
     $this->service->setForQuote($cartId, $this->giftMessageMock);
 }
Esempio n. 9
0
 public function testSetMethod()
 {
     $cartId = 12;
     $carrierCode = 34;
     $methodCode = 56;
     $countryId = 1;
     $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1));
     $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false));
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock));
     $billingAddressMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', ['getCountryId', '__wakeup'], [], '', false);
     $this->quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($billingAddressMock));
     $billingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(23));
     $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue($countryId));
     $this->shippingAddressMock->expects($this->once())->method('setShippingMethod')->with($carrierCode . '_' . $methodCode);
     $this->shippingAddressMock->expects($this->once())->method('requestShippingRates')->will($this->returnValue(true));
     $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnSelf());
     $this->quoteMock->expects($this->once())->method('save');
     $this->assertTrue($this->service->setMethod($cartId, $carrierCode, $methodCode));
 }
Esempio n. 10
0
 public function testSetAddress()
 {
     $storeId = 323;
     $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
     $quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', [], [], '', false);
     $this->quoteLoaderMock->expects($this->once())->method('load')->with('cartId', $storeId)->will($this->returnValue($quoteMock));
     /** @var \Magento\Checkout\Service\V1\Data\Cart\AddressBuilder $addressDataBuilder */
     $addressDataBuilder = $this->objectManager->getObject('Magento\\Checkout\\Service\\V1\\Data\\Cart\\AddressBuilder');
     /** @var \Magento\Checkout\Service\V1\Data\Cart\Address $addressData */
     $addressData = $addressDataBuilder->setId(454)->create();
     $this->validatorMock->expects($this->once())->method('validate')->with($addressData)->will($this->returnValue(true));
     $this->converterMock->expects($this->once())->method('convertDataObjectToModel')->with($addressData, $this->quoteAddressMock)->will($this->returnValue($this->quoteAddressMock));
     $quoteMock->expects($this->once())->method('setBillingAddress')->with($this->quoteAddressMock);
     $quoteMock->expects($this->once())->method('setDataChanges')->with(true);
     $quoteMock->expects($this->once())->method('save');
     $addressId = 1;
     $billingAddressMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', [], [], '', false);
     $billingAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId));
     $quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($billingAddressMock));
     $this->assertEquals($addressId, $this->service->setAddress('cartId', $addressData));
 }