Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
TaxCalculationTest Class Reference
Inheritance diagram for TaxCalculationTest:

Public Member Functions

 testCalculateTaxUnitBased ($quoteDetailsData, $expected)
 
 calculateUnitBasedDataProvider ()
 
 testCalculateTaxTotalBased ($quoteDetailsData, $expectedTaxDetails, $storeId=null)
 
 calculateTaxTotalBasedDataProvider ()
 
 calculateTaxNoTaxInclDataProvider ()
 
 calculateTaxTaxInclDataProvider ()
 
 calculateTaxRoundingDataProvider ()
 
 testCalculateTaxRowBased ($quoteDetailsData, $expectedTaxDetails)
 
 calculateTaxRowBasedDataProvider ()
 
 testMultiRulesRowBased ($quoteDetailsData, $expectedTaxDetails)
 
 multiRulesRowBasedDataProvider ()
 
 testMultiRulesTotalBased ($quoteDetailsData, $expectedTaxDetails)
 
 multiRulesTotalBasedDataProvider ()
 
 testMultiRulesUnitBased ($quoteDetailsData, $expectedTaxDetails)
 
 multiRulesUnitBasedDataProvider ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 
 setupMultiRuleQuote ()
 
 getBaseQuoteResult ()
 

Detailed Description

@magentoDbIsolation enabled @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 16 of file TaxCalculationTest.php.

Member Function Documentation

◆ calculateTaxNoTaxInclDataProvider()

calculateTaxNoTaxInclDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 842 of file TaxCalculationTest.php.

843  {
844  $prodNoTaxInclBase = [
845  'quote_details' => [
846  'shipping_address' => [
847  'postcode' => '55555',
848  'country_id' => 'US',
849  'region' => ['region_id' => 42],
850  ],
851  'items' => [
852  [
853  'code' => 'code',
854  'type' => 'type',
855  'quantity' => 1,
856  'unit_price' => 10.0,
857  'is_tax_included' => false,
858  ],
859  ],
860  'customer_tax_class_key' => 'DefaultCustomerClass',
861  ],
862  'expected_tax_details' => [
863  'subtotal' => 10.0,
864  'tax_amount' => 0.0,
865  'discount_tax_compensation_amount' => 0.0,
866  'applied_taxes' => [],
867  'items' => [],
868  ],
869  'store_id' => null,
870  ];
871 
872  $prodQuoteDetailItemBase = [
873  'code' => 'code',
874  'type' => 'type',
875  'quantity' => 1,
876  'unit_price' => 10.0,
877  'is_tax_included' => false,
878  ];
879 
880  $quoteDetailAppliedTaxesBase = [
881  [
882  'amount' => 0.75,
883  'percent' => 7.5,
884  'rates' => [
885  [
886  'code' => 'US - 42 - 7.5',
887  'title' => 'US - 42 - 7.5',
888  'percent' => 7.5,
889  ],
890  ],
891  'tax_rate_key' => 'US - 42 - 7.5',
892  ],
893  ];
894 
895  $itemDetailAppliedTaxesBase = [
896  'US - 42 - 7.5' => [
897  'amount' => 0.75,
898  'percent' => 7.5,
899  'tax_rate_key' => 'US - 42 - 7.5',
900  'rates' => [
901  'US - 42 - 7.5' => [
902  'percent' => 7.5,
903  'code' => 'US - 42 - 7.5',
904  'title' => 'US - 42 - 7.5',
905  ],
906  ],
907  ],
908  ];
909 
910  $quoteDetailItemWithDefaultProductTaxClass = $prodQuoteDetailItemBase;
911  $quoteDetailItemWithDefaultProductTaxClass['tax_class_key'] = 'DefaultProductClass';
912 
913  $prodExpectedItemWithNoProductTaxClass = [
914  'code' => [
915  'code' => 'code',
916  'row_tax' => 0,
917  'price' => 10.0,
918  'price_incl_tax' => 10.0,
919  'row_total' => 10.0,
920  'row_total_incl_tax' => 10.0,
921  'type' => 'type',
922  'tax_percent' => 0,
923  'discount_tax_compensation_amount' => 0,
924  'associated_item_code' => null,
925  'applied_taxes' => [],
926  ],
927  ];
928 
929  $itemAppliedTaxes = $itemDetailAppliedTaxesBase;
930  $prodExpectedItemWithDefaultProductTaxClass = [
931  'code' => [
932  'code' => 'code',
933  'row_tax' => 0.75,
934  'price' => 10.0,
935  'price_incl_tax' => 10.75,
936  'row_total' => 10.0,
937  'row_total_incl_tax' => 10.75,
938  'type' => 'type',
939  'tax_percent' => 7.5,
940  'discount_tax_compensation_amount' => 0,
941  'associated_item_code' => null,
942  'applied_taxes' => $itemAppliedTaxes,
943  ],
944  ];
945 
946  $prodWithStoreIdWithTaxClassId = $prodNoTaxInclBase;
947  $prodWithStoreIdWithoutTaxClassId = $prodNoTaxInclBase;
948  $prodWithoutStoreIdWithTaxClassId = $prodNoTaxInclBase;
949  $prodWithoutStoreIdWithoutTaxClassId = $prodNoTaxInclBase;
950 
951  $prodWithStoreIdWithTaxClassId['store_id'] = 1;
952  $prodWithStoreIdWithTaxClassId['quote_details']['items'][] = $quoteDetailItemWithDefaultProductTaxClass;
953  $prodWithStoreIdWithTaxClassId['expected_tax_details']['tax_amount'] = 0.75;
954  $prodWithStoreIdWithTaxClassId['expected_tax_details']['applied_taxes'] = $quoteDetailAppliedTaxesBase;
955  $prodWithStoreIdWithTaxClassId['expected_tax_details']['items'] =
956  $prodExpectedItemWithDefaultProductTaxClass;
957 
958  $prodWithStoreIdWithoutTaxClassId['store_id'] = 1;
959  $prodWithStoreIdWithoutTaxClassId['quote_details']['items'][] = $prodQuoteDetailItemBase;
960  $prodWithStoreIdWithoutTaxClassId['expected_tax_details']['items'] =
961  $prodExpectedItemWithNoProductTaxClass;
962 
963  $prodWithoutStoreIdWithTaxClassId['quote_details']['items'][] =
964  $quoteDetailItemWithDefaultProductTaxClass;
965  $prodWithoutStoreIdWithTaxClassId['expected_tax_details']['tax_amount'] = 0.75;
966  $prodWithoutStoreIdWithTaxClassId['expected_tax_details']['applied_taxes'] = $quoteDetailAppliedTaxesBase;
967  $prodWithoutStoreIdWithTaxClassId['expected_tax_details']['items'] =
968  $prodExpectedItemWithDefaultProductTaxClass;
969 
970  $prodWithoutStoreIdWithoutTaxClassId['quote_details']['items'][] = $prodQuoteDetailItemBase;
971  $prodWithoutStoreIdWithoutTaxClassId['expected_tax_details']['items'] =
972  $prodExpectedItemWithNoProductTaxClass;
973 
974  return [
975  'product with store id, with tax class id' => $prodWithStoreIdWithTaxClassId,
976  'product with store id, without tax class id' => $prodWithStoreIdWithoutTaxClassId,
977  'product without store id, with tax class id' => $prodWithoutStoreIdWithTaxClassId,
978  'product without store id, without tax class id' => $prodWithoutStoreIdWithoutTaxClassId,
979  ];
980  }

◆ calculateTaxRoundingDataProvider()

calculateTaxRoundingDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 1134 of file TaxCalculationTest.php.

1135  {
1136  $prodRoundingNoTaxInclBase = [
1137  'quote_details' => [
1138  'shipping_address' => [
1139  'postcode' => '55555',
1140  'country_id' => 'US',
1141  'region' => ['region_id' => 42],
1142  ],
1143  'items' => [
1144  [
1145  'code' => 'code',
1146  'type' => 'type',
1147  'quantity' => 2,
1148  'unit_price' => 7.97,
1149  'is_tax_included' => false,
1150  ],
1151  ],
1152  'customer_tax_class_key' => 'DefaultCustomerClass',
1153  ],
1154  'expected_tax_details' => [
1155  'subtotal' => 15.94,
1156  'tax_amount' => 0.0,
1157  'discount_tax_compensation_amount' => 0.0,
1158  'applied_taxes' => [],
1159  'items' => [],
1160  ],
1161  'store_id' => null,
1162  ];
1163 
1164  $prodQuoteDetailItemBase = [
1165  'code' => 'code',
1166  'type' => 'type',
1167  'quantity' => 2,
1168  'unit_price' => 7.97,
1169  'is_tax_included' => false,
1170  ];
1171 
1172  $quoteDetailItemWithDefaultProductTaxClass = $prodQuoteDetailItemBase;
1173  $quoteDetailItemWithDefaultProductTaxClass['tax_class_key'] = 'DefaultProductClass';
1174 
1175  $quoteDetailAppliedTaxesBase = [
1176  [
1177  'amount' => 1.20,
1178  'percent' => 7.5,
1179  'rates' => [
1180  [
1181  'code' => 'US - 42 - 7.5',
1182  'title' => 'US - 42 - 7.5',
1183  'percent' => 7.5,
1184  ],
1185  ],
1186  'tax_rate_key' => 'US - 42 - 7.5',
1187  ],
1188  ];
1189 
1190  $prodExpectedItemWithNoProductTaxClass = [
1191  'code' => [
1192  'code' => 'code',
1193  'row_tax' => 0,
1194  'price' => 7.97,
1195  'price_incl_tax' => 7.97,
1196  'row_total' => 15.94,
1197  'row_total_incl_tax' => 15.94,
1198  'type' => 'type',
1199  'tax_percent' => 0,
1200  'discount_tax_compensation_amount' => 0,
1201  'associated_item_code' => null,
1202  'applied_taxes' => [],
1203  ],
1204  ];
1205 
1206  $prodExpectedItemWithDefaultProductTaxClass = [
1207  'code' => [
1208  'code' => 'code',
1209  'row_tax' => 1.20,
1210  'price' => 7.97,
1211  'price_incl_tax' => 8.57,
1212  'row_total' => 15.94,
1213  'row_total_incl_tax' => 17.14,
1214  'type' => 'type',
1215  'tax_percent' => 7.5,
1216  'discount_tax_compensation_amount' => 0,
1217  'associated_item_code' => null,
1218  'applied_taxes' => [
1219  'US - 42 - 7.5' => [
1220  'amount' => 1.2,
1221  'percent' => 7.5,
1222  'tax_rate_key' => 'US - 42 - 7.5',
1223  'rates' => [
1224  'US - 42 - 7.5' => [
1225  'percent' => 7.5,
1226  'code' => 'US - 42 - 7.5',
1227  'title' => 'US - 42 - 7.5',
1228  ],
1229  ],
1230  ],
1231  ],
1232  ],
1233  ];
1234 
1235  $prodWithStoreIdWithTaxClassId = $prodRoundingNoTaxInclBase;
1236  $prodWithStoreIdWithoutTaxClassId = $prodRoundingNoTaxInclBase;
1237  $prodWithoutStoreIdWithTaxClassId = $prodRoundingNoTaxInclBase;
1238  $prodWithoutStoreIdWithoutTaxClassId = $prodRoundingNoTaxInclBase;
1239 
1240  $prodWithStoreIdWithTaxClassId['store_id'] = 1;
1241  $prodWithStoreIdWithTaxClassId['quote_details']['items'][] = $quoteDetailItemWithDefaultProductTaxClass;
1242  $prodWithStoreIdWithTaxClassId['expected_tax_details']['tax_amount'] = 1.20;
1243  $prodWithStoreIdWithTaxClassId['expected_tax_details']['applied_taxes'] = $quoteDetailAppliedTaxesBase;
1244  $prodWithStoreIdWithTaxClassId['expected_tax_details']['items'] =
1245  $prodExpectedItemWithDefaultProductTaxClass;
1246 
1247  $prodWithStoreIdWithoutTaxClassId['store_id'] = 1;
1248  $prodWithStoreIdWithoutTaxClassId['quote_details']['items'][] = $prodQuoteDetailItemBase;
1249  $prodWithStoreIdWithoutTaxClassId['expected_tax_details']['items'] =
1250  $prodExpectedItemWithNoProductTaxClass;
1251 
1252  $prodWithoutStoreIdWithTaxClassId['quote_details']['items'][] =
1253  $quoteDetailItemWithDefaultProductTaxClass;
1254  $prodWithoutStoreIdWithTaxClassId['expected_tax_details']['tax_amount'] = 1.20;
1255  $prodWithoutStoreIdWithTaxClassId['expected_tax_details']['applied_taxes'] =
1256  $quoteDetailAppliedTaxesBase;
1257  $prodWithoutStoreIdWithTaxClassId['expected_tax_details']['items'] =
1258  $prodExpectedItemWithDefaultProductTaxClass;
1259 
1260  $prodWithoutStoreIdWithoutTaxClassId['quote_details']['items'][] = $prodQuoteDetailItemBase;
1261  $prodWithoutStoreIdWithoutTaxClassId['expected_tax_details']['items'] =
1262  $prodExpectedItemWithNoProductTaxClass;
1263 
1264  return [
1265  'rounding product with store id, with tax class id' => $prodWithStoreIdWithTaxClassId,
1266  'rounding product with store id, without tax class id' => $prodWithStoreIdWithoutTaxClassId,
1267  'rounding product without store id, with tax class id' => $prodWithoutStoreIdWithTaxClassId,
1268  'rounding product without store id, without tax class id' => $prodWithoutStoreIdWithoutTaxClassId,
1269  ];
1270  }

