|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Tax\Test\Unit; |
| 7 | + |
| 8 | +class GetterSetterTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @param string $className |
| 12 | + * @param array $variableNames |
| 13 | + * @dataProvider dataProviderGettersSetters |
| 14 | + */ |
| 15 | + public function testGettersSetters($className = null, $variableNames = null) |
| 16 | + { |
| 17 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 18 | + $classObject = $objectManager->getObject($className); |
| 19 | + |
| 20 | + foreach ($variableNames as $variableName => $variableValue) { |
| 21 | + $setterName = 'set' . $variableName; |
| 22 | + |
| 23 | + $this->assertTrue(method_exists($classObject, $setterName), |
| 24 | + "Method " . $setterName . " does not exist in " . $className); |
| 25 | + |
| 26 | + if (is_array($variableValue)) { |
| 27 | + if (strpos($variableValue[0], 'Magento') !== false) { |
| 28 | + $obj = $objectManager->getObject($variableValue[0]); |
| 29 | + $variableValue = [$obj]; |
| 30 | + $variableNames[$variableName] = $variableValue; |
| 31 | + } |
| 32 | + } else if (strpos($variableValue, 'Magento') !== false) { |
| 33 | + $obj = $objectManager->getObject($variableValue); |
| 34 | + $variableValue = $obj; |
| 35 | + $variableNames[$variableName] = $variableValue; |
| 36 | + } |
| 37 | + $this->assertNotFalse(call_user_func(array($classObject, $setterName), $variableValue), |
| 38 | + "Calling method " . $setterName . " failed in " . $className); |
| 39 | + } |
| 40 | + |
| 41 | + foreach ($variableNames as $variableName => $variableValue) { |
| 42 | + $getterName = 'get' . $variableName; |
| 43 | + |
| 44 | + $this->assertTrue(method_exists($classObject, $getterName), |
| 45 | + "Method " . $getterName . " does not exist in " . $className); |
| 46 | + $result = call_user_func(array($classObject, $getterName)); |
| 47 | + $this->assertNotFalse($result, |
| 48 | + "Calling method " . $getterName . " failed in " . $className); |
| 49 | + $this->assertSame($result, $variableValue, |
| 50 | + "Value from " . $getterName . "did not match in " . $className); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @return array |
| 56 | + */ |
| 57 | + public function dataProviderGettersSetters() |
| 58 | + { |
| 59 | + // Test each class that implements the Tax Api Data Interfaces |
| 60 | + return [ |
| 61 | + [ |
| 62 | + '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'] |
| 66 | + ], |
| 67 | + [ |
| 68 | + 'Magento\Tax\Model\TaxDetails\AppliedTaxRate', |
| 69 | + ['Code' => 'code', 'Title' => 'title', 'Percent' => 1.0, |
| 70 | + 'ExtensionAttributes' => 'Magento\Tax\Api\Data\AppliedTaxRateExtension'] |
| 71 | + ], |
| 72 | + [ |
| 73 | + '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'] |
| 77 | + ], |
| 78 | + [ |
| 79 | + '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'] |
| 83 | + ], |
| 84 | + [ |
| 85 | + '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'] |
| 89 | + ], |
| 90 | + [ |
| 91 | + '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'] |
| 99 | + ], |
| 100 | + [ |
| 101 | + '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'] |
| 109 | + ], |
| 110 | + [ |
| 111 | + 'Magento\Tax\Model\ClassModel', |
| 112 | + ['ClassId' => 1, 'ClassName' => 'className', 'ClassType' => 'classType', |
| 113 | + 'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassExtension'] |
| 114 | + ], |
| 115 | + [ |
| 116 | + 'Magento\Tax\Model\TaxClass\Key', |
| 117 | + ['Type' => 'type', 'Value' => 'value', |
| 118 | + 'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxClassKeyExtension'] |
| 119 | + ], |
| 120 | + [ |
| 121 | + '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'] |
| 127 | + ], |
| 128 | + [ |
| 129 | + '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'] |
| 136 | + ], |
| 137 | + [ |
| 138 | + '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'] |
| 144 | + ], |
| 145 | + [ |
| 146 | + 'Magento\Tax\Model\Calculation\Rate\Title', |
| 147 | + ['StoreId' => 'storeId', 'Value' => 'value', |
| 148 | + 'ExtensionAttributes' => '\Magento\Tax\Api\Data\TaxRateTitleExtension'] |
| 149 | + ], |
| 150 | + [ |
| 151 | + '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'] |
| 155 | + ] |
| 156 | + ]; |
| 157 | + } |
| 158 | +} |
0 commit comments