Exemplo 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));
 }
Exemplo n.º 2
0
 public function testSet()
 {
     $cartId = 33;
     $couponCode = '153a-ABC';
     $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->couponCodeDataMock->expects($this->once())->method('getCouponCode')->will($this->returnValue($couponCode));
     $this->quoteMock->expects($this->once())->method('setCouponCode')->with($couponCode);
     $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($couponCode));
     $this->assertTrue($this->service->set($cartId, $this->couponCodeDataMock));
 }