◆ calculateTaxRowBasedDataProvider()

calculateTaxRowBasedDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 1295 of file TaxCalculationTest.php.

1296  {
1297  $baseQuote = $this->getBaseQuoteData();
1298 
1299  $oneProduct = $baseQuote;
1300  $oneProduct['items'][] = [
1301  'code' => 'sku_1',
1302  'type' => 'product',
1303  'quantity' => 10,
1304  'unit_price' => 1,
1305  'tax_class_key' => 'DefaultProductClass',
1306  ];
1307  $oneProductResults = [
1308  'subtotal' => 10,
1309  'tax_amount' => 0.75,
1310  'discount_tax_compensation_amount' => 0,
1311  'applied_taxes' => [
1312  [
1313  'amount' => 0.75,
1314  'percent' => 7.5,
1315  'rates' => [
1316  [
1317  'code' => 'US - 42 - 7.5',
1318  'title' => 'US - 42 - 7.5',
1319  'percent' => 7.5,
1320  ],
1321  ],
1322  'tax_rate_key' => 'US - 42 - 7.5',
1323  ],
1324  ],
1325  'items' => [
1326  'sku_1' => [
1327  'code' => 'sku_1',
1328  'row_tax' => 0.75,
1329  'price' => 1,
1330  'price_incl_tax' => 1.08,
1331  'row_total' => 10,
1332  'row_total_incl_tax' => 10.75,
1333  'type' => 'product',
1334  'tax_percent' => 7.5,
1335  'discount_tax_compensation_amount' => 0,
1336  'associated_item_code' => null,
1337  'applied_taxes' => [
1338  'US - 42 - 7.5' => [
1339  'amount' => 0.75,
1340  'percent' => 7.5,
1341  'tax_rate_key' => 'US - 42 - 7.5',
1342  'rates' => [
1343  'US - 42 - 7.5' => [
1344  'percent' => 7.5,
1345  'code' => 'US - 42 - 7.5',
1346  'title' => 'US - 42 - 7.5',
1347  ],
1348  ],
1349  ],
1350  ],
1351  ],
1352  ],
1353  ];
1354 
1355  $weeeProduct = $baseQuote;
1356  $weeeProduct['items'][] = [
1357  'code' => 'sequence-1',
1358  'type' => 'product',
1359  'quantity' => 1,
1360  'unit_price' => 10,
1361  'tax_class_key' => 'WeeeProductClass',
1362  ];
1363  $weeeProduct['items'][] = [
1364  'code' => 'weee1-Recycling Fee',
1365  'type' => 'weee',
1366  'quantity' => 1,
1367  'unit_price' => 7,
1368  'tax_class_key' => 'WeeeProductClass',
1369  'associated_item_code' => 'sequence-1'
1370  ];
1371  $weeeProductResults = [
1372  'subtotal' => 17,
1373  'tax_amount' => 1.4,
1374  'discount_tax_compensation_amount' => 0,
1375  'applied_taxes' => [
1376  [
1377  'amount' => 1.4,
1378  'percent' => 8.25,
1379  'rates' => [
1380  [
1381  'code' => 'US - 42 - 8.25',
1382  'title' => 'US - 42 - 8.25',
1383  'percent' => 8.25,
1384  ],
1385  ],
1386  'tax_rate_key' => 'US - 42 - 8.25',
1387  ],
1388  ],
1389  'items' => [
1390  'sequence-1' => [
1391  'code' => 'sequence-1',
1392  'row_tax' => 0.83,
1393  'price' => 10,
1394  'price_incl_tax' => 10.83,
1395  'row_total' => 10,
1396  'row_total_incl_tax' => 10.83,
1397  'type' => 'product',
1398  'tax_percent' => 8.25,
1399  'discount_tax_compensation_amount' => 0,
1400  'associated_item_code' => null,
1401  'applied_taxes' => [
1402  'US - 42 - 8.25' => [
1403  'amount' => 0.83,
1404  'percent' => 8.25,
1405  'tax_rate_key' => 'US - 42 - 8.25',
1406  'rates' => [
1407  'US - 42 - 8.25' => [
1408  'percent' => 8.25,
1409  'code' => 'US - 42 - 8.25',
1410  'title' => 'US - 42 - 8.25',
1411  ],
1412  ],
1413  ],
1414  ],
1415  ],
1416  'weee1-Recycling Fee' => [
1417  'code' => 'weee1-Recycling Fee',
1418  'row_tax' => 0.57,
1419  'price' => 7,
1420  'price_incl_tax' => 7.57,
1421  'row_total' => 7,
1422  'row_total_incl_tax' => 7.57,
1423  'type' => 'weee',
1424  'tax_percent' => 8.25,
1425  'discount_tax_compensation_amount' => 0,
1426  'associated_item_code' => 'sequence-1',
1427  'applied_taxes' => [
1428  'US - 42 - 8.25' => [
1429  'amount' => 0.57,
1430  'percent' => 8.25,
1431  'tax_rate_key' => 'US - 42 - 8.25',
1432  'rates' => [
1433  'US - 42 - 8.25' => [
1434  'percent' => 8.25,
1435  'code' => 'US - 42 - 8.25',
1436  'title' => 'US - 42 - 8.25',
1437  ],
1438  ],
1439  ],
1440  ],
1441  ]
1442  ],
1443  ];
1444 
1445  $weeeProducts = $baseQuote;
1446  $weeeProducts['items'][] = [
1447  'code' => 'sequence-1',
1448  'type' => 'product',
1449  'quantity' => 2,
1450  'unit_price' => 10,
1451  'tax_class_key' => 'WeeeProductClass',
1452  ];
1453  $weeeProducts['items'][] = [
1454  'code' => 'weee1-Recycling Fee',
1455  'type' => 'weee',
1456  'quantity' => 2,
1457  'unit_price' => 7,
1458  'tax_class_key' => 'WeeeProductClass',
1459  'associated_item_code' => 'sequence-1'
1460  ];
1461  $weeeProductsResults = [
1462  'subtotal' => 34,
1463  'tax_amount' => 2.81,
1464  'discount_tax_compensation_amount' => 0,
1465  'applied_taxes' => [
1466  [
1467  'amount' => 2.81,
1468  'percent' => 8.25,
1469  'rates' => [
1470  [
1471  'code' => 'US - 42 - 8.25',
1472  'title' => 'US - 42 - 8.25',
1473  'percent' => 8.25,
1474  ],
1475  ],
1476  'tax_rate_key' => 'US - 42 - 8.25',
1477  ],
1478  ],
1479  'items' => [
1480  'sequence-1' => [
1481  'code' => 'sequence-1',
1482  'row_tax' => 1.65,
1483  'price' => 10,
1484  'price_incl_tax' => 10.83,
1485  'row_total' => 20,
1486  'row_total_incl_tax' => 21.65,
1487  'type' => 'product',
1488  'tax_percent' => 8.25,
1489  'discount_tax_compensation_amount' => 0,
1490  'associated_item_code' => null,
1491  'applied_taxes' => [
1492  'US - 42 - 8.25' => [
1493  'amount' => 1.65,
1494  'percent' => 8.25,
1495  'tax_rate_key' => 'US - 42 - 8.25',
1496  'rates' => [
1497  'US - 42 - 8.25' => [
1498  'percent' => 8.25,
1499  'code' => 'US - 42 - 8.25',
1500  'title' => 'US - 42 - 8.25',
1501  ],
1502  ],
1503  ],
1504  ],
1505  ],
1506  'weee1-Recycling Fee' => [
1507  'code' => 'weee1-Recycling Fee',
1508  'row_tax' => 1.16,
1509  'price' => 7,
1510  'price_incl_tax' => 7.58,
1511  'row_total' => 14,
1512  'row_total_incl_tax' => 15.16,
1513  'type' => 'weee',
1514  'tax_percent' => 8.25,
1515  'discount_tax_compensation_amount' => 0,
1516  'associated_item_code' => 'sequence-1',
1517  'applied_taxes' => [
1518  'US - 42 - 8.25' => [
1519  'amount' => 1.16,
1520  'percent' => 8.25,
1521  'tax_rate_key' => 'US - 42 - 8.25',
1522  'rates' => [
1523  'US - 42 - 8.25' => [
1524  'percent' => 8.25,
1525  'code' => 'US - 42 - 8.25',
1526  'title' => 'US - 42 - 8.25',
1527  ],
1528  ],
1529  ],
1530  ],
1531  ]
1532  ],
1533  ];
1534 
1535  $multiWeeeProducts = $baseQuote;
1536  $multiWeeeProducts['items'][] = [
1537  'code' => 'sequence-1',
1538  'type' => 'product',
1539  'quantity' => 2,
1540  'unit_price' => 10,
1541  'tax_class_key' => 'WeeeProductClass',
1542  ];
1543  $multiWeeeProducts['items'][] = [
1544  'code' => 'weee1-Recycling Fee',
1545  'type' => 'weee',
1546  'quantity' => 2,
1547  'unit_price' => 7,
1548  'tax_class_key' => 'WeeeProductClass',
1549  'associated_item_code' => 'sequence-1'
1550  ];
1551  $multiWeeeProducts['items'][] = [
1552  'code' => 'sequence-2',
1553  'type' => 'product',
1554  'quantity' => 2,
1555  'unit_price' => 10,
1556  'tax_class_key' => 'WeeeProductClass',
1557  ];
1558  $multiWeeeProducts['items'][] = [
1559  'code' => 'weee2-Recycling Fee',
1560  'type' => 'weee',
1561  'quantity' => 2,
1562  'unit_price' => 7,
1563  'tax_class_key' => 'WeeeProductClass',
1564  'associated_item_code' => 'sequence-2'
1565  ];
1566  $multiWeeeProductsResults = [
1567  'subtotal' => 68,
1568  'tax_amount' => 5.62,
1569  'discount_tax_compensation_amount' => 0,
1570  'applied_taxes' => [
1571  [
1572  'amount' => 5.62,
1573  'percent' => 8.25,
1574  'rates' => [
1575  [
1576  'code' => 'US - 42 - 8.25',
1577  'title' => 'US - 42 - 8.25',
1578  'percent' => 8.25,
1579  ],
1580  ],
1581  'tax_rate_key' => 'US - 42 - 8.25',
1582  ],
1583  ],
1584  'items' => [
1585  'sequence-1' => [
1586  'code' => 'sequence-1',
1587  'row_tax' => 1.65,
1588  'price' => 10,
1589  'price_incl_tax' => 10.83,
1590  'row_total' => 20,
1591  'row_total_incl_tax' => 21.65,
1592  'type' => 'product',
1593  'tax_percent' => 8.25,
1594  'discount_tax_compensation_amount' => 0,
1595  'associated_item_code' => null,
1596  'applied_taxes' => [
1597  'US - 42 - 8.25' => [
1598  'amount' => 1.65,
1599  'percent' => 8.25,
1600  'tax_rate_key' => 'US - 42 - 8.25',
1601  'rates' => [
1602  'US - 42 - 8.25' => [
1603  'percent' => 8.25,
1604  'code' => 'US - 42 - 8.25',
1605  'title' => 'US - 42 - 8.25',
1606  ],
1607  ],
1608  ],
1609  ],
1610  ],
1611  'weee1-Recycling Fee' => [
1612  'code' => 'weee1-Recycling Fee',
1613  'row_tax' => 1.16,
1614  'price' => 7,
1615  'price_incl_tax' => 7.58,
1616  'row_total' => 14,
1617  'row_total_incl_tax' => 15.16,
1618  'type' => 'weee',
1619  'tax_percent' => 8.25,
1620  'discount_tax_compensation_amount' => 0,
1621  'associated_item_code' => 'sequence-1',
1622  'applied_taxes' => [
1623  'US - 42 - 8.25' => [
1624  'amount' => 1.16,
1625  'percent' => 8.25,
1626  'tax_rate_key' => 'US - 42 - 8.25',
1627  'rates' => [
1628  'US - 42 - 8.25' => [
1629  'percent' => 8.25,
1630  'code' => 'US - 42 - 8.25',
1631  'title' => 'US - 42 - 8.25',
1632  ],
1633  ],
1634  ],
1635  ],
1636  ],
1637  'sequence-2' => [
1638  'code' => 'sequence-2',
1639  'row_tax' => 1.65,
1640  'price' => 10,
1641  'price_incl_tax' => 10.83,
1642  'row_total' => 20,
1643  'row_total_incl_tax' => 21.65,
1644  'type' => 'product',
1645  'tax_percent' => 8.25,
1646  'discount_tax_compensation_amount' => 0,
1647  'associated_item_code' => null,
1648  'applied_taxes' => [
1649  'US - 42 - 8.25' => [
1650  'amount' => 1.65,
1651  'percent' => 8.25,
1652  'tax_rate_key' => 'US - 42 - 8.25',
1653  'rates' => [
1654  'US - 42 - 8.25' => [
1655  'percent' => 8.25,
1656  'code' => 'US - 42 - 8.25',
1657  'title' => 'US - 42 - 8.25',
1658  ],
1659  ],
1660  ],
1661  ],
1662  ],
1663  'weee2-Recycling Fee' => [
1664  'code' => 'weee2-Recycling Fee',
1665  'row_tax' => 1.16,
1666  'price' => 7,
1667  'price_incl_tax' => 7.58,
1668  'row_total' => 14,
1669  'row_total_incl_tax' => 15.16,
1670  'type' => 'weee',
1671  'tax_percent' => 8.25,
1672  'discount_tax_compensation_amount' => 0,
1673  'associated_item_code' => 'sequence-2',
1674  'applied_taxes' => [
1675  'US - 42 - 8.25' => [
1676  'amount' => 1.16,
1677  'percent' => 8.25,
1678  'tax_rate_key' => 'US - 42 - 8.25',
1679  'rates' => [
1680  'US - 42 - 8.25' => [
1681  'percent' => 8.25,
1682  'code' => 'US - 42 - 8.25',
1683  'title' => 'US - 42 - 8.25',
1684  ],
1685  ],
1686  ],
1687  ],
1688  ]
1689  ],
1690  ];
1691 
1692  $oneProductInclTax = $baseQuote;
1693  $oneProductInclTax['items'][] = [
1694  'code' => 'sku_1',
1695  'type' => 'product',
1696  'quantity' => 10,
1697  'unit_price' => 1.0,
1698  'tax_class_key' => 'DefaultProductClass',
1699  'is_tax_included' => true,
1700  ];
1701  $oneProductInclTaxResults = [
1702  'subtotal' => 9.3,
1703  'tax_amount' => 0.7,
1704  'discount_tax_compensation_amount' => 0,
1705  'applied_taxes' => [
1706  [
1707  'amount' => 0.7,
1708  'percent' => 7.5,
1709  'tax_rate_key' => 'US - 42 - 7.5',
1710  'rates' => [
1711  [
1712  'percent' => 7.5,
1713  'code' => 'US - 42 - 7.5',
1714  'title' => 'US - 42 - 7.5',
1715  ],
1716  ],
1717  ],
1718  ],
1719  'items' => [
1720  'sku_1' => [
1721  'code' => 'sku_1',
1722  'row_tax' => .7,
1723  'price' => 0.93,
1724  'price_incl_tax' => 1.0,
1725  'row_total' => 9.3,
1726  'row_total_incl_tax' => 10,
1727  'type' => 'product',
1728  'tax_percent' => 7.5,
1729  'discount_tax_compensation_amount' => 0,
1730  'associated_item_code' => null,
1731  'applied_taxes' => [
1732  'US - 42 - 7.5' => [
1733  'amount' => 0.7,
1734  'percent' => 7.5,
1735  'tax_rate_key' => 'US - 42 - 7.5',
1736  'rates' => [
1737  'US - 42 - 7.5' => [
1738  'percent' => 7.5,
1739  'code' => 'US - 42 - 7.5',
1740  'title' => 'US - 42 - 7.5',
1741  ],
1742  ],
1743  ],
1744  ],
1745  ],
1746  ],
1747  ];
1748 
1749  $oneProductInclTaxDiffRate = $baseQuote;
1750  $oneProductInclTaxDiffRate['items'][] = [
1751  'code' => 'sku_1',
1752  'type' => 'product',
1753  'quantity' => 9,
1754  'unit_price' => 0.33, // this is including the store tax of 10%. Pre tax is 0.3
1755  'tax_class_key' => [
1757  Key::KEY_VALUE => 'HigherProductClass',
1758  ],
1759  'is_tax_included' => true,
1760  ];
1761  $oneProductInclTaxDiffRateResults = [
1762  'subtotal' => 2.73,
1763  'tax_amount' => 0.6,
1764  'discount_tax_compensation_amount' => 0,
1765  'applied_taxes' => [
1766  [
1767  'amount' => 0.6,
1768  'percent' => 22,
1769  'rates' => [
1770  [
1771  'percent' => 22,
1772  'code' => 'US - 42 - 22',
1773  'title' => 'US - 42 - 22',
1774  ],
1775  ],
1776  'tax_rate_key' => 'US - 42 - 22',
1777  ],
1778  ],
1779  'items' => [
1780  'sku_1' => [
1781  'code' => 'sku_1',
1782  'row_tax' => 0.6,
1783  'price' => 0.3,
1784  'price_incl_tax' => 0.37,
1785  'row_total' => 2.73,
1786  'row_total_incl_tax' => 3.33,
1787  'type' => 'product',
1788  'tax_percent' => 22.0,
1789  'discount_tax_compensation_amount' => 0,
1790  'associated_item_code' => null,
1791  'applied_taxes' => [
1792  'US - 42 - 22' => [
1793  'amount' => 0.6,
1794  'percent' => 22,
1795  'tax_rate_key' => 'US - 42 - 22',
1796  'rates' => [
1797  'US - 42 - 22' => [
1798  'percent' => 22,
1799  'code' => 'US - 42 - 22',
1800  'title' => 'US - 42 - 22',
1801  ],
1802  ],
1803  ],
1804  ],
1805  ],
1806  ],
1807  ];
1808 
1809  $twoProducts = $baseQuote;
1810  $twoProducts['items'] = [
1811  [
1812  'code' => 'sku_1',
1813  'type' => 'product',
1814  'quantity' => 10,
1815  'unit_price' => 1,
1816  'tax_class_key' => 'DefaultProductClass',
1817  ],
1818  [
1819  'code' => 'sku_2',
1820  'type' => 'product',
1821  'quantity' => 20,
1822  'unit_price' => 11,
1823  'tax_class_key' => 'DefaultProductClass',
1824  ],
1825  ];
1826  $twoProductsResults = [
1827  'subtotal' => 230,
1828  'tax_amount' => 17.25,
1829  'discount_tax_compensation_amount' => 0,
1830  'applied_taxes' => [
1831  [
1832  'amount' => 17.25,
1833  'percent' => 7.5,
1834  'tax_rate_key' => 'US - 42 - 7.5',
1835  'rates' => [
1836  [
1837  'percent' => 7.5,
1838  'code' => 'US - 42 - 7.5',
1839  'title' => 'US - 42 - 7.5',
1840  ],
1841  ],
1842  ],
1843  ],
1844  'items' => [
1845  'sku_1' => [
1846  'code' => 'sku_1',
1847  'row_tax' => .75,
1848  'price' => 1,
1849  'price_incl_tax' => 1.08,
1850  'row_total' => 10,
1851  'row_total_incl_tax' => 10.75,
1852  'type' => 'product',
1853  'tax_percent' => 7.5,
1854  'discount_tax_compensation_amount' => 0,
1855  'associated_item_code' => null,
1856  'applied_taxes' => [
1857  'US - 42 - 7.5' => [
1858  'amount' => 0.75,
1859  'percent' => 7.5,
1860  'tax_rate_key' => 'US - 42 - 7.5',
1861  'rates' => [
1862  'US - 42 - 7.5' => [
1863  'percent' => 7.5,
1864  'code' => 'US - 42 - 7.5',
1865  'title' => 'US - 42 - 7.5',
1866  ],
1867  ],
1868  ],
1869  ],
1870  ],
1871  'sku_2' => [
1872  'code' => 'sku_2',
1873  'row_tax' => 16.5,
1874  'price' => 11,
1875  'price_incl_tax' => 11.83,
1876  'row_total' => 220,
1877  'row_total_incl_tax' => 236.5,
1878  'type' => 'product',
1879  'tax_percent' => 7.5,
1880  'discount_tax_compensation_amount' => 0,
1881  'associated_item_code' => null,
1882  'applied_taxes' => [
1883  'US - 42 - 7.5' => [
1884  'amount' => 16.5,
1885  'percent' => 7.5,
1886  'tax_rate_key' => 'US - 42 - 7.5',
1887  'rates' => [
1888  'US - 42 - 7.5' => [
1889  'percent' => 7.5,
1890  'code' => 'US - 42 - 7.5',
1891  'title' => 'US - 42 - 7.5',
1892  ],
1893  ],
1894  ],
1895  ],
1896  ],
1897  ],
1898  ];
1899 
1900  $twoProductsInclTax = $baseQuote;
1901  $twoProductsInclTax['items'] = [
1902  [
1903  'code' => 'sku_1',
1904  'type' => 'product',
1905  'quantity' => 10,
1906  'unit_price' => 0.98,
1907  'tax_class_key' => 'DefaultProductClass',
1908  'is_tax_included' => true,
1909  ],
1910  [
1911  'code' => 'sku_2',
1912  'type' => 'product',
1913  'quantity' => 20,
1914  'unit_price' => 11.99,
1915  'tax_class_key' => 'DefaultProductClass',
1916  'is_tax_included' => true,
1917  ],
1918  ];
1919  $twoProductInclTaxResults = [
1920  'subtotal' => 232.19,
1921  'tax_amount' => 17.41,
1922  'discount_tax_compensation_amount' => 0,
1923  'applied_taxes' => [
1924  [
1925  'amount' => 17.41,
1926  'percent' => 7.5,
1927  'tax_rate_key' => 'US - 42 - 7.5',
1928  'rates' => [
1929  [
1930  'percent' => 7.5,
1931  'code' => 'US - 42 - 7.5',
1932  'title' => 'US - 42 - 7.5',
1933  ],
1934  ],
1935  ],
1936  ],
1937  'items' => [
1938  'sku_1' => [
1939  'code' => 'sku_1',
1940  'row_tax' => .68,
1941  'price' => 0.91,
1942  'price_incl_tax' => 0.98,
1943  'row_total' => 9.12,
1944  'row_total_incl_tax' => 9.8,
1945  'type' => 'product',
1946  'tax_percent' => 7.5,
1947  'discount_tax_compensation_amount' => 0,
1948  'associated_item_code' => null,
1949  'applied_taxes' => [
1950  'US - 42 - 7.5' => [
1951  'amount' => 0.68,
1952  'percent' => 7.5,
1953  'tax_rate_key' => 'US - 42 - 7.5',
1954  'rates' => [
1955  'US - 42 - 7.5' => [
1956  'percent' => 7.5,
1957  'code' => 'US - 42 - 7.5',
1958  'title' => 'US - 42 - 7.5',
1959  ],
1960  ],
1961  ],
1962  ],
1963  ],
1964  'sku_2' => [
1965  'code' => 'sku_2',
1966  'row_tax' => 16.73,
1967  'price' => 11.15,
1968  'price_incl_tax' => 11.99,
1969  'row_total' => 223.07,
1970  'row_total_incl_tax' => 239.8, // Shouldn't this be 223.07?
1971  'type' => 'product',
1972  'tax_percent' => 7.5,
1973  'discount_tax_compensation_amount' => 0,
1974  'associated_item_code' => null,
1975  'applied_taxes' => [
1976  'US - 42 - 7.5' => [
1977  'amount' => 16.73,
1978  'percent' => 7.5,
1979  'tax_rate_key' => 'US - 42 - 7.5',
1980  'rates' => [
1981  'US - 42 - 7.5' => [
1982  'percent' => 7.5,
1983  'code' => 'US - 42 - 7.5',
1984  'title' => 'US - 42 - 7.5',
1985  ],
1986  ],
1987  ],
1988  ],
1989  ],
1990  ],
1991  ];
1992 
1993  $oneProductWithChildren = $baseQuote;
1994  $oneProductWithChildren['items'] = [
1995  [
1996  'code' => 'child_1_sku',
1997  'type' => 'product',
1998  'quantity' => 2,
1999  'unit_price' => 12.34,
2000  'tax_class_key' => 'DefaultProductClass',
2001  'parent_code' => 'parent_sku',
2002  ],
2003  [
2004  'code' => 'parent_sku', // Put the parent in the middle of the children to test an edge case
2005  'type' => 'product',
2006  'quantity' => 10,
2007  'unit_price' => 0,
2008  'tax_class_key' => 'DefaultProductClass',
2009  ],
2010  [
2011  'code' => 'child_2_sku',
2012  'type' => 'product',
2013  'quantity' => 2,
2014  'unit_price' => 1.99,
2015  'tax_class_key' => 'HigherProductClass',
2016  'parent_code' => 'parent_sku',
2017  ],
2018  ];
2019  $oneProductWithChildrenResults = [
2020  'subtotal' => 286.6,
2021  'tax_amount' => 27.27,
2022  'discount_tax_compensation_amount' => 0,
2023  'applied_taxes' => [
2024  [
2025  'amount' => 18.51,
2026  'percent' => 7.5,
2027  'rates' => [
2028  [
2029  'code' => 'US - 42 - 7.5',
2030  'title' => 'US - 42 - 7.5',
2031  'percent' => 7.5,
2032  ],
2033  ],
2034  'tax_rate_key' => 'US - 42 - 7.5',
2035  ],
2036  [
2037  'amount' => 8.76,
2038  'percent' => 22,
2039  'rates' => [
2040  [
2041  'code' => 'US - 42 - 22',
2042  'title' => 'US - 42 - 22',
2043  'percent' => 22,
2044  ],
2045  ],
2046  'tax_rate_key' => 'US - 42 - 22',
2047  ],
2048  ],
2049  'items' => [
2050  'child_1_sku' => [
2051  'code' => 'child_1_sku',
2052  'row_tax' => 18.51,
2053  'price' => 12.34,
2054  'price_incl_tax' => 13.27,
2055  'row_total' => 246.8,
2056  'row_total_incl_tax' => 265.31,
2057  'type' => 'product',
2058  'tax_percent' => 7.5,
2059  'discount_tax_compensation_amount' => 0,
2060  'associated_item_code' => null,
2061  'applied_taxes' => [
2062  'US - 42 - 7.5' => [
2063  'amount' => 18.51,
2064  'percent' => 7.5,
2065  'tax_rate_key' => 'US - 42 - 7.5',
2066  'rates' => [
2067  'US - 42 - 7.5' => [
2068  'percent' => 7.5,
2069  'code' => 'US - 42 - 7.5',
2070  'title' => 'US - 42 - 7.5',
2071  ],
2072  ],
2073  ],
2074  ],
2075  ],
2076  'child_2_sku' => [
2077  'code' => 'child_2_sku',
2078  'row_tax' => 8.76,
2079  'price' => 1.99,
2080  'price_incl_tax' => 2.43,
2081  'row_total' => 39.8,
2082  'row_total_incl_tax' => 48.56,
2083  'type' => 'product',
2084  'tax_percent' => 22,
2085  'discount_tax_compensation_amount' => 0,
2086  'associated_item_code' => null,
2087  'applied_taxes' => [
2088  'US - 42 - 22' => [
2089  'amount' => 8.76,
2090  'percent' => 22,
2091  'tax_rate_key' => 'US - 42 - 22',
2092  'rates' => [
2093  'US - 42 - 22' => [
2094  'percent' => 22,
2095  'code' => 'US - 42 - 22',
2096  'title' => 'US - 42 - 22',
2097  ],
2098  ],
2099  ],
2100  ],
2101  ],
2102  'parent_sku' => [
2103  'price' => 28.66,
2104  'price_incl_tax' => 31.39,
2105  'row_total' => 286.6,
2106  'row_total_incl_tax' => 313.87,
2107  'row_tax' => 27.27,
2108  'code' => 'parent_sku',
2109  'type' => 'product',
2110  ],
2111  ],
2112  ];
2113 
2114  return [
2115  'one product' => [
2116  'quote_details' => $oneProduct,
2117  'expected_tax_details' => $oneProductResults,
2118  ],
2119  'weee_product' => [
2120  'quote_details' => $weeeProduct,
2121  'expected_tax_details' => $weeeProductResults,
2122  ],
2123  'weee_products' => [
2124  'quote_details' => $weeeProducts,
2125  'expected_tax_details' => $weeeProductsResults,
2126  ],
2127  'multi weee_products' => [
2128  'quote_details' => $multiWeeeProducts,
2129  'expected_tax_details' => $multiWeeeProductsResults,
2130  ],
2131  'one product, tax included' => [
2132  'quote_details' => $oneProductInclTax,
2133  'expected_tax_details' => $oneProductInclTaxResults,
2134  ],
2135  'one product, tax included but differs from store rate' => [
2136  'quote_details' => $oneProductInclTaxDiffRate,
2137  'expected_tax_details' => $oneProductInclTaxDiffRateResults,
2138  ],
2139  'two products' => [
2140  'quote_details' => $twoProducts,
2141  'expected_tax_details' => $twoProductsResults,
2142  ],
2143  'two products, tax included' => [
2144  'quote_details' => $twoProductsInclTax,
2145  'expected_tax_details' => $twoProductInclTaxResults,
2146  ],
2147  'one product with two children' => [
2148  'quote_details' => $oneProductWithChildren,
2149  'expected_tax_details' => $oneProductWithChildrenResults,
2150  ],
2151  ];
2152  }

