Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxConfigProviderTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Tax\Model\Config;
9 
10 class TaxConfigProviderTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $taxHelperMock;
16 
20  protected $taxConfigMock;
21 
26 
30  protected $scopeConfigMock;
31 
35  protected $quoteMock;
36 
40  protected $model;
41 
42  protected function setUp()
43  {
44  $this->taxHelperMock = $this->createMock(\Magento\Tax\Helper\Data::class);
45  $this->taxConfigMock = $this->createMock(\Magento\Tax\Model\Config::class);
46  $this->checkoutSessionMock = $this->createMock(\Magento\Checkout\Model\Session::class);
47  $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
48  $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
49  $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
50  $this->model = new \Magento\Tax\Model\TaxConfigProvider(
51  $this->taxHelperMock,
52  $this->taxConfigMock,
53  $this->checkoutSessionMock,
54  $this->scopeConfigMock
55  );
56  }
57 
70  public function testGetConfig(
71  $expectedResult,
72  $cartShippingBoth,
73  $cartShippingExclTax,
74  $cartBothPrices,
75  $cartPriceExclTax,
76  $cartSubTotalBoth,
77  $cartSubTotalExclTax,
78  $isQuoteVirtual,
79  $config
80  ) {
81  $this->taxConfigMock->expects($this->any())->method('displayCartShippingBoth')
82  ->will($this->returnValue($cartShippingBoth));
83  $this->taxConfigMock->expects($this->any())->method('displayCartShippingExclTax')
84  ->will($this->returnValue($cartShippingExclTax));
85 
86  $this->taxHelperMock->expects($this->any())->method('displayCartBothPrices')
87  ->will($this->returnValue($cartBothPrices));
88  $this->taxHelperMock->expects($this->any())->method('displayCartPriceExclTax')
89  ->will($this->returnValue($cartPriceExclTax));
90 
91  $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalBoth')
92  ->will($this->returnValue($cartSubTotalBoth));
93  $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalExclTax')
94  ->will($this->returnValue($cartSubTotalExclTax));
95 
96  $this->taxHelperMock->expects(($this->any()))->method('displayShippingPriceExcludingTax')
97  ->will($this->returnValue(1));
98  $this->taxHelperMock->expects(($this->any()))->method('displayShippingBothPrices')
99  ->will($this->returnValue(1));
100  $this->taxHelperMock->expects(($this->any()))->method('displayFullSummary')
101  ->will($this->returnValue(1));
102  $this->taxConfigMock->expects(($this->any()))->method('displayCartTaxWithGrandTotal')
103  ->will($this->returnValue(1));
104  $this->taxConfigMock->expects(($this->any()))->method('displayCartZeroTax')
105  ->will($this->returnValue(1));
106 
107  $valueMap = [];
108  foreach ($config as $key => $value) {
109  $valueMap[] = [$key, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, $value];
110  }
111  $this->scopeConfigMock->expects($this->atLeastOnce())
112  ->method('getValue')
113  ->willReturnMap($valueMap);
114  $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn($isQuoteVirtual);
115  $this->assertEquals($expectedResult, $this->model->getConfig());
116  }
117 
122  public function getConfigDataProvider()
123  {
124  return [
125  [
126  'expectedResult' => [
127  'isDisplayShippingPriceExclTax' => 1,
128  'isDisplayShippingBothPrices' => 1,
129  'reviewShippingDisplayMode' => 'both',
130  'reviewItemPriceDisplayMode' => 'both',
131  'reviewTotalsDisplayMode' => 'both',
132  'includeTaxInGrandTotal' => 1,
133  'isFullTaxSummaryDisplayed' => 1,
134  'isZeroTaxDisplayed' => 1,
135  'reloadOnBillingAddress' => false,
136  'defaultCountryId' => 'US',
137  'defaultRegionId' => 12,
138  'defaultPostcode' => '*',
139  ],
140  'cartShippingBoth' => 1,
141  'cartShippingExclTax' => 1,
142  'cartBothPrices' => 1,
143  'cartPriceExclTax' => 1,
144  'cartSubTotalBoth' => 1,
145  'cartSubTotalExclTax' => 1,
146  'isQuoteVirtual' => false,
147  'config' => [
148  Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
152  ],
153  ],
154  [
155  'expectedResult' => [
156  'isDisplayShippingPriceExclTax' => 1,
157  'isDisplayShippingBothPrices' => 1,
158  'reviewShippingDisplayMode' => 'excluding',
159  'reviewItemPriceDisplayMode' => 'excluding',
160  'reviewTotalsDisplayMode' => 'excluding',
161  'includeTaxInGrandTotal' => 1,
162  'isFullTaxSummaryDisplayed' => 1,
163  'isZeroTaxDisplayed' => 1,
164  'reloadOnBillingAddress' => true,
165  'defaultCountryId' => 'US',
166  'defaultRegionId' => 12,
167  'defaultPostcode' => '*',
168  ],
169  'cartShippingBoth' => 0,
170  'cartShippingExclTax' => 1,
171  'cartBothPrices' => 0,
172  'cartPriceExclTax' => 1,
173  'cartSubTotalBoth' => 0,
174  'cartSubTotalExclTax' => 1,
175  'isQuoteVirtual' => false,
176  'config' => [
181  ],
182  ],
183  [
184  'expectedResult' => [
185  'isDisplayShippingPriceExclTax' => 1,
186  'isDisplayShippingBothPrices' => 1,
187  'reviewShippingDisplayMode' => 'including',
188  'reviewItemPriceDisplayMode' => 'including',
189  'reviewTotalsDisplayMode' => 'including',
190  'includeTaxInGrandTotal' => 1,
191  'isFullTaxSummaryDisplayed' => 1,
192  'isZeroTaxDisplayed' => 1,
193  'reloadOnBillingAddress' => true,
194  'defaultCountryId' => 'US',
195  'defaultRegionId' => 12,
196  'defaultPostcode' => '*',
197  ],
198  'cartShippingBoth' => 0,
199  'cartShippingExclTax' => 0,
200  'cartBothPrices' => 0,
201  'cartPriceExclTax' => 0,
202  'cartSubTotalBoth' => 0,
203  'cartSubTotalExclTax' => 0,
204  'isQuoteVirtual' => true,
205  'config' => [
206  Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
210  ],
211  ],
212  [
213  'expectedResult' => [
214  'isDisplayShippingPriceExclTax' => 1,
215  'isDisplayShippingBothPrices' => 1,
216  'reviewShippingDisplayMode' => 'including',
217  'reviewItemPriceDisplayMode' => 'including',
218  'reviewTotalsDisplayMode' => 'including',
219  'includeTaxInGrandTotal' => 1,
220  'isFullTaxSummaryDisplayed' => 1,
221  'isZeroTaxDisplayed' => 1,
222  'reloadOnBillingAddress' => true,
223  'defaultCountryId' => 'US',
224  'defaultRegionId' => 12,
225  'defaultPostcode' => '*',
226  ],
227  'cartShippingBoth' => 0,
228  'cartShippingExclTax' => 0,
229  'cartBothPrices' => 0,
230  'cartPriceExclTax' => 0,
231  'cartSubTotalBoth' => 0,
232  'cartSubTotalExclTax' => 0,
233  'isQuoteVirtual' => true,
234  'config' => [
239  ],
240  ],
241  [
242  'expectedResult' => [
243  'isDisplayShippingPriceExclTax' => 1,
244  'isDisplayShippingBothPrices' => 1,
245  'reviewShippingDisplayMode' => 'both',
246  'reviewItemPriceDisplayMode' => 'both',
247  'reviewTotalsDisplayMode' => 'both',
248  'includeTaxInGrandTotal' => 1,
249  'isFullTaxSummaryDisplayed' => 1,
250  'isZeroTaxDisplayed' => 1,
251  'reloadOnBillingAddress' => false,
252  'defaultCountryId' => 'US',
253  'defaultRegionId' => 12,
254  'defaultPostcode' => '*',
255  ],
256  'cartShippingBoth' => 1,
257  'cartShippingExclTax' => 0,
258  'cartBothPrices' => 1,
259  'cartPriceExclTax' => 0,
260  'cartSubTotalBoth' => 1,
261  'cartSubTotalExclTax' => 0,
262  'isQuoteVirtual' => false,
263  'config' => [
264  Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
268  ],
269  ],
270  [
271  'expectedResult' => [
272  'isDisplayShippingPriceExclTax' => 1,
273  'isDisplayShippingBothPrices' => 1,
274  'reviewShippingDisplayMode' => 'excluding',
275  'reviewItemPriceDisplayMode' => 'including',
276  'reviewTotalsDisplayMode' => 'both',
277  'includeTaxInGrandTotal' => 1,
278  'isFullTaxSummaryDisplayed' => 1,
279  'isZeroTaxDisplayed' => 1,
280  'reloadOnBillingAddress' => false,
281  'defaultCountryId' => 'US',
282  'defaultRegionId' => 12,
283  'defaultPostcode' => '*',
284  ],
285  'cartShippingBoth' => 0,
286  'cartShippingExclTax' => 1,
287  'cartBothPrices' => 0,
288  'cartPriceExclTax' => 0,
289  'cartSubTotalBoth' => 1,
290  'cartSubTotalExclTax' => 0,
291  'isQuoteVirtual' => false,
292  'config' => [
293  Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
297  ],
298  ],
299  'zeroRegionToNull' => [
300  'expectedResult' => [
301  'isDisplayShippingPriceExclTax' => 1,
302  'isDisplayShippingBothPrices' => 1,
303  'reviewShippingDisplayMode' => 'excluding',
304  'reviewItemPriceDisplayMode' => 'including',
305  'reviewTotalsDisplayMode' => 'both',
306  'includeTaxInGrandTotal' => 1,
307  'isFullTaxSummaryDisplayed' => 1,
308  'isZeroTaxDisplayed' => 1,
309  'reloadOnBillingAddress' => false,
310  'defaultCountryId' => 'US',
311  'defaultRegionId' => null,
312  'defaultPostcode' => '*',
313  ],
314  'cartShippingBoth' => 0,
315  'cartShippingExclTax' => 1,
316  'cartBothPrices' => 0,
317  'cartPriceExclTax' => 0,
318  'cartSubTotalBoth' => 1,
319  'cartSubTotalExclTax' => 0,
320  'isQuoteVirtual' => false,
321  'config' => [
322  Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
326  ],
327  ],
328  ];
329  }
330 }
const CONFIG_XML_PATH_DEFAULT_POSTCODE
Definition: Config.php:55
$config
Definition: fraud_order.php:17
const CONFIG_XML_PATH_DEFAULT_REGION
Definition: Config.php:53
const CONFIG_XML_PATH_DEFAULT_COUNTRY
Definition: Config.php:51
$value
Definition: gender.phtml:16
testGetConfig( $expectedResult, $cartShippingBoth, $cartShippingExclTax, $cartBothPrices, $cartPriceExclTax, $cartSubTotalBoth, $cartSubTotalExclTax, $isQuoteVirtual, $config)
const CONFIG_XML_PATH_BASED_ON
Definition: Config.php:38