Skip to content

Commit f8a7ac6

Browse files
author
Robert He
committed
MAGETWO-31371: Improve Unit and Integration test coverage
- more fixes for isTaxIncluded key
1 parent 63a818d commit f8a7ac6

File tree

8 files changed

+187
-92
lines changed

8 files changed

+187
-92
lines changed

app/code/Magento/GoogleShopping/Model/Attribute/Tax.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ public function convertAttribute($product, $entry)
170170
foreach ($regions as $region) {
171171
$adjustments = $product->getPriceInfo()->getAdjustments();
172172
if (array_key_exists('tax', $adjustments)) {
173-
$taxIncluded = true;
173+
$isTaxIncluded = true;
174174
} else {
175-
$taxIncluded = false;
175+
$isTaxIncluded = false;
176176
}
177177

178178
$quoteDetailsItemDataArray = [
@@ -184,7 +184,7 @@ public function convertAttribute($product, $entry)
184184
],
185185
'unit_price' => $product->getPrice(),
186186
'quantity' => 1,
187-
'tax_included' => $taxIncluded,
187+
'is_tax_included' => $isTaxIncluded,
188188
'short_description' => $product->getName(),
189189
];
190190

app/code/Magento/GoogleShopping/Test/Unit/Model/Attribute/TaxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function testConvertAttribute()
192192
],
193193
'unit_price' => $price,
194194
'quantity' => 1,
195-
'tax_included' => 1,
195+
'is_tax_included' => 1,
196196
'short_description' => $name,
197197
],
198198
],

app/code/Magento/Tax/Api/Data/QuoteDetailsItemInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface QuoteDetailsItemInterface extends \Magento\Framework\Api\ExtensibleDat
2020

2121
const KEY_QUANTITY = 'quantity';
2222

23-
const KEY_TAX_INCLUDED = 'tax_included';
23+
const KEY_IS_TAX_INCLUDED = 'is_tax_included';
2424

2525
const KEY_SHORT_DESCRIPTION = 'short_description';
2626

app/code/Magento/Tax/Model/Sales/Quote/ItemDetails.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getQuantity()
5858
*/
5959
public function getIsTaxIncluded()
6060
{
61-
return $this->getData(QuoteDetailsItemInterface::KEY_TAX_INCLUDED);
61+
return $this->getData(QuoteDetailsItemInterface::KEY_IS_TAX_INCLUDED);
6262
}
6363

6464
/**
@@ -164,7 +164,7 @@ public function setQuantity($quantity)
164164
*/
165165
public function setIsTaxIncluded($isTaxIncluded)
166166
{
167-
return $this->setData(QuoteDetailsItemInterface::KEY_TAX_INCLUDED, $isTaxIncluded);
167+
return $this->setData(QuoteDetailsItemInterface::KEY_IS_TAX_INCLUDED, $isTaxIncluded);
168168
}
169169