◆ calculateTaxTaxInclDataProvider()

calculateTaxTaxInclDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 985 of file TaxCalculationTest.php.

986  {
987  $productTaxInclBase = [
988  'quote_details' => [
989  'shipping_address' => [
990  'postcode' => '55555',
991  'country_id' => 'US',
992  'region' => ['region_id' => 42],
993  ],
994  'items' => [
995  [
996  'code' => 'code',
997  'type' => 'type',
998  'quantity' => 1,
999  'unit_price' => 10.0,
1000  'is_tax_included' => true,
1001  ],
1002  ],
1003  'customer_tax_class_key' => [
1005  Key::KEY_VALUE => 'DefaultCustomerClass',
1006  ],
1007  ],
1008  'expected_tax_details' => [
1009  'subtotal' => 10.0,
1010  'tax_amount' => 0.0,
1011  'discount_tax_compensation_amount' => 0.0,
1012  'applied_taxes' => [],
1013  'items' => [],
1014  ],
1015  'store_id' => null,
1016  ];
1017 
1018  $productTaxInclQuoteDetailItemBase = [
1019  'code' => 'code',
1020  'type' => 'type',
1021  'quantity' => 1,
1022  'unit_price' => 10.0,
1023  'is_tax_included' => true,
1024  ];
1025 
1026  $quoteDetailTaxInclItemWithDefaultProductTaxClass = $productTaxInclQuoteDetailItemBase;
1027  $quoteDetailTaxInclItemWithDefaultProductTaxClass['tax_class_key'] = 'DefaultProductClass';
1028 
1029  $productTaxInclExpectedItemWithNoProductTaxClass = [
1030  'code' => [
1031  'code' => 'code',
1032  'row_tax' => 0,
1033  'price' => 10.0,
1034  'price_incl_tax' => 10.0,
1035  'row_total' => 10.0,
1036  'row_total_incl_tax' => 10.0,
1037  'type' => 'type',
1038  'tax_percent' => 0,
1039  'discount_tax_compensation_amount' => 0,
1040  'associated_item_code' => null,
1041  'applied_taxes' => [],
1042  ],
1043  ];
1044 
1045  $quoteDetailAppliedTaxesBase = [
1046  [
1047  'amount' => 0.70,
1048  'percent' => 7.5,
1049  'rates' => [
1050  [
1051  'code' => 'US - 42 - 7.5',
1052  'title' => 'US - 42 - 7.5',
1053  'percent' => 7.5,
1054  ],
1055  ],
1056  'tax_rate_key' => 'US - 42 - 7.5',
1057  ],
1058  ];
1059 
1060  $productTaxInclExpectedItemWithDefaultProductTaxClass = [
1061  'code' => [
1062  'code' => 'code',
1063  'row_tax' => 0.70,
1064  'price' => 9.30,
1065  'price_incl_tax' => 10.00,
1066  'row_total' => 9.30,
1067  'row_total_incl_tax' => 10.00,
1068  'type' => 'type',
1069  'tax_percent' => 7.5,
1070  'discount_tax_compensation_amount' => 0,
1071  'associated_item_code' => null,
1072  'applied_taxes' => [
1073  'US - 42 - 7.5' => [
1074  'amount' => 0.7,
1075  'percent' => 7.5,
1076  'tax_rate_key' => 'US - 42 - 7.5',
1077  'rates' => [
1078  'US - 42 - 7.5' => [
1079  'percent' => 7.5,
1080  'code' => 'US - 42 - 7.5',
1081  'title' => 'US - 42 - 7.5',
1082  ],
1083  ],
1084  ],
1085  ],
1086  ],
1087  ];
1088 
1089  $productInclTaxWithStoreIdWithTaxClassId = $productTaxInclBase;
1090  $productInclTaxWithStoreIdWithoutTaxClassId = $productTaxInclBase;
1091  $productInclTaxWithoutStoreIdWithTaxClassId = $productTaxInclBase;
1092  $productInclTaxWithoutStoreIdWithoutTaxClassId = $productTaxInclBase;
1093 
1094  $productInclTaxWithStoreIdWithTaxClassId['store_id'] = 1;
1095  $productInclTaxWithStoreIdWithTaxClassId['quote_details']['items'][] =
1096  $quoteDetailTaxInclItemWithDefaultProductTaxClass;
1097  $productInclTaxWithStoreIdWithTaxClassId['expected_tax_details']['tax_amount'] = 0.70;
1098  $productInclTaxWithStoreIdWithTaxClassId['expected_tax_details']['subtotal'] = 9.30;
1099  $productInclTaxWithStoreIdWithTaxClassId['expected_tax_details']['applied_taxes'] =
1100  $quoteDetailAppliedTaxesBase;
1101  $productInclTaxWithStoreIdWithTaxClassId['expected_tax_details']['items'] =
1102  $productTaxInclExpectedItemWithDefaultProductTaxClass;
1103 
1104  $productInclTaxWithStoreIdWithoutTaxClassId['store_id'] = 1;
1105  $productInclTaxWithStoreIdWithoutTaxClassId['quote_details']['items'][] =
1106  $productTaxInclQuoteDetailItemBase;
1107  $productInclTaxWithStoreIdWithoutTaxClassId['expected_tax_details']['items'] =
1108  $productTaxInclExpectedItemWithNoProductTaxClass;
1109 
1110  $productInclTaxWithoutStoreIdWithTaxClassId['quote_details']['items'][] =
1111  $quoteDetailTaxInclItemWithDefaultProductTaxClass;
1112  $productInclTaxWithoutStoreIdWithTaxClassId['expected_tax_details']['tax_amount'] = 0.70;
1113  $productInclTaxWithoutStoreIdWithTaxClassId['expected_tax_details']['subtotal'] = 9.30;
1114  $productInclTaxWithoutStoreIdWithTaxClassId['expected_tax_details']['applied_taxes'] =
1115  $quoteDetailAppliedTaxesBase;
1116  $productInclTaxWithoutStoreIdWithTaxClassId['expected_tax_details']['items'] =
1117  $productTaxInclExpectedItemWithDefaultProductTaxClass;
1118 
1119  $productInclTaxWithoutStoreIdWithoutTaxClassId['quote_details']['items'][] = $productTaxInclQuoteDetailItemBase;
1120  $productInclTaxWithoutStoreIdWithoutTaxClassId['expected_tax_details']['items'] =
1121  $productTaxInclExpectedItemWithNoProductTaxClass;
1122 
1123  return [
1124  'product incl tax with store id, with tax class id' => $productInclTaxWithStoreIdWithTaxClassId,
1125  'product incl tax with store id, without tax class id' => $productInclTaxWithStoreIdWithoutTaxClassId,
1126  'product incl tax without store id, with tax class id' => $productInclTaxWithoutStoreIdWithTaxClassId,
1127  'product incl tax without store id, without tax class id' => $productInclTaxWithoutStoreIdWithoutTaxClassId,
1128  ];
1129  }

