|
12 | 12 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
13 | 13 | use Magento\Quote\Api\CartRepositoryInterface;
|
14 | 14 | use Magento\Quote\Api\CartTotalRepositoryInterface;
|
| 15 | +use Magento\Quote\Model\Quote; |
15 | 16 | use Magento\Quote\Model\Quote\Address;
|
16 | 17 |
|
17 | 18 | class TotalsInformationManagementTest extends \PHPUnit\Framework\TestCase
|
@@ -67,7 +68,7 @@ public function testCalculate(?string $carrierCode, ?string $carrierMethod, int
|
67 | 68 | {
|
68 | 69 | $cartId = 1;
|
69 | 70 | $cartMock = $this->createMock(
|
70 |
| - \Magento\Quote\Model\Quote::class |
| 71 | + Quote::class |
71 | 72 | );
|
72 | 73 | $cartMock->expects($this->once())->method('getItemsCount')->willReturn(1);
|
73 | 74 | $cartMock->expects($this->once())->method('getIsVirtual')->willReturn(false);
|
@@ -101,6 +102,72 @@ public function testCalculate(?string $carrierCode, ?string $carrierMethod, int
|
101 | 102 | $this->totalsInformationManagement->calculate($cartId, $addressInformationMock);
|
102 | 103 | }
|
103 | 104 |
|
| 105 | + /** |
| 106 | + * Test case when shipping amount must be reset to 0 because of changed shipping method. |
| 107 | + */ |
| 108 | + public function testResetShippingAmount() |
| 109 | + { |
| 110 | + $cartId = 1; |
| 111 | + $carrierCode = 'carrier_code'; |
| 112 | + $carrierMethod = 'carrier_method'; |
| 113 | + |
| 114 | + $cartMock = $this->createMock(Quote::class); |
| 115 | + $cartMock->method('getItemsCount') |
| 116 | + ->willReturn(1); |
| 117 | + $cartMock->method('getIsVirtual') |
| 118 | + ->willReturn(false); |
| 119 | + $this->cartRepositoryMock->method('get')->with($cartId)->willReturn($cartMock); |
| 120 | + $this->cartTotalRepositoryMock->method('get')->with($cartId); |
| 121 | + |
| 122 | + $addressInformationMock = $this->createMock(TotalsInformationInterface::class); |
| 123 | + $addressMock = $this->getMockBuilder(Address::class) |
| 124 | + ->addMethods( |
| 125 | + [ |
| 126 | + 'setShippingMethod', |
| 127 | + 'setCollectShippingRates' |
| 128 | + ] |
| 129 | + )->onlyMethods( |
| 130 | + [ |
| 131 | + 'getShippingMethod', |
| 132 | + 'setShippingAmount', |
| 133 | + 'setBaseShippingAmount', |
| 134 | + ] |
| 135 | + ) |
| 136 | + ->disableOriginalConstructor() |
| 137 | + ->getMock(); |
| 138 | + $addressMock->method('getShippingMethod') |
| 139 | + ->willReturn('flatrate_flatrate'); |
| 140 | + $addressInformationMock->method('getAddress') |
| 141 | + ->willReturn($addressMock); |
| 142 | + $addressInformationMock->method('getShippingCarrierCode') |
| 143 | + ->willReturn($carrierCode); |
| 144 | + $addressInformationMock->method('getShippingMethodCode') |
| 145 | + ->willReturn($carrierMethod); |
| 146 | + $cartMock->method('setShippingAddress') |
| 147 | + ->with($addressMock); |
| 148 | + $cartMock->method('getShippingAddress') |
| 149 | + ->willReturn($addressMock); |
| 150 | + $addressMock->expects($this->once()) |
| 151 | + ->method('setCollectShippingRates') |
| 152 | + ->with(true) |
| 153 | + ->willReturn($addressMock); |
| 154 | + $addressMock->expects($this->once()) |
| 155 | + ->method('setShippingAmount') |
| 156 | + ->with(0) |
| 157 | + ->willReturn($addressMock); |
| 158 | + $addressMock->expects($this->once()) |
| 159 | + ->method('setBaseShippingAmount') |
| 160 | + ->with(0) |
| 161 | + ->willReturn($addressMock); |
| 162 | + $addressMock->expects($this->once()) |
| 163 | + ->method('setShippingMethod') |
| 164 | + ->with($carrierCode . '_' . $carrierMethod); |
| 165 | + $cartMock->expects($this->once()) |
| 166 | + ->method('collectTotals'); |
| 167 | + |
| 168 | + $this->totalsInformationManagement->calculate($cartId, $addressInformationMock); |
| 169 | + } |
| 170 | + |
104 | 171 | /**
|
105 | 172 | * Data provider for testCalculate.
|
106 | 173 | *
|
|
0 commit comments