170170
/**

app/code/Magento/Tax/Test/Unit/GetterSetterTest.php

Lines changed: 156 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class GetterSetterTest extends \PHPUnit_Framework_TestCase
99
{
1010
/**
1111
* @param string $className
12-
* @param array $variableNames
12+
* @param array $variables
1313
* @dataProvider dataProviderGettersSetters
1414
*/
15-
public function testGettersSetters($className = null, $variableNames = null)
15+
public function testGettersSetters($className = null, $variables = null)
1616
{
1717
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
1818
$classObject = $objectManager->getObject($className);
1919

20-
foreach ($variableNames as $variableName => $variableValue) {
20+
foreach ($variables as $variableName => $variableValue) {
2121
$setterName = 'set' . $variableName;
2222

2323
$this->assertTrue(method_exists($classObject, $setterName),
@@ -27,23 +27,23 @@ public function testGettersSetters($className = null, $variableNames = null)
2727
if (strpos($variableValue[0], 'Magento') !== false) {
2828
$obj = $objectManager->getObject($variableValue[0]);
2929
$variableValue = [$obj];
30-
$variableNames[$variableName] = $variableValue;
30+
$variables[$variableName] = $variableValue;
3131
}
3232
} else if (strpos($variableValue, 'Magento') !== false) {
3333
$obj = $objectManager->getObject($variableValue);
3434
$variableValue = $obj;
35-
$variableNames[$variableName] = $variableValue;
35+
$variables[$variableName] = $variableValue;
3636
}
37-
$this->assertNotFalse(call_user_func(array($classObject, $setterName), $variableValue),
37+
$this->assertNotFalse(call_user_func([$classObject, $setterName], $variableValue),
3838
"Calling method " . $setterName . " failed in " . $className);
3939
}
4040

41-
foreach ($variableNames as $variableName => $variableValue) {
41+
foreach ($variables as $variableName => $variableValue) {
4242
$getterName = 'get' . $variableName;
4343

4444
$this->assertTrue(method_exists($classObject, $getterName),
4545
"Method " . $getterName . " does not exist in " . $className);
46-
$result = call_user_func(array($classObject, $getterName));
46+
$result = call_user_func([$classObject, $getterName]);
4747
$this->assertNotFalse($result,
4848
"Calling method " . $getterName . " failed in " . $className);
4949
$this->assertSame($result, $variableValue,
@@ -60,98 +60,193 @@ public function dataProviderGettersSetters()
6060
return [
6161
[
6262
'Magento\Tax\Model\TaxDetails\AppliedTax',
63-
['TaxRateKey' => 'taxRateKey', 'Percent' => 1.0, 'Amount' => 1.0,
64-
'Rates' => ['Magento\Tax\Model\TaxDetails\AppliedTaxRate'],
65-
'ExtensionAttributes' => 'Magento\Tax\Api\Data\AppliedTaxExtension']
63+
[
64+
'TaxRateKey' => 'taxRateKey',
65+
'Percent' => 1.0,
66+
'Amount' => 1.0,
67+
'Rates' =>
68+
[
69+
'Magento\Tax\Model\TaxDetails\AppliedTaxRate'
70+
],
71+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\AppliedTaxExtension'
72+
]
6673
],
6774
[
6875
'Magento\Tax\Model\TaxDetails\AppliedTaxRate',
69-
['Code' => 'code', 'Title' => 'title', 'Percent' => 1.0,
70-
'ExtensionAttributes' => 'Magento\Tax\Api\Data\AppliedTaxRateExtension']
76+
[
77+
'Code' => 'code',
78+
'Title' => 'title',
79+
'Percent' => 1.0,
80+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\AppliedTaxRateExtension'
81+
]
7182
],
7283
[
7384
'Magento\Tax\Model\Sales\Order\Tax',
74-
['Code' => 'code', 'Title' => 'title', 'Percent' => 1.0, 'Amount' => 'amount',
75-
'BaseAmount' => 'baseAmount',
76-
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxExtension']
85+
[
86+
'Code' => 'code',
87+
'Title' => 'title',
88+
'Percent' => 1.0,
89+
'Amount' => 'amount',
90+
'BaseAmount' => 'baseAmount',
91+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxExtension'
92+
]
7793
],
7894
[
7995
'Magento\Tax\Model\Sales\Order\Details',
80-
['AppliedTaxes' => ['Magento\Tax\Model\Sales\Order\Tax'],
81-
'Items' => ['Magento\Tax\Model\Sales\Order\Tax\Item'],
82-
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsExtension']
96+
[
97+
'AppliedTaxes' =>
98+
[
99+
'Magento\Tax\Model\Sales\Order\Tax'
100+
],
101+
'Items' =>
102+
[
103+
'Magento\Tax\Model\Sales\Order\Tax\Item'
104+
],
105+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsExtension'
106+
]
83107
],
84108
[
85109
'Magento\Tax\Model\Sales\Order\Tax\Item',
86-
['Type' => 'type', 'ItemId' => 1, 'AssociatedItemId' => 1,
87-
'AppliedTaxes' => ['Magento\Tax\Model\Sales\Order\Tax'],
88-
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsItemExtension']
110+
[
111+
'Type' => 'type',
112+
'ItemId' => 1,
113+
'AssociatedItemId' => 1,
114+
'AppliedTaxes' =>
115+
[
116+
'Magento\Tax\Model\Sales\Order\Tax'
117+
],
118+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\OrderTaxDetailsItemExtension'
119+
]
89120
],
90121
[
91122
'Magento\Tax\Model\Sales\Quote\QuoteDetails',
92-
['BillingAddress' => 'Magento\Customer\Model\Data\Address',
93-
'ShippingAddress' => 'Magento\Customer\Model\Data\Address',
94-
'CustomerTaxClassKey' => 'Magento\Tax\Model\TaxClass\Key',
95-
'CustomerId' => 1,
96-
'Items' => ['Magento\Tax\Model\Sales\Order\Tax\Item'],
97-
'CustomerTaxClassId' => 1,
98-
'ExtensionAttributes' => 'Magento\Tax\Api\Data\QuoteDetailsExtension']
123+
[
124+
'BillingAddress' => 'Magento\Customer\Model\Data\Address',
125+
'ShippingAddress' => 'Magento\Customer\Model\Data\Address',
126+
'CustomerTaxClassKey' => 'Magento\Tax\Model\TaxClass\Key',
127+
'CustomerId' => 1,
128+
'Items' =>
129+
[
130+
'Magento\Tax\Model\Sales\Order\Tax\Item'
131+
],
132+
'CustomerTaxClassId' => 1,
133+
'ExtensionAttributes' => 'Magento\Tax\Api\Data\QuoteDetailsExtension'
134+
]
99135
],
100136
[
101137
'Magento\Tax\Model\Sales\Quote\ItemDetails',
102-
['Code' => 'code', 'Type' => 'type',
103-
'TaxClassKey' => 'Magento\Tax\Model\TaxClass\Key',
104-
'UnitPrice' => 1.0, 'Quantity' => 1.0,
105-
'IsTaxIncluded' => true, 'ShortDescription' => 'shortDescription',
106-
'DiscountAmount' => 1.0, 'ParentCode' => 'parentCode', 'AssociatedItemCode' => 1,
107-
'TaxClassId' => 1,
108-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\QuoteDetailsItemExtension']
138+
[
139+
'Code' => 'code',
140+
'Type' => 'type',
141+
'TaxClassKey' => 'Magento\Tax\Model\TaxClass\Key',
142+
'UnitPrice' => 1.0,
143+
'Quantity' => 1.0,
144+
'IsTaxIncluded' => true,
145+
'ShortDescription' => 'shortDescription',
146+
'DiscountAmount' => 1.0,
147+
'ParentCode' => 'parentCode',
148+
'AssociatedItemCode' => 1,
149+
'TaxClassId' => 1,
150+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\QuoteDetailsItemExtension'
151+
]
109152
],
110153
[
111154
'Magento\Tax\Model\ClassModel',
112-
['ClassId' => 1, 'ClassName' => 'className', 'ClassType' => 'classType',
113-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassExtension']
155+
[
156+
'ClassId' => 1,
157+
'ClassName' => 'className',
158+
'ClassType' => 'classType',
159+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassExtension'
160+
]
114161
],
115162
[
116163
'Magento\Tax\Model\TaxClass\Key',
117-
['Type' => 'type', 'Value' => 'value',
118-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassKeyExtension']
164+
[
165+
'Type' => 'type',
166+
'Value' => 'value',
167+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassKeyExtension'
168+
]
119169
],
120170
[
121171
'Magento\Tax\Model\TaxDetails\TaxDetails',
122-
['Subtotal' => 1.0, 'TaxAmount' => 1.0,
123-
'DiscountTaxCompensationAmount' => 1.0,
124-
'AppliedTaxes' => ['Magento\Tax\Model\TaxDetails\AppliedTax'],
125-
'Items' => ['Magento\Tax\Model\TaxDetails\ItemDetails'],
126-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxDetailsExtension']
172+
[
173+
'Subtotal' => 1.0,
174+
'TaxAmount' => 1.0,
175+
'DiscountTaxCompensationAmount' => 1.0,
176+
'AppliedTaxes' =>
177+
[
178+
'Magento\Tax\Model\TaxDetails\AppliedTax'
179+
],
180+
'Items' =>
181+
[
182+
'Magento\Tax\Model\TaxDetails\ItemDetails'
183+
],
184+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxDetailsExtension'
185+
]
127186
],
128187
[
129188
'Magento\Tax\Model\TaxDetails\ItemDetails',
130-
['Code' => 'code', 'Type' => 'type', 'TaxPercent' => 1.0, 'Price' => 1.0, 'PriceInclTax' => 1.0,
131-
'RowTotal' => 1.0, 'RowTotalInclTax' => 1.0, 'RowTax' => 1.0, 'TaxableAmount' => 1.0,
132-
'DiscountAmount' => 1.0, 'DiscountTaxCompensationAmount' => 1.0,
133-
'AppliedTaxes' => ['Magento\Tax\Model\TaxDetails\AppliedTax'],
134-
'AssociatedItemCode' => 1,
135-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxDetailsItemExtension']
189+
[
190+
'Code' => 'code',
191+
'Type' => 'type',
192+
'TaxPercent' => 1.0,
193+
'Price' => 1.0,
194+
'PriceInclTax' => 1.0,
195+
'RowTotal' => 1.0,
196+
'RowTotalInclTax' => 1.0,
197+
'RowTax' => 1.0,
198+
'TaxableAmount' => 1.0,
199+
'DiscountAmount' => 1.0,
200+
'DiscountTaxCompensationAmount' => 1.0,
201+
'AppliedTaxes' =>
202+
[
203+
'Magento\Tax\Model\TaxDetails\AppliedTax'
204+
],
205+
'AssociatedItemCode' => 1,
206+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxDetailsItemExtension'
207+
]
136208
],
137209
[
138210
'Magento\Tax\Model\Calculation\Rate',
139-
['Id' => 1, 'TaxCountryId' => 'taxCountryId', 'TaxRegionId' => 1, 'RegionName' => 'regionName',
140-
'TaxPostcode' => 'taxPostCode', 'ZipIsRange' => 1, 'ZipFrom' => 1, 'ZipTo' => 1,
141-
'Rate' => 1.0, 'Code' => 'code',
142-
'Titles' => ['Magento\Tax\Model\Calculation\Rate\Title'],
143-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRateExtension']
211+
[
212+
'Id' => 1,
213+
'TaxCountryId' => 'taxCountryId',
214+
'TaxRegionId' => 1,
215+
'RegionName' => 'regionName',
216+
'TaxPostcode' => 'taxPostCode',
217+
'ZipIsRange' => 1,
218+
'ZipFrom' => 1,
219+
'ZipTo' => 1,
220+
'Rate' => 1.0,
221+
'Code' => 'code',
222+
'Titles' =>
223+
[
224+
'Magento\Tax\Model\Calculation\Rate\Title'
225+
],
226+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRateExtension'
227+
]
144228
],
145229
[
146230
'Magento\Tax\Model\Calculation\Rate\Title',
147-
['StoreId' => 'storeId', 'Value' => 'value',
148-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRateTitleExtension']
231+
[
232+
'StoreId' => 'storeId',
233+
'Value' => 'value',
234+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRateTitleExtension'
235+
]
149236
],
150237
[
151238
'Magento\Tax\Model\Calculation\Rule',
152-
['Id' => 1, 'Code' => 'code', 'Priority' => 1, 'Position' => 1, 'CustomerTaxClassIds' => [1],
153-
'ProductTaxClassIds' => [1], 'TaxRateIds' => [1], 'CalculateSubtotal' => true,
154-
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRuleExtension']
239+
[
240+
'Id' => 1,
241+
'Code' => 'code',
242+
'Priority' => 1,
243+
'Position' => 1,
244+
'CustomerTaxClassIds' => [1],
245+
'ProductTaxClassIds' => [1],
246+
'TaxRateIds' => [1],
247+
'CalculateSubtotal' => true,
248+
'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRuleExtension'
249+
]
155250
]
156251
];
157252
}

app/code/Magento/Tax/Test/Unit/Model/Calculation/RowBaseAndTotalBaseCalculatorTestCase.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ class RowBaseAndTotalBaseCalculatorTestCase extends \PHPUnit_Framework_TestCase
6565
/**
6666
* initialize all mocks
6767
*
68-
* @param bool $taxIncluded
68+
* @param bool $isTaxIncluded
6969
*/
70-
public function initMocks($taxIncluded)
70+
public function initMocks($isTaxIncluded)
7171
{
72-
$this->initMockItem($taxIncluded);
72+
$this->initMockItem($isTaxIncluded);
7373
$this->initMockConfig();
7474
$this->initMockCalculationTool();
7575
$this->initMockAppliedTaxDataObjectFactory();
@@ -139,9 +139,9 @@ public function calculate($calculator)
139139
/**
140140
* init mock Items
141141
*
142-
* @param bool $taxIncluded
142+
* @param bool $isTaxIncluded
143143
*/
144-
protected function initMockItem($taxIncluded)
144+
protected function initMockItem($isTaxIncluded)
145145
{
146146
$this->mockReturnValues(
147147
$this->mockItem,
@@ -169,7 +169,7 @@ protected function initMockItem($taxIncluded)
169169
[
170170
self::ONCE => true,
171171
self::MOCK_METHOD_NAME => 'getIsTaxIncluded',
172-
self::MOCK_VALUE => $taxIncluded
172+
self::MOCK_VALUE => $isTaxIncluded
173173
]
174174
]
175175
);

app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public function dataProviderCollectArray()
352352
'quantity' => 1,
353353
'unit_price' => 100,
354354
'tax_class_key' => ["_data" => ["type" => "id", "value" => 2]],
355-
'tax_included = false',
355+
'is_tax_included = false',
356356
],
357357
],
358358
],

0 commit comments

Comments
 (0)