41 $this->quoteRepositoryMock = $this->createMock(\
Magento\
Quote\Api\CartRepositoryInterface::class);
42 $this->storeMock = $this->createMock(\
Magento\
Store\Model\Store::class);
43 $this->quoteMock = $this->createPartialMock(\
Magento\
Quote\Model\Quote::class, [
53 $this->quoteAddressMock = $this->createPartialMock(\
Magento\
Quote\Model\
Quote\Address::class, [
54 'setCollectShippingRates',
58 $this->quoteRepositoryMock
70 $this->quoteRepositoryMock->expects($this->once())
86 $this->quoteRepositoryMock->expects($this->once())
87 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
88 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(0));
90 $this->couponManagement->set(
$cartId,
'coupon_code');
102 $this->storeMock->expects($this->any())->method(
'getId')->will($this->returnValue(1));
103 $this->quoteMock->expects($this->once())->method(
'getStoreId')->willReturn($this->returnValue(1));
105 $this->quoteRepositoryMock->expects($this->once())
106 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
107 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(12));
108 $this->quoteMock->expects($this->once())
109 ->method(
'getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
110 $this->quoteAddressMock->expects($this->once())->method(
'setCollectShippingRates')->with(
true);
111 $this->quoteMock->expects($this->once())->method(
'setCouponCode')->with(
$couponCode);
112 $exceptionMessage =
"The coupon code couldn't be applied. Verify the coupon code and try again.";
113 $exception = new \Magento\Framework\Exception\CouldNotDeleteException(
__($exceptionMessage));
114 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
115 $this->quoteRepositoryMock->expects($this->once())
117 ->with($this->quoteMock)
118 ->willThrowException($exception);
132 $this->storeMock->expects($this->any())->method(
'getId')->will($this->returnValue(1));
133 $this->quoteMock->expects($this->once())->method(
'getStoreId')->willReturn($this->returnValue(1));
135 $this->quoteRepositoryMock->expects($this->once())
136 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
137 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(12));
138 $this->quoteMock->expects($this->once())
139 ->method(
'getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
140 $this->quoteAddressMock->expects($this->once())->method(
'setCollectShippingRates')->with(
true);
141 $this->quoteMock->expects($this->once())->method(
'setCouponCode')->with(
$couponCode);
142 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
143 $this->quoteRepositoryMock->expects($this->once())->method(
'save')->with($this->quoteMock);
144 $this->quoteMock->expects($this->once())->method(
'getCouponCode')->will($this->returnValue(
'invalidCoupon'));
154 $this->storeMock->expects($this->any())->method(
'getId')->will($this->returnValue(1));
155 $this->quoteMock->expects($this->once())->method(
'getStoreId')->willReturn($this->returnValue(1));
157 $this->quoteRepositoryMock->expects($this->once())
158 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
159 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(12));
160 $this->quoteMock->expects($this->once())
161 ->method(
'getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
162 $this->quoteAddressMock->expects($this->once())->method(
'setCollectShippingRates')->with(
true);
163 $this->quoteMock->expects($this->once())->method(
'setCouponCode')->with(
$couponCode);
164 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
165 $this->quoteRepositoryMock->expects($this->once())->method(
'save')->with($this->quoteMock);
166 $this->quoteMock->expects($this->once())->method(
'getCouponCode')->will($this->returnValue(
$couponCode));
179 $this->quoteRepositoryMock->expects($this->once())
180 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
181 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(0));
182 $this->quoteMock->expects($this->never())->method(
'getShippingAddress');
184 $this->couponManagement->remove(
$cartId);
195 $this->quoteRepositoryMock->expects($this->once())
196 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
197 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(12));
198 $this->quoteMock->expects($this->once())
199 ->method(
'getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
200 $this->quoteAddressMock->expects($this->once())->method(
'setCollectShippingRates')->with(
true);
201 $this->quoteMock->expects($this->once())->method(
'setCouponCode')->with(
'');
202 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
203 $exceptionMessage =
"The coupon code couldn't be deleted. Verify the coupon code and try again.";
204 $exception = new \Magento\Framework\Exception\CouldNotSaveException(
__($exceptionMessage));
205 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
206 $this->quoteRepositoryMock->expects($this->once())
208 ->with($this->quoteMock)
209 ->willThrowException($exception);
211 $this->couponManagement->remove(
$cartId);
222 $this->quoteRepositoryMock->expects($this->once())
223 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
224 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(12));
225 $this->quoteMock->expects($this->once())
226 ->method(
'getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
227 $this->quoteAddressMock->expects($this->once())->method(
'setCollectShippingRates')->with(
true);
228 $this->quoteMock->expects($this->once())->method(
'setCouponCode')->with(
'');
229 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
230 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
231 $this->quoteRepositoryMock->expects($this->once())->method(
'save')->with($this->quoteMock);
232 $this->quoteMock->expects($this->once())->method(
'getCouponCode')->will($this->returnValue(
'123_ABC'));
234 $this->couponManagement->remove(
$cartId);
241 $this->quoteRepositoryMock->expects($this->once())
242 ->method(
'getActive')->with(
$cartId)->will($this->returnValue($this->quoteMock));
243 $this->quoteMock->expects($this->once())->method(
'getItemsCount')->will($this->returnValue(12));
244 $this->quoteMock->expects($this->once())
245 ->method(
'getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
246 $this->quoteAddressMock->expects($this->once())->method(
'setCollectShippingRates')->with(
true);
247 $this->quoteMock->expects($this->once())->method(
'setCouponCode')->with(
'');
248 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
249 $this->quoteMock->expects($this->once())->method(
'collectTotals')->will($this->returnValue($this->quoteMock));
250 $this->quoteRepositoryMock->expects($this->once())->method(
'save')->with($this->quoteMock);
251 $this->quoteMock->expects($this->once())->method(
'getCouponCode')->will($this->returnValue(
''));
253 $this->assertTrue($this->couponManagement->remove(
$cartId));
testSetWhenCartDoesNotContainsProducts()
testDeleteWhenCouponIsNotEmpty()
testSetWhenCouponCodeIsInvalid()
testDeleteWhenCouldNotDeleteCoupon()
testDeleteWhenCartDoesNotContainsProducts()
testSetWhenCouldNotApplyCoupon()