5
5
*/
6
6
namespace Magento \Quote \Model \Quote ;
7
7
8
+ use Magento \Store \Api \StoreRepositoryInterface ;
8
9
use Magento \TestFramework \Helper \Bootstrap ;
9
10
10
11
/**
@@ -25,6 +26,9 @@ class AddressTest extends \PHPUnit\Framework\TestCase
25
26
/**@var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
26
27
protected $ customerRepository ;
27
28
29
+ /** @var StoreRepositoryInterface */
30
+ private $ storeRepository ;
31
+
28
32
/**
29
33
* Initialize quote and customer fixtures
30
34
*/
@@ -48,6 +52,8 @@ public function setUp()
48
52
$ this ->_address ->setId (1 );
49
53
$ this ->_address ->load ($ this ->_address ->getId ());
50
54
$ this ->_address ->setQuote ($ this ->_quote );
55
+ $ this ->storeRepository = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
56
+ ->create (StoreRepositoryInterface::class);
51
57
}
52
58
53
59
protected function tearDown ()
@@ -309,4 +315,50 @@ public function dataProvider()
309
315
[[123 , true ], [123 , true ]]
310
316
];
311
317
}
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
+ }
312
364
}
0 commit comments