◆ calculateTaxTotalBasedDataProvider()

calculateTaxTotalBasedDataProvider ( )

Definition at line 830 of file TaxCalculationTest.php.

◆ calculateUnitBasedDataProvider()

calculateUnitBasedDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 117 of file TaxCalculationTest.php.

118  {
119  $baseQuote = $this->getBaseQuoteData();
120  $oneProduct = $baseQuote;
121  $oneProduct['items'][] = [
122  'code' => 'sku_1',
123  'type' => 'product',
124  'quantity' => 2,
125  'unit_price' => 10,
126  'tax_class_key' => [
128  Key::KEY_VALUE => 'DefaultProductClass',
129  ],
130  ];
131  $oneProductResults = [
132  'subtotal' => 20,
133  'tax_amount' => 1.5,
134  'discount_tax_compensation_amount' => 0,
135  'applied_taxes' => [
136  [
137  'amount' => 1.5,
138  'percent' => 7.5,
139  'rates' => [
140  [
141  'code' => 'US - 42 - 7.5',
142  'title' => 'US - 42 - 7.5',
143  'percent' => 7.5,
144  ],
145  ],
146  'tax_rate_key' => 'US - 42 - 7.5',
147  ],
148  ],
149  'items' => [
150  'sku_1' => [
151  'code' => 'sku_1',
152  'row_tax' => 1.5,
153  'price' => 10,
154  'price_incl_tax' => 10.75,
155  'row_total' => 20,
156  'row_total_incl_tax' => 21.5,
157  'type' => 'product',
158  'tax_percent' => 7.5,
159  'discount_tax_compensation_amount' => 0,
160  'associated_item_code' => null,
161  'applied_taxes' => [
162  'US - 42 - 7.5' => [
163  'amount' => 1.5,
164  'percent' => 7.5,
165  'tax_rate_key' => 'US - 42 - 7.5',
166  'rates' => [
167  'US - 42 - 7.5' => [
168  'percent' => 7.5,
169  'code' => 'US - 42 - 7.5',
170  'title' => 'US - 42 - 7.5',
171  ],
172  ],
173  ],
174  ],
175  ],
176  ],
177  ];
178 
179  $weeeProduct = $baseQuote;
180  $weeeProduct['items'][] = [
181  'code' => 'sequence-1',
182  'type' => 'product',
183  'quantity' => 1,
184  'unit_price' => 10,
185  'tax_class_key' => 'WeeeProductClass',
186  ];
187  $weeeProduct['items'][] = [
188  'code' => 'weee1-Recycling Fee',
189  'type' => 'weee',
190  'quantity' => 1,
191  'unit_price' => 7,
192  'tax_class_key' => 'WeeeProductClass',
193  'associated_item_code' => 'sequence-1'
194  ];
195  $weeeProductResults = [
196  'subtotal' => 17,
197  'tax_amount' => 1.4,
198  'discount_tax_compensation_amount' => 0,
199  'applied_taxes' => [
200  [
201  'amount' => 1.4,
202  'percent' => 8.25,
203  'rates' => [
204  [
205  'code' => 'US - 42 - 8.25',
206  'title' => 'US - 42 - 8.25',
207  'percent' => 8.25,
208  ],
209  ],
210  'tax_rate_key' => 'US - 42 - 8.25',
211  ],
212  ],
213  'items' => [
214  'sequence-1' => [
215  'code' => 'sequence-1',
216  'row_tax' => 0.83,
217  'price' => 10,
218  'price_incl_tax' => 10.83,
219  'row_total' => 10,
220  'row_total_incl_tax' => 10.83,
221  'type' => 'product',
222  'tax_percent' => 8.25,
223  'discount_tax_compensation_amount' => 0,
224  'associated_item_code' => null,
225  'applied_taxes' => [
226  'US - 42 - 8.25' => [
227  'amount' => 0.83,
228  'percent' => 8.25,
229  'tax_rate_key' => 'US - 42 - 8.25',
230  'rates' => [
231  'US - 42 - 8.25' => [
232  'percent' => 8.25,
233  'code' => 'US - 42 - 8.25',
234  'title' => 'US - 42 - 8.25',
235  ],
236  ],
237  ],
238  ],
239  ],
240  'weee1-Recycling Fee' => [
241  'code' => 'weee1-Recycling Fee',
242  'row_tax' => 0.57,
243  'price' => 7,
244  'price_incl_tax' => 7.57,
245  'row_total' => 7,
246  'row_total_incl_tax' => 7.57,
247  'type' => 'weee',
248  'tax_percent' => 8.25,
249  'discount_tax_compensation_amount' => 0,
250  'associated_item_code' => 'sequence-1',
251  'applied_taxes' => [
252  'US - 42 - 8.25' => [
253  'amount' => 0.57,
254  'percent' => 8.25,
255  'tax_rate_key' => 'US - 42 - 8.25',
256  'rates' => [
257  'US - 42 - 8.25' => [
258  'percent' => 8.25,
259  'code' => 'US - 42 - 8.25',
260  'title' => 'US - 42 - 8.25',
261  ],
262  ],
263  ],
264  ],
265  ]
266  ],
267  ];
268 
269  $weeeProducts = $baseQuote;
270  $weeeProducts['items'][] = [
271  'code' => 'sequence-1',
272  'type' => 'product',
273  'quantity' => 2,
274  'unit_price' => 10,
275  'tax_class_key' => 'WeeeProductClass',
276  ];
277  $weeeProducts['items'][] = [
278  'code' => 'weee1-Recycling Fee',
279  'type' => 'weee',
280  'quantity' => 2,
281  'unit_price' => 7,
282  'tax_class_key' => 'WeeeProductClass',
283  'associated_item_code' => 'sequence-1'
284  ];
285  $weeeProductsResults = [
286  'subtotal' => 34,
287  'tax_amount' => 2.80,
288  'discount_tax_compensation_amount' => 0,
289  'applied_taxes' => [
290  [
291  'amount' => 2.80,
292  'percent' => 8.25,
293  'rates' => [
294  [
295  'code' => 'US - 42 - 8.25',
296  'title' => 'US - 42 - 8.25',
297  'percent' => 8.25,
298  ],
299  ],
300  'tax_rate_key' => 'US - 42 - 8.25',
301  ],
302  ],
303  'items' => [
304  'sequence-1' => [
305  'code' => 'sequence-1',
306  'row_tax' => 1.66,
307  'price' => 10,
308  'price_incl_tax' => 10.83,
309  'row_total' => 20,
310  'row_total_incl_tax' => 21.66,
311  'type' => 'product',
312  'tax_percent' => 8.25,
313  'discount_tax_compensation_amount' => 0,
314  'associated_item_code' => null,
315  'applied_taxes' => [
316  'US - 42 - 8.25' => [
317  'amount' => 1.66,
318  'percent' => 8.25,
319  'tax_rate_key' => 'US - 42 - 8.25',
320  'rates' => [
321  'US - 42 - 8.25' => [
322  'percent' => 8.25,
323  'code' => 'US - 42 - 8.25',
324  'title' => 'US - 42 - 8.25',
325  ],
326  ],
327  ],
328  ],
329  ],
330  'weee1-Recycling Fee' => [
331  'code' => 'weee1-Recycling Fee',
332  'row_tax' => 1.14,
333  'price' => 7,
334  'price_incl_tax' => 7.57,
335  'row_total' => 14,
336  'row_total_incl_tax' => 15.14,
337  'type' => 'weee',
338  'tax_percent' => 8.25,
339  'discount_tax_compensation_amount' => 0,
340  'associated_item_code' => 'sequence-1',
341  'applied_taxes' => [
342  'US - 42 - 8.25' => [
343  'amount' => 1.14,
344  'percent' => 8.25,
345  'tax_rate_key' => 'US - 42 - 8.25',
346  'rates' => [
347  'US - 42 - 8.25' => [
348  'percent' => 8.25,
349  'code' => 'US - 42 - 8.25',
350  'title' => 'US - 42 - 8.25',
351  ],
352  ],
353  ],
354  ],
355  ]
356  ],
357  ];
358 
359  $multiWeeeProducts = $baseQuote;
360  $multiWeeeProducts['items'][] = [
361  'code' => 'sequence-1',
362  'type' => 'product',
363  'quantity' => 2,
364  'unit_price' => 10,
365  'tax_class_key' => 'WeeeProductClass',
366  ];
367  $multiWeeeProducts['items'][] = [
368  'code' => 'weee1-Recycling Fee',
369  'type' => 'weee',
370  'quantity' => 2,
371  'unit_price' => 7,
372  'tax_class_key' => 'WeeeProductClass',
373  'associated_item_code' => 'sequence-1'
374  ];
375  $multiWeeeProducts['items'][] = [
376  'code' => 'sequence-2',
377  'type' => 'product',
378  'quantity' => 2,
379  'unit_price' => 10,
380  'tax_class_key' => 'WeeeProductClass',
381  ];
382  $multiWeeeProducts['items'][] = [
383  'code' => 'weee2-Recycling Fee',
384  'type' => 'weee',
385  'quantity' => 2,
386  'unit_price' => 7,
387  'tax_class_key' => 'WeeeProductClass',
388  'associated_item_code' => 'sequence-2'
389  ];
390  $multiWeeeProductsResults = [
391  'subtotal' => 68,
392  'tax_amount' => 5.60,
393  'discount_tax_compensation_amount' => 0,
394  'applied_taxes' => [
395  [
396  'amount' => 5.60,
397  'percent' => 8.25,
398  'rates' => [
399  [
400  'code' => 'US - 42 - 8.25',
401  'title' => 'US - 42 - 8.25',
402  'percent' => 8.25,
403  ],
404  ],
405  'tax_rate_key' => 'US - 42 - 8.25',
406  ],
407  ],
408  'items' => [
409  'sequence-1' => [
410  'code' => 'sequence-1',
411  'row_tax' => 1.66,
412  'price' => 10,
413  'price_incl_tax' => 10.83,
414  'row_total' => 20,
415  'row_total_incl_tax' => 21.66,
416  'type' => 'product',
417  'tax_percent' => 8.25,
418  'discount_tax_compensation_amount' => 0,
419  'associated_item_code' => null,
420  'applied_taxes' => [
421  'US - 42 - 8.25' => [
422  'amount' => 1.66,
423  'percent' => 8.25,
424  'tax_rate_key' => 'US - 42 - 8.25',
425  'rates' => [
426  'US - 42 - 8.25' => [
427  'percent' => 8.25,
428  'code' => 'US - 42 - 8.25',
429  'title' => 'US - 42 - 8.25',
430  ],
431  ],
432  ],
433  ],
434  ],
435  'weee1-Recycling Fee' => [
436  'code' => 'weee1-Recycling Fee',
437  'row_tax' => 1.14,
438  'price' => 7,
439  'price_incl_tax' => 7.57,
440  'row_total' => 14,
441  'row_total_incl_tax' => 15.14,
442  'type' => 'weee',
443  'tax_percent' => 8.25,
444  'discount_tax_compensation_amount' => 0,
445  'associated_item_code' => 'sequence-1',
446  'applied_taxes' => [
447  'US - 42 - 8.25' => [
448  'amount' => 1.14,
449  'percent' => 8.25,
450  'tax_rate_key' => 'US - 42 - 8.25',
451  'rates' => [
452  'US - 42 - 8.25' => [
453  'percent' => 8.25,
454  'code' => 'US - 42 - 8.25',
455  'title' => 'US - 42 - 8.25',
456  ],
457  ],
458  ],
459  ],
460  ],
461  'sequence-2' => [
462  'code' => 'sequence-2',
463  'row_tax' => 1.66,
464  'price' => 10,
465  'price_incl_tax' => 10.83,
466  'row_total' => 20,
467  'row_total_incl_tax' => 21.66,
468  'type' => 'product',
469  'tax_percent' => 8.25,
470  'discount_tax_compensation_amount' => 0,
471  'associated_item_code' => null,
472  'applied_taxes' => [
473  'US - 42 - 8.25' => [
474  'amount' => 1.66,
475  'percent' => 8.25,
476  'tax_rate_key' => 'US - 42 - 8.25',
477  'rates' => [
478  'US - 42 - 8.25' => [
479  'percent' => 8.25,
480  'code' => 'US - 42 - 8.25',
481  'title' => 'US - 42 - 8.25',
482  ],
483  ],
484  ],
485  ],
486  ],
487  'weee2-Recycling Fee' => [
488  'code' => 'weee2-Recycling Fee',
489  'row_tax' => 1.14,
490  'price' => 7,
491  'price_incl_tax' => 7.57,
492  'row_total' => 14,
493  'row_total_incl_tax' => 15.14,
494  'type' => 'weee',
495  'tax_percent' => 8.25,
496  'discount_tax_compensation_amount' => 0,
497  'associated_item_code' => 'sequence-2',
498  'applied_taxes' => [
499  'US - 42 - 8.25' => [
500  'amount' => 1.14,
501  'percent' => 8.25,
502  'tax_rate_key' => 'US - 42 - 8.25',
503  'rates' => [
504  'US - 42 - 8.25' => [
505  'percent' => 8.25,
506  'code' => 'US - 42 - 8.25',
507  'title' => 'US - 42 - 8.25',
508  ],
509  ],
510  ],
511  ],
512  ]
513  ],
514  ];
515 
516  $oneProductInclTax = $baseQuote;
517  $oneProductInclTax['items'][] = [
518  'code' => 'sku_1',
519  'type' => 'product',
520  'quantity' => 2,
521  'unit_price' => 10.75,
522  'tax_class_key' => 'DefaultProductClass',
523  'is_tax_included' => true,
524  ];
525  $oneProductInclTaxResults = $oneProductResults;
526 
527  $oneProductInclTaxDiffRate = $baseQuote;
528  $oneProductInclTaxDiffRate['items'][] = [
529  'code' => 'sku_1',
530  'type' => 'product',
531  'quantity' => 2,
532  'unit_price' => 11,
533  'tax_class_key' => 'HigherProductClass',
534  'is_tax_included' => true,
535  ];
536  $oneProductInclTaxDiffRateResults = [
537  'subtotal' => 20,
538  'tax_amount' => 4.4,
539  'discount_tax_compensation_amount' => 0,
540  'applied_taxes' => [
541  [
542  'amount' => 4.4,
543  'percent' => 22,
544  'rates' => [
545  [
546  'code' => 'US - 42 - 22',
547  'title' => 'US - 42 - 22',
548  'percent' => 22,
549  ],
550  ],
551  'tax_rate_key' => 'US - 42 - 22',
552  ],
553  ],
554  'items' => [
555  'sku_1' => [
556  'code' => 'sku_1',
557  'row_tax' => 4.4,
558  'price' => 10,
559  'price_incl_tax' => 12.2,
560  'row_total' => 20,
561  'row_total_incl_tax' => 24.4,
562  'type' => 'product',
563  'tax_percent' => 22.0,
564  'discount_tax_compensation_amount' => 0,
565  'associated_item_code' => null,
566  'applied_taxes' => [
567  'US - 42 - 22' => [
568  'amount' => 4.4,
569  'percent' => 22,
570  'tax_rate_key' => 'US - 42 - 22',
571  'rates' => [
572  'US - 42 - 22' => [
573  'percent' => 22,
574  'code' => 'US - 42 - 22',
575  'title' => 'US - 42 - 22',
576  ],
577  ],
578  ],
579  ],
580  ],
581  ],
582  ];
583 
584  $twoProducts = $baseQuote;
585  $twoProducts['items'] = [
586  [
587  'code' => 'sku_1',
588  'type' => 'product',
589  'quantity' => 2,
590  'unit_price' => 10,
591  'tax_class_key' => 'DefaultProductClass',
592  ],
593  [
594  'code' => 'sku_2',
595  'type' => 'product',
596  'quantity' => 20,
597  'unit_price' => 11,
598  'tax_class_key' => 'DefaultProductClass',
599  ],
600  ];
601  $twoProductsResults = [
602  'subtotal' => 240,
603  'tax_amount' => 18.1,
604  'discount_tax_compensation_amount' => 0,
605  'applied_taxes' => [
606  [
607  'amount' => 18.1,
608  'percent' => 7.5,
609  'rates' => [
610  [
611  'code' => 'US - 42 - 7.5',
612  'title' => 'US - 42 - 7.5',
613  'percent' => 7.5,
614  ],
615  ],
616  'tax_rate_key' => 'US - 42 - 7.5',
617  ],
618  ],
619  'items' => [
620  'sku_1' => [
621  'code' => 'sku_1',
622  'row_tax' => 1.5,
623  'price' => 10,
624  'price_incl_tax' => 10.75,
625  'row_total' => 20,
626  'row_total_incl_tax' => 21.5,
627  'type' => 'product',
628  'tax_percent' => 7.5,
629  'discount_tax_compensation_amount' => 0,
630  'associated_item_code' => null,
631  'applied_taxes' => [
632  'US - 42 - 7.5' => [
633  'amount' => 1.5,
634  'percent' => 7.5,
635  'tax_rate_key' => 'US - 42 - 7.5',
636  'rates' => [
637  'US - 42 - 7.5' => [
638  'percent' => 7.5,
639  'code' => 'US - 42 - 7.5',
640  'title' => 'US - 42 - 7.5',
641  ],
642  ],
643  ],
644  ],
645  ],
646  'sku_2' => [
647  'code' => 'sku_2',
648  'row_tax' => 16.6,
649  'price' => 11,
650  'price_incl_tax' => 11.83,
651  'row_total' => 220,
652  'row_total_incl_tax' => 236.6,
653  'type' => 'product',
654  'tax_percent' => 7.5,
655  'discount_tax_compensation_amount' => 0,
656  'associated_item_code' => null,
657  'applied_taxes' => [
658  'US - 42 - 7.5' => [
659  'amount' => 16.6,
660  'percent' => 7.5,
661  'tax_rate_key' => 'US - 42 - 7.5',
662  'rates' => [
663  'US - 42 - 7.5' => [
664  'percent' => 7.5,
665  'code' => 'US - 42 - 7.5',
666  'title' => 'US - 42 - 7.5',
667  ],
668  ],
669  ],
670  ],
671  ],
672  ],
673  ];
674 
675  $twoProductsInclTax = $baseQuote;
676  $twoProductsInclTax['items'] = [
677  [
678  'code' => 'sku_1',
679  'type' => 'product',
680  'quantity' => 2,
681  'unit_price' => 10.75,
682  'row_total' => 21.5,
683  'tax_class_key' => 'DefaultProductClass',
684  'is_tax_included' => true,
685  ],
686  [
687  'code' => 'sku_2',
688  'type' => 'product',
689  'quantity' => 20,
690  'unit_price' => 11.83,
691  'row_total' => 236.6,
692  'tax_class_key' => 'DefaultProductClass',
693  'is_tax_included' => true,
694  ],
695  ];
696  $twoProductInclTaxResults = $twoProductsResults;
697 
698  $bundleProduct = $baseQuote;
699  $bundleProduct['items'][] = [
700  'code' => 'sku_1',
701  'type' => 'product',
702  'quantity' => 1,
703  'unit_price' => 10,
704  'tax_class_key' => 'DefaultProductClass',
705  'parent_code' => 'bundle',
706  ];
707  $bundleProduct['items'][] = [
708  'code' => 'bundle',
709  'type' => 'product',
710  'quantity' => 2,
711  'unit_price' => 0,
712  'tax_class_key' => 'DefaultProductClass',
713  ];
714  $bundleProductResults = [
715  'subtotal' => 20,
716  'tax_amount' => 1.5,
717  'discount_tax_compensation_amount' => 0,
718  'applied_taxes' => [
719  [
720  'amount' => 1.5,
721  'percent' => 7.5,
722  'rates' => [
723  [
724  'code' => 'US - 42 - 7.5',
725  'title' => 'US - 42 - 7.5',
726  'percent' => 7.5,
727  ],
728  ],
729  'tax_rate_key' => 'US - 42 - 7.5',
730  ],
731  ],
732  'items' => [
733  'sku_1' => [
734  'code' => 'sku_1',
735  'row_tax' => 1.5,
736  'price' => 10,
737  'price_incl_tax' => 10.75,
738  'row_total' => 20,
739  'row_total_incl_tax' => 21.5,
740  'type' => 'product',
741  'tax_percent' => 7.5,
742  'discount_tax_compensation_amount' => 0,
743  'associated_item_code' => null,
744  'applied_taxes' => [
745  'US - 42 - 7.5' => [
746  'amount' => 1.5,
747  'percent' => 7.5,
748  'tax_rate_key' => 'US - 42 - 7.5',
749  'rates' => [
750  'US - 42 - 7.5' => [
751  'percent' => 7.5,
752  'code' => 'US - 42 - 7.5',
753  'title' => 'US - 42 - 7.5',
754  ],
755  ],
756  ],
757  ],
758  ],
759  'bundle' => [
760  'price' => 10,
761  'price_incl_tax' => 10.75,
762  'row_total' => 20,
763  'row_total_incl_tax' => 21.5,
764  'row_tax' => 1.5,
765  'code' => 'bundle',
766  'type' => 'product',
767  ],
768  ],
769  ];
770 
771  return [
772  'one product' => [
773  'quote_details' => $oneProduct,
774  'expected_tax_details' => $oneProductResults,
775  ],
776  'weee product' => [
777  'quote_details' => $weeeProduct,
778  'expected_tax_details' => $weeeProductResults,
779  ],
780  'weee products' => [
781  'quote_details' => $weeeProducts,
782  'expected_tax_details' => $weeeProductsResults,
783  ],
784  'multi weee products' => [
785  'quote_details' => $multiWeeeProducts,
786  'expected_tax_details' => $multiWeeeProductsResults,
787  ],
788  'one product, tax included' => [
789  'quote_details' => $oneProductInclTax,
790  'expected_tax_details' => $oneProductInclTaxResults,
791  ],
792  'one product, tax included but differs from store rate' => [
793  'quote_details' => $oneProductInclTaxDiffRate,
794  'expected_tax_details' => $oneProductInclTaxDiffRateResults,
795  ],
796  'two products' => [
797  'quote_details' => $twoProducts,
798  'expected_tax_details' => $twoProductsResults,
799  ],
800  'two products, tax included' => [
801  'quote_details' => $twoProductsInclTax,
802  'expected_tax_details' => $twoProductInclTaxResults,
803  ],
804  'bundle product' => [
805  'quote_details' => $bundleProduct,
806  'expected_tax_details' => $bundleProductResults,
807  ],
808  ];
809  }
$bundleProduct

