Skip to content

Commit 1fb7e45

Browse files
ACQE-8552: [AC-5466] Use DHL (US) Online Shipping Carrier on Checkout as a Registered Customer
- Updated test name. - Added assertion for dhl availability. - Rearranged use statements.
1 parent 72adaad commit 1fb7e45

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

dev/tests/integration/testsuite/Magento/Dhl/PlaceOrderWithDhlUsCarrierTest.php

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@
88

99
namespace Magento\Dhl;
1010

11+
use Magento\Bundle\Model\Product\Price;
12+
use Magento\Bundle\Test\Fixture\AddProductToCart as AddBundleProductToCart;
13+
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
14+
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
15+
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
1116
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
17+
use Magento\ConfigurableProduct\Test\Fixture\AddProductToCart as AddConfigurableProductToCartFixture;
1218
use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture;
1319
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
1420
use Magento\Customer\Test\Fixture\Customer as CustomerFixture;
21+
use Magento\Framework\Exception\LocalizedException;
22+
use Magento\Framework\ObjectManagerInterface;
23+
use Magento\Quote\Api\CartManagementInterface;
24+
use Magento\Quote\Api\CartRepositoryInterface;
25+
use Magento\Quote\Api\Data\AddressInterface;
1526
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
1627
use Magento\Quote\Test\Fixture\CustomerCart as CustomerCartFixture;
28+
use Magento\Sales\Api\OrderRepositoryInterface;
1729
use Magento\TestFramework\Fixture\Config;
1830
use Magento\TestFramework\Fixture\DataFixture;
19-
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2031
use Magento\TestFramework\Fixture\DataFixtureStorage;
32+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2133
use Magento\TestFramework\Helper\Bootstrap;
2234
use PHPUnit\Framework\TestCase;
23-
use Magento\Quote\Api\CartRepositoryInterface;
24-
use Magento\Quote\Api\CartManagementInterface;
25-
use Magento\Quote\Api\Data\AddressInterface;
26-
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
27-
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
28-
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
29-
use Magento\ConfigurableProduct\Test\Fixture\AddProductToCart as AddConfigurableProductToCartFixture;
30-
use Magento\Bundle\Test\Fixture\AddProductToCart as AddBundleProductToCart;
31-
use Magento\Bundle\Model\Product\Price;
32-
use Magento\Sales\Api\OrderRepositoryInterface;
33-
use Magento\Framework\ObjectManagerInterface;
34-
use Magento\Framework\Exception\LocalizedException;
3535

3636
/**
3737
* Integration test to verify order placement using dhl international shipping carrier
@@ -159,13 +159,13 @@ protected function setUp(): void
159159
*
160160
* @return void
161161
*/
162-
public function testPlaceOrderWithDhlUsCarrierTest(): void
162+
public function testPlaceOrderWithDhlUsCarrier(): void
163163
{
164164
$cartId = (int)$this->fixtures->get('cart')->getId();
165165
$this->setShippingAndBillingAddressForQuote($cartId);
166166
$order = $this->orderRepository->get($this->selectDhlAndCheckmoAndPlaceOrder($cartId));
167167
$this->assertNotEmpty($order->getIncrementId());
168-
$this->assertSame('dhl_P', $order->getShippingMethod());
168+
$this->assertStringStartsWith('dhl_', $order->getShippingMethod());
169169
}
170170

171171
/**
@@ -178,7 +178,7 @@ private function setShippingAndBillingAddressForQuote(int $cartId): void
178178
{
179179
$quote = $this->quoteRepository->get($cartId);
180180
/** @var AddressInterface $address */
181-
$address = $this->objectManager->create(AddressInterface::class);
181+
$address = $this->objectManager->create(AddressInterface::class);
182182
$address->setFirstname('Joe')
183183
->setLastname('Doe')
184184
->setCountryId('CA')
@@ -202,9 +202,20 @@ private function setShippingAndBillingAddressForQuote(int $cartId): void
202202
private function selectDhlAndCheckmoAndPlaceOrder(int $cartId): int
203203
{
204204
$quote = $this->quoteRepository->get($cartId);
205-
$quote->getShippingAddress()->setShippingMethod('dhl_P')->setCollectShippingRates(true);
206-
$quote->collectTotals();
205+
$shippingAddress = $quote->getShippingAddress();
206+
$shippingAddress->setCollectShippingRates(true);
207+
$shippingAddress->collectShippingRates();
208+
$dhlRate = null;
209+
foreach ($shippingAddress->getAllShippingRates() as $rate) {
210+
if ($rate->getCarrier() === 'dhl') {
211+
$dhlRate = $rate;
212+
break;
213+
}
214+
}
215+
$this->assertNotEmpty($dhlRate, 'No DHL rates available for the given address.');
216+
$shippingAddress->setShippingMethod($dhlRate->getCode());
207217
$quote->getPayment()->setMethod('checkmo');
218+
$quote->collectTotals();
208219
$this->quoteRepository->save($quote);
209220
return (int)$this->cartManagement->placeOrder($quote->getId());
210221
}

0 commit comments

Comments
 (0)