55 */
66namespace Magento \Quote \Model \Quote ;
77
8+ use Magento \Store \Api \StoreRepositoryInterface ;
89use Magento \TestFramework \Helper \Bootstrap ;
910
1011/**
@@ -25,6 +26,9 @@ class AddressTest extends \PHPUnit\Framework\TestCase
2526 /**@var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
2627 protected $ customerRepository ;
2728
29+ /** @var StoreRepositoryInterface */
30+ private $ storeRepository ;
31+
2832 /**
2933 * Initialize quote and customer fixtures
3034 */
@@ -48,6 +52,8 @@ public function setUp()
4852 $ this ->_address ->setId (1 );
4953 $ this ->_address ->load ($ this ->_address ->getId ());
5054 $ this ->_address ->setQuote ($ this ->_quote );
55+ $ this ->storeRepository = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
56+ ->create (StoreRepositoryInterface::class);
5157 }
5258
5359 protected function tearDown ()
@@ -309,4 +315,50 @@ public function dataProvider()
309315 [[123 , true ], [123 , true ]]
310316 ];
311317 }
318+
319+ /**
320+ * Tests different shipping rates for different stores.
321+ *
322+ * @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
323+ * @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
324+ * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
325+ * @magentoDataFixture Magento/Sales/_files/quote.php
326+ * @magentoConfigFixture default_store carriers/flatrate/price 5
327+ * @magentoConfigFixture fixture_second_store_store carriers/flatrate/price 10
328+ * @magentoAppIsolation enabled
329+ * @magentoDbIsolation enabled
330+ * @dataProvider requestShippingRatesDataProvider
331+ */
332+ public function testRequestShippingRates ($ storeCode , $ expectedRate )
333+ {
334+ $ store = $ this ->storeRepository ->get ($ storeCode );
335+ $ this ->_quote ->setStoreId ($ store ->getId ());
336+ $ this ->_address ->setItemQty (1 );
337+ $ this ->_address ->requestShippingRates ();
338+ /**
339+ * @var \Magento\Quote\Model\ResourceModel\Quote\Address\Rate\Collection $shippingRatesCollection
340+ */
341+ $ shippingRatesCollection = $ this ->_address ->getShippingRatesCollection ();
342+ /**
343+ * @var \Magento\Quote\Model\Quote\Address\Rate[] $shippingRates
344+ */
345+ $ shippingRates = $ shippingRatesCollection ->getItems ();
346+ self ::assertEquals (
347+ $ expectedRate ,
348+ $ shippingRates [0 ]->getPrice ()
349+ );
350+ }
351+
352+ /**
353+ * Data provider for testRequestShippingRates.
354+ *
355+ * @return array
356+ */
357+ public function requestShippingRatesDataProvider ()
358+ {
359+ return [
360+ ['default ' , 5 ],
361+ ['fixture_second_store ' , 10 ],
362+ ];
363+ }
312364}
0 commit comments