◆ getBaseQuoteResult()

getBaseQuoteResult ( )
protected

Create the base results for the multi rules test

Returns
array @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 2200 of file TaxCalculationTest.php.

2201  {
2202  $result = [
2203  'subtotal' => 183.75,
2204  'tax_amount' => 42.88,
2205  'discount_tax_compensation_amount' => 3.08,
2206  'applied_taxes' => [
2207  [
2208  'amount' => 22.1,
2209  'percent' => 13.25,
2210  'rates' => [
2211  [
2212  'code' => 'US - 42 - 8.25',
2213  'title' => 'US - 42 - 8.25',
2214  'percent' => 8.25,
2215  ],
2216  [
2217  'code' => 'US - 42 - 5 - 55555',
2218  'title' => 'US - 42 - 5 - 55555',
2219  'percent' => 5,
2220  ],
2221  ],
2222  'tax_rate_key' => 'US - 42 - 8.25US - 42 - 5 - 55555',
2223  ],
2224  [
2225  'amount' => 20.78,
2226  'percent' => 12.4575,
2227  'rates' => [
2228  [
2229  'code' => 'US - 42 - 11 - 55555',
2230  'title' => 'US - 42 - 11 - 55555',
2231  'percent' => 11,
2232  ],
2233  ],
2234  'tax_rate_key' => 'US - 42 - 11 - 55555',
2235  ],
2236  ],
2237  'items' => [
2238  'sku_1' => [
2239  'code' => 'sku_1',
2240  'row_tax' => 3.31,
2241  'price' => 1.69,
2242  'price_incl_tax' => 2.12,
2243  'row_total' => 16.86,
2244  'row_total_incl_tax' => 21.2,
2245  'type' => 'product',
2246  'tax_percent' => 25.7075,
2247  'discount_tax_compensation_amount' => 1.03,
2248  'associated_item_code' => null,
2249  'applied_taxes' => [
2250  'US - 42 - 8.25US - 42 - 5 - 55555' => [
2251  'amount' => 1.71,
2252  'percent' => 13.25,
2253  'tax_rate_key' => 'US - 42 - 8.25US - 42 - 5 - 55555',
2254  'rates' => [
2255  'US - 42 - 8.25' => [
2256  'percent' => 8.25,
2257  'code' => 'US - 42 - 8.25',
2258  'title' => 'US - 42 - 8.25',
2259  ],
2260  'US - 42 - 5 - 55555' => [
2261  'percent' => 5,
2262  'code' => 'US - 42 - 5 - 55555',
2263  'title' => 'US - 42 - 5 - 55555',
2264  ],
2265  ],
2266  ],
2267  'US - 42 - 11 - 55555' => [
2268  'amount' => 1.6,
2269  'percent' => 12.4575,
2270  'tax_rate_key' => 'US - 42 - 11 - 55555',
2271  'rates' => [
2272  'US - 42 - 11 - 55555' => [
2273  'percent' => 11,
2274  'code' => 'US - 42 - 11 - 55555',
2275  'title' => 'US - 42 - 11 - 55555',
2276  ],
2277  ],
2278  ],
2279  ],
2280  ],
2281  'sku_2' => [
2282  'code' => 'sku_2',
2283  'row_tax' => 15.15,
2284  'price' => 13.38,
2285  'price_incl_tax' => 16.82,
2286  'row_total' => 66.9,
2287  'row_total_incl_tax' => 84.1,
2288  'type' => 'product',
2289  'tax_percent' => 25.7075,
2290  'discount_tax_compensation_amount' => 2.05,
2291  'associated_item_code' => null,
2292  'applied_taxes' => [
2293  'US - 42 - 8.25US - 42 - 5 - 55555' => [
2294  'amount' => 7.8,
2295  'percent' => 13.25,
2296  'tax_rate_key' => 'US - 42 - 8.25US - 42 - 5 - 55555',
2297  'rates' => [
2298  'US - 42 - 8.25' => [
2299  'percent' => 8.25,
2300  'code' => 'US - 42 - 8.25',
2301  'title' => 'US - 42 - 8.25',
2302  ],
2303  'US - 42 - 5 - 55555' => [
2304  'percent' => 5,
2305  'code' => 'US - 42 - 5 - 55555',
2306  'title' => 'US - 42 - 5 - 55555',
2307  ],
2308  ],
2309  ],
2310  'US - 42 - 11 - 55555' => [
2311  'amount' => 7.35,
2312  'percent' => 12.4575,
2313  'tax_rate_key' => 'US - 42 - 11 - 55555',
2314  'rates' => [
2315  'US - 42 - 11 - 55555' => [
2316  'percent' => 11,
2317  'code' => 'US - 42 - 11 - 55555',
2318  'title' => 'US - 42 - 11 - 55555',
2319  ],
2320  ],
2321  ],
2322  ],
2323  ],
2324  'sku_3' => [
2325  'code' => 'sku_3',
2326  'row_tax' => 24.42,
2327  'price' => 99.99,
2328  'price_incl_tax' => 125.7,
2329  'row_total' => 99.99,
2330  'row_total_incl_tax' => 125.7,
2331  'type' => 'product',
2332  'tax_percent' => 25.7075,
2333  'discount_tax_compensation_amount' => 0,
2334  'associated_item_code' => null,
2335  'applied_taxes' => [
2336  'US - 42 - 8.25US - 42 - 5 - 55555' => [
2337  'amount' => 12.59,
2338  'percent' => 13.25,
2339  'tax_rate_key' => 'US - 42 - 8.25US - 42 - 5 - 55555',
2340  'rates' => [
2341  'US - 42 - 8.25' => [
2342  'percent' => 8.25,
2343  'code' => 'US - 42 - 8.25',
2344  'title' => 'US - 42 - 8.25',
2345  ],
2346  'US - 42 - 5 - 55555' => [
2347  'percent' => 5,
2348  'code' => 'US - 42 - 5 - 55555',
2349  'title' => 'US - 42 - 5 - 55555',
2350  ],
2351  ],
2352  ],
2353  'US - 42 - 11 - 55555' => [
2354  'amount' => 11.83,
2355  'percent' => 12.4575,
2356  'tax_rate_key' => 'US - 42 - 11 - 55555',
2357  'rates' => [
2358  'US - 42 - 11 - 55555' => [
2359  'percent' => 11,
2360  'code' => 'US - 42 - 11 - 55555',
2361  'title' => 'US - 42 - 11 - 55555',
2362  ],
2363  ],
2364  ],
2365  ],
2366  ],
2367  ],
2368  ];
2369 
2370  return $result;
2371  }

