Skip to content

Commit 5e12cf5

Browse files
committed
AC-15664::Added integration test for modified methods
1 parent 257edb5 commit 5e12cf5

File tree

1 file changed

+190
-0
lines changed

1 file changed

+190
-0
lines changed
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Multishipping\Block\Checkout;
10+
11+
use Magento\Framework\App\Area;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Framework\Pricing\PriceCurrencyInterface;
14+
use Magento\Quote\Model\Quote;
15+
use Magento\Quote\Model\Quote\Address;
16+
use Magento\Quote\Model\Quote\Address\Rate;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
use Magento\TestFramework\Helper\Bootstrap;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class OverviewCurrencyTest extends TestCase
22+
{
23+
/** @var ObjectManagerInterface */
24+
private $objectManager;
25+
26+
/** @var StoreManagerInterface */
27+
private $storeManager;
28+
29+
protected function setUp(): void
30+
{
31+
Bootstrap::getInstance()->loadArea(Area::AREA_FRONTEND);
32+
$this->objectManager = Bootstrap::getObjectManager();
33+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
34+
}
35+
36+
/**
37+
* @magentoConfigFixture default_store currency/options/base USD
38+
* @magentoConfigFixture default_store currency/options/default USD
39+
* @magentoConfigFixture default_store currency/options/allow USD
40+
*/
41+
public function testGetShippingPriceInclTaxSameCurrency(): void
42+
{
43+
$store = $this->storeManager->getStore();
44+
45+
$quote = $this->objectManager->create(Quote::class);
46+
$quote->setStore($store);
47+
48+
$multishipping = $this->getMockBuilder(\Magento\Multishipping\Model\Checkout\Type\Multishipping::class)
49+
->disableOriginalConstructor()
50+
->onlyMethods(['getQuote'])
51+
->getMock();
52+
$multishipping->method('getQuote')->willReturn($quote);
53+
54+
$block = $this->objectManager->create(Overview::class, ['multishipping' => $multishipping]);
55+
56+
$address = $this->objectManager->create(Address::class);
57+
$address->setShippingMethod('flatrate_flatrate');
58+
$address->setShippingTaxAmount(2.5);
59+
60+
$rate = $this->objectManager->create(Rate::class);
61+
$rate->setCode('flatrate_flatrate');
62+
$rate->setPrice(10.0);
63+
$address->addShippingRate($rate);
64+
65+
$result = $block->getShippingPriceInclTax($address);
66+
67+
/** @var PriceCurrencyInterface $priceCurrency */
68+
$priceCurrency = $this->objectManager->get(PriceCurrencyInterface::class);
69+
$expected = $priceCurrency->format(12.5, true, PriceCurrencyInterface::DEFAULT_PRECISION, $store);
70+
71+
$this->assertSame($expected, $result);
72+
}
73+
74+
/**
75+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
76+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate_rollback.php
77+
* @magentoConfigFixture default_store currency/options/base USD
78+
* @magentoConfigFixture default_store currency/options/default CNY
79+
* @magentoConfigFixture default_store currency/options/allow USD,CNY
80+
*/
81+
public function testGetShippingPriceInclTaxDifferentCurrency(): void
82+
{
83+
$currency = $this->getMockBuilder(\Magento\Directory\Model\Currency::class)
84+
->disableOriginalConstructor()
85+
->onlyMethods(['convert'])
86+
->getMock();
87+
$currency->method('convert')->with(12.0, 'CNY')->willReturn(12.0);
88+
89+
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)
90+
->disableOriginalConstructor()
91+
->onlyMethods(['getBaseCurrencyCode', 'getCurrentCurrencyCode', 'getBaseCurrency'])
92+
->getMock();
93+
$store->method('getBaseCurrencyCode')->willReturn('USD');
94+
$store->method('getCurrentCurrencyCode')->willReturn('CNY');
95+
$store->method('getBaseCurrency')->willReturn($currency);
96+
97+
$quote = $this->objectManager->create(Quote::class);
98+
$quote->setStore($store);
99+
100+
$multishipping = $this->getMockBuilder(\Magento\Multishipping\Model\Checkout\Type\Multishipping::class)
101+
->disableOriginalConstructor()
102+
->onlyMethods(['getQuote'])
103+
->getMock();
104+
$multishipping->method('getQuote')->willReturn($quote);
105+
106+
$block = $this->objectManager->create(Overview::class, ['multishipping' => $multishipping]);
107+
108+
$address = $this->objectManager->create(Address::class);
109+
$address->setShippingMethod('flatrate_flatrate');
110+
$address->setBaseShippingTaxAmount(2.0);
111+
112+
$rate = $this->objectManager->create(Rate::class);
113+
$rate->setCode('flatrate_flatrate');
114+
$rate->setPrice(10.0);
115+
$address->addShippingRate($rate);
116+
117+
$expected = $block->formatPrice(10.0);
118+
119+
$this->assertSame($expected, $block->getShippingPriceInclTax($address));
120+
}
121+
122+
/**
123+
* @magentoConfigFixture default_store currency/options/base USD
124+
* @magentoConfigFixture default_store currency/options/default USD
125+
* @magentoConfigFixture default_store currency/options/allow USD
126+
*/
127+
public function testGetShippingPriceExclTaxSameCurrency(): void
128+
{
129+
$store = $this->storeManager->getStore();
130+
131+
$quote = $this->objectManager->create(Quote::class);
132+
$quote->setStore($store);
133+
134+
$multishipping = $this->getMockBuilder(\Magento\Multishipping\Model\Checkout\Type\Multishipping::class)
135+
->disableOriginalConstructor()
136+
->onlyMethods(['getQuote'])
137+
->getMock();
138+
$multishipping->method('getQuote')->willReturn($quote);
139+
140+
$block = $this->objectManager->create(Overview::class, ['multishipping' => $multishipping]);
141+
142+
$address = $this->objectManager->create(Address::class);
143+
$address->setShippingMethod('flatrate_flatrate');
144+
145+
$rate = $this->objectManager->create(Rate::class);
146+
$rate->setCode('flatrate_flatrate');
147+
$rate->setPrice(15.75);
148+
$address->addShippingRate($rate);
149+
150+
$expected = $block->formatPrice(15.75);
151+
$this->assertSame($expected, $block->getShippingPriceExclTax($address));
152+
}
153+
154+
/**
155+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php
156+
* @magentoDataFixture Magento/Directory/_files/usd_cny_rate_rollback.php
157+
* @magentoConfigFixture default_store currency/options/base USD
158+
* @magentoConfigFixture default_store currency/options/default CNY
159+
* @magentoConfigFixture default_store currency/options/allow USD,CNY
160+
*/
161+
public function testGetShippingPriceExclTaxDifferentCurrency(): void
162+
{
163+
$store = $this->storeManager->getStore();
164+
$store->setCurrentCurrencyCode('CNY');
165+
166+
$quote = $this->objectManager->create(Quote::class);
167+
$quote->setStore($store);
168+
169+
$multishipping = $this->getMockBuilder(\Magento\Multishipping\Model\Checkout\Type\Multishipping::class)
170+
->disableOriginalConstructor()
171+
->onlyMethods(['getQuote'])
172+
->getMock();
173+
$multishipping->method('getQuote')->willReturn($quote);
174+
175+
$block = $this->objectManager->create(Overview::class, ['multishipping' => $multishipping]);
176+
177+
$address = $this->objectManager->create(Address::class);
178+
$address->setShippingMethod('flatrate_flatrate');
179+
180+
$rate = $this->objectManager->create(Rate::class);
181+
$rate->setCode('flatrate_flatrate');
182+
$rate->setPrice(20.0);
183+
$address->addShippingRate($rate);
184+
185+
$converted = $store->getBaseCurrency()->convert(20.0, $store->getCurrentCurrencyCode());
186+
$expected = $block->formatPrice($converted);
187+
188+
$this->assertSame($expected, $block->getShippingPriceExclTax($address));
189+
}
190+
}

0 commit comments

Comments
 (0)