|
14 | 14 | use Magento\Framework\HTTP\AsyncClient\Response;
|
15 | 15 | use Magento\Framework\HTTP\AsyncClientInterface;
|
16 | 16 | use Magento\Quote\Model\Quote\Address\RateRequest;
|
| 17 | +use Magento\Quote\Model\Quote\Address\RateRequestFactory; |
17 | 18 | use Magento\Quote\Model\Quote\Address\RateResult\Error;
|
| 19 | +use Magento\Shipping\Model\Shipment\Request; |
18 | 20 | use Magento\TestFramework\Helper\Bootstrap;
|
19 |
| -use Magento\Quote\Model\Quote\Address\RateRequestFactory; |
20 | 21 | use Magento\TestFramework\HTTP\AsyncClientInterfaceMock;
|
21 |
| -use PHPUnit\Framework\TestCase; |
22 | 22 | use PHPUnit\Framework\MockObject\MockObject;
|
23 |
| -use Magento\Shipping\Model\Shipment\Request; |
| 23 | +use PHPUnit\Framework\TestCase; |
24 | 24 | use Psr\Log\LoggerInterface;
|
25 | 25 |
|
26 | 26 | /**
|
@@ -113,29 +113,54 @@ public function testGetShipConfirmUrlLive()
|
113 | 113 | }
|
114 | 114 |
|
115 | 115 | /**
|
116 |
| - * Collect free rates. |
| 116 | + * Collect rates for UPS Ground method. |
117 | 117 | *
|
118 | 118 | * @magentoConfigFixture current_store carriers/ups/active 1
|
119 |
| - * @magentoConfigFixture current_store carriers/ups/type UPS |
120 |
| - * @magentoConfigFixture current_store carriers/ups/allowed_methods 1DA,GND |
121 |
| - * @magentoConfigFixture current_store carriers/ups/free_method GND |
| 119 | + * @magentoConfigFixture current_store carriers/ups/type UPS_XML |
| 120 | + * @magentoConfigFixture current_store carriers/ups/allowed_methods 03 |
| 121 | + * @magentoConfigFixture current_store carriers/ups/free_method 03 |
| 122 | + * @magentoConfigFixture default_store carriers/ups/shipper_number 12345 |
| 123 | + * @magentoConfigFixture default_store carriers/ups/origin_shipment Shipments Originating in the United States |
| 124 | + * @magentoConfigFixture default_store carriers/ups/username user |
| 125 | + * @magentoConfigFixture default_store carriers/ups/password pass |
| 126 | + * @magentoConfigFixture default_store carriers/ups/access_license_number acn |
| 127 | + * @magentoConfigFixture default_store carriers/ups/debug 1 |
| 128 | + * @magentoConfigFixture default_store currency/options/allow USD,EUR |
| 129 | + * @magentoConfigFixture default_store currency/options/base USD |
122 | 130 | */
|
123 | 131 | public function testCollectFreeRates()
|
124 | 132 | {
|
125 |
| - $rateRequest = Bootstrap::getObjectManager()->get(RateRequestFactory::class)->create(); |
126 |
| - $rateRequest->setDestCountryId('US'); |
127 |
| - $rateRequest->setDestRegionId('CA'); |
128 |
| - $rateRequest->setDestPostcode('90001'); |
129 |
| - $rateRequest->setPackageQty(1); |
130 |
| - $rateRequest->setPackageWeight(1); |
131 |
| - $rateRequest->setFreeMethodWeight(0); |
132 |
| - $rateRequest->setLimitCarrier($this->carrier::CODE); |
133 |
| - $rateRequest->setFreeShipping(true); |
134 |
| - $rateResult = $this->carrier->collectRates($rateRequest); |
135 |
| - $result = $rateResult->asArray(); |
136 |
| - $methods = $result[$this->carrier::CODE]['methods']; |
137 |
| - $this->assertEquals(0, $methods['GND']['price']); |
138 |
| - $this->assertNotEquals(0, $methods['1DA']['price']); |
| 133 | + $request = Bootstrap::getObjectManager()->create( |
| 134 | + RateRequest::class, |
| 135 | + [ |
| 136 | + 'data' => [ |
| 137 | + 'dest_country' => 'US', |
| 138 | + 'dest_postal' => '90001', |
| 139 | + 'package_weight' => '1', |
| 140 | + 'package_qty' => '1', |
| 141 | + 'free_method_weight' => '5', |
| 142 | + 'product' => '11', |
| 143 | + 'action' => 'Rate', |
| 144 | + 'unit_measure' => 'KGS', |
| 145 | + 'free_shipping' => '1', |
| 146 | + 'base_currency' => new DataObject(['code' => 'USD']) |
| 147 | + ] |
| 148 | + ] |
| 149 | + ); |
| 150 | + //phpcs:disable Magento2.Functions.DiscouragedFunction |
| 151 | + $this->httpClient->nextResponses( |
| 152 | + [ |
| 153 | + new Response( |
| 154 | + 200, |
| 155 | + [], |
| 156 | + file_get_contents(__DIR__ . "/../_files/ups_rates_response_option9.xml") |
| 157 | + ) |
| 158 | + ] |
| 159 | + ); |
| 160 | + |
| 161 | + $rates = $this->carrier->collectRates($request)->getAllRates(); |
| 162 | + $this->assertEquals('19.19', $rates[0]->getPrice()); |
| 163 | + $this->assertEquals('03', $rates[0]->getMethod()); |
139 | 164 | }
|
140 | 165 |
|
141 | 166 | /**
|
@@ -181,7 +206,7 @@ public function testCollectRates(int $negotiable, int $tax, int $responseId, str
|
181 | 206 | new Response(
|
182 | 207 | 200,
|
183 | 208 | [],
|
184 |
| - file_get_contents(__DIR__ ."/../_files/ups_rates_response_option$responseId.xml") |
| 209 | + file_get_contents(__DIR__ . "/../_files/ups_rates_response_option$responseId.xml") |
185 | 210 | )
|
186 | 211 | ]
|
187 | 212 | );
|
@@ -283,9 +308,9 @@ public function collectRatesDataProvider()
|
283 | 308 | public function testRequestToShipment(): void
|
284 | 309 | {
|
285 | 310 | //phpcs:disable Magento2.Functions.DiscouragedFunction
|
286 |
| - $expectedShipmentRequest = file_get_contents(__DIR__ .'/../_files/ShipmentConfirmRequest.xml'); |
287 |
| - $shipmentResponse = file_get_contents(__DIR__ .'/../_files/ShipmentConfirmResponse.xml'); |
288 |
| - $acceptResponse = file_get_contents(__DIR__ .'/../_files/ShipmentAcceptResponse.xml'); |
| 311 | + $expectedShipmentRequest = file_get_contents(__DIR__ . '/../_files/ShipmentConfirmRequest.xml'); |
| 312 | + $shipmentResponse = file_get_contents(__DIR__ . '/../_files/ShipmentConfirmResponse.xml'); |
| 313 | + $acceptResponse = file_get_contents(__DIR__ . '/../_files/ShipmentAcceptResponse.xml'); |
289 | 314 | //phpcs:enable Magento2.Functions.DiscouragedFunction
|
290 | 315 | $this->httpClient->nextResponses(
|
291 | 316 | [
|
|
0 commit comments