◆ multiRulesRowBasedDataProvider()

multiRulesRowBasedDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 2396 of file TaxCalculationTest.php.

2397  {
2398  $quoteDetails = $this->setupMultiRuleQuote();
2399 
2400  $results = $this->getBaseQuoteResult();
2401 
2402  return [
2403  'multi rules, multi rows' => [
2404  'quote_details' => $quoteDetails,
2405  'expected_tax_details' => $results,
2406  ],
2407  ];
2408  }
$results
Definition: popup.phtml:13

◆ multiRulesTotalBasedDataProvider()

multiRulesTotalBasedDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 2433 of file TaxCalculationTest.php.

2434  {
2435  $quoteDetails = $this->setupMultiRuleQuote();
2436 
2437  $results = $this->getBaseQuoteResult();
2438 
2439  //Differences from the row base result
2440  $results['subtotal'] = 183.76;
2441  $results['tax_amount'] = 42.89;
2442  $results['discount_tax_compensation_amount'] = 3.06;
2443  $results['applied_taxes'][0]['amount'] = 22.11;
2444  $results['items']['sku_2']['row_tax'] = 15.16;
2445  $results['items']['sku_2']['row_total'] = 66.91;
2446  $results['items']['sku_2']['discount_tax_compensation_amount'] = 2.03;
2447  $results['items']['sku_2']['applied_taxes']['US - 42 - 8.25US - 42 - 5 - 55555']['amount'] = 7.81;
2448 
2449  return [
2450  'multi rules, multi rows' => [
2451  'quote_details' => $quoteDetails,
2452  'expected_tax_details' => $results,
2453  ],
2454  ];
2455  }
$results
Definition: popup.phtml:13

◆ multiRulesUnitBasedDataProvider()

multiRulesUnitBasedDataProvider ( )

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 2480 of file TaxCalculationTest.php.

2481  {
2482  $quoteDetails = $this->setupMultiRuleQuote();
2483 
2484  $results = $this->getBaseQuoteResult();
2485 
2486  //Differences from the row base result
2487  $results['subtotal'] = 183.79;
2488  $results['tax_amount'] = 42.87;
2489  $results['discount_tax_compensation_amount'] = 3.05;
2490  $results['applied_taxes'][1]['amount'] = 20.77;
2491  $results['items']['sku_1']['row_tax'] = 3.3;
2492  $results['items']['sku_1']['row_total'] = 16.9;
2493  $results['items']['sku_1']['discount_tax_compensation_amount'] = 1;
2494  $results['items']['sku_1']['applied_taxes']['US - 42 - 8.25US - 42 - 5 - 55555']['amount'] = 1.7;
2495  $results['items']['sku_2']['applied_taxes']['US - 42 - 8.25US - 42 - 5 - 55555']['amount'] = 7.81;
2496  $results['items']['sku_2']['applied_taxes']['US - 42 - 11 - 55555']['amount'] = 7.34;
2497 
2498  return [
2499  'multi rules, multi rows' => [
2500  'quote_details' => $quoteDetails,
2501  'expected_tax_details' => $results,
2502  ],
2503  ];
2504  }
$results
Definition: popup.phtml:13

◆ setUp()

setUp ( )
protected

Definition at line 78 of file TaxCalculationTest.php.

79  {
80  $this->objectManager = Bootstrap::getObjectManager();
81  $this->quoteDetailsFactory = $this->objectManager->create(
82  \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory::class
83  );
84  $this->dataObjectHelper = $this->objectManager->create(\Magento\Framework\Api\DataObjectHelper::class);
85  $this->taxCalculationService = $this->objectManager->get(\Magento\Tax\Api\TaxCalculationInterface::class);
86  $this->taxRuleFixtureFactory = new TaxRuleFixtureFactory();
87 
88  $this->setUpDefaultRules();
89  }

◆ setupMultiRuleQuote()

setupMultiRuleQuote ( )
protected

Create quote details for use with multi rules tests

Returns
array

Definition at line 2159 of file TaxCalculationTest.php.

2160  {
2161  $baseQuote = $this->getBaseQuoteData();
2162 
2163  $baseQuote['items'][] = [
2164  'code' => 'sku_1',
2165  'type' => 'product',
2166  'quantity' => 10,
2167  'unit_price' => 1.89,
2168  'tax_class_key' => 'MultipleRulesProductClass',
2169  'is_tax_included' => true,
2170  'discount_amount' => 5,
2171  ];
2172  $baseQuote['items'][] = [
2173  'code' => 'sku_2',
2174  'type' => 'product',
2175  'quantity' => 5,
2176  'unit_price' => 14.99,
2177  'tax_class_key' => 'MultipleRulesProductClass',
2178  'is_tax_included' => true,
2179  'discount_amount' => 10,
2180  ];
2181  $baseQuote['items'][] = [
2182  'code' => 'sku_3',
2183  'type' => 'product',
2184  'quantity' => 1,
2185  'unit_price' => 99.99,
2186  'tax_class_key' => 'MultipleRulesProductClass',
2187  'is_tax_included' => false,
2188  'discount_amount' => 5,
2189  ];
2190 
2191  return $baseQuote;
2192  }

◆ tearDown()

tearDown ( )
protected

Definition at line 91 of file TaxCalculationTest.php.

92  {
93  $this->tearDownDefaultRules();
94  }

◆ testCalculateTaxRowBased()

testCalculateTaxRowBased (   $quoteDetailsData,
  $expectedTaxDetails 
)

@magentoDbIsolation enabled @dataProvider calculateTaxRowBasedDataProvider @magentoConfigFixture default_store tax/calculation/algorithm ROW_BASE_CALCULATION

Definition at line 1277 of file TaxCalculationTest.php.

1278  {
1279  $quoteDetailsData = $this->performTaxClassSubstitution($quoteDetailsData);
1280  $quoteDetails = $this->quoteDetailsFactory->create();
1281  $this->dataObjectHelper->populateWithArray(
1282  $quoteDetails,
1283  $quoteDetailsData,
1284  \Magento\Tax\Api\Data\QuoteDetailsInterface::class
1285  );
1286 
1287  $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails);
1288 
1289  $this->assertEquals($expectedTaxDetails, $this->convertObjectToArray($taxDetails));
1290  }

◆ testCalculateTaxTotalBased()

testCalculateTaxTotalBased (   $quoteDetailsData,
  $expectedTaxDetails,
  $storeId = null 
)

@dataProvider calculateTaxTotalBasedDataProvider @magentoConfigFixture current_store tax/calculation/algorithm TOTAL_BASE_CALCULATION

Definition at line 815 of file TaxCalculationTest.php.

816  {
817  $quoteDetailsData = $this->performTaxClassSubstitution($quoteDetailsData);
818  $quoteDetails = $this->quoteDetailsFactory->create();
819  $this->dataObjectHelper->populateWithArray(
820  $quoteDetails,
821  $quoteDetailsData,
822  \Magento\Tax\Api\Data\QuoteDetailsInterface::class
823  );
824 
825  $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails, $storeId);
826 
827  $this->assertEquals($expectedTaxDetails, $this->convertObjectToArray($taxDetails));
828  }

◆ testCalculateTaxUnitBased()

testCalculateTaxUnitBased (   $quoteDetailsData,
  $expected 
)

@magentoConfigFixture current_store tax/calculation/algorithm UNIT_BASE_CALCULATION @dataProvider calculateUnitBasedDataProvider

Definition at line 100 of file TaxCalculationTest.php.

101  {
102  $quoteDetailsData = $this->performTaxClassSubstitution($quoteDetailsData);
103  $quoteDetails = $this->quoteDetailsFactory->create();
104  $this->dataObjectHelper->populateWithArray(
105  $quoteDetails,
106  $quoteDetailsData,
107  \Magento\Tax\Api\Data\QuoteDetailsInterface::class
108  );
109 
110  $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails, 1);
111  $this->assertEquals($expected, $this->convertObjectToArray($taxDetails));
112  }

◆ testMultiRulesRowBased()

testMultiRulesRowBased (   $quoteDetailsData,
  $expectedTaxDetails 
)

@magentoDbIsolation enabled @dataProvider multiRulesRowBasedDataProvider @magentoConfigFixture default_store tax/calculation/algorithm ROW_BASE_CALCULATION

Definition at line 2378 of file TaxCalculationTest.php.

2379  {
2380  $quoteDetailsData = $this->performTaxClassSubstitution($quoteDetailsData);
2381  $quoteDetails = $this->quoteDetailsFactory->create();
2382  $this->dataObjectHelper->populateWithArray(
2383  $quoteDetails,
2384  $quoteDetailsData,
2385  \Magento\Tax\Api\Data\QuoteDetailsInterface::class
2386  );
2387 
2388  $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails);
2389 
2390  $this->assertEquals($expectedTaxDetails, $this->convertObjectToArray($taxDetails));
2391  }

◆ testMultiRulesTotalBased()

testMultiRulesTotalBased (   $quoteDetailsData,
  $expectedTaxDetails 
)

@magentoDbIsolation enabled @dataProvider multiRulesTotalBasedDataProvider @magentoConfigFixture default_store tax/calculation/algorithm TOTAL_BASE_CALCULATION

Definition at line 2415 of file TaxCalculationTest.php.

2416  {
2417  $quoteDetailsData = $this->performTaxClassSubstitution($quoteDetailsData);
2418  $quoteDetails = $this->quoteDetailsFactory->create();
2419  $this->dataObjectHelper->populateWithArray(
2420  $quoteDetails,
2421  $quoteDetailsData,
2422  \Magento\Tax\Api\Data\QuoteDetailsInterface::class
2423  );
2424 
2425  $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails);
2426 
2427  $this->assertEquals($expectedTaxDetails, $this->convertObjectToArray($taxDetails));
2428  }

◆ testMultiRulesUnitBased()

testMultiRulesUnitBased (   $quoteDetailsData,
  $expectedTaxDetails 
)

@magentoDbIsolation enabled @dataProvider multiRulesUnitBasedDataProvider @magentoConfigFixture default_store tax/calculation/algorithm UNIT_BASE_CALCULATION

Definition at line 2462 of file TaxCalculationTest.php.

2463  {
2464  $quoteDetailsData = $this->performTaxClassSubstitution($quoteDetailsData);
2465  $quoteDetails = $this->quoteDetailsFactory->create();
2466  $this->dataObjectHelper->populateWithArray(
2467  $quoteDetails,
2468  $quoteDetailsData,
2469  \Magento\Tax\Api\Data\QuoteDetailsInterface::class
2470  );
2471 
2472  $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails);
2473 
2474  $this->assertEquals($expectedTaxDetails, $this->convertObjectToArray($taxDetails));
2475  }

The documentation for this class was generated from the following file: