Skip to content

Commit 6f23c88

Browse files
committed
MAGETWO-90802: Fix modularity of \Magento\Catalog\Block\Adminhtml\Product\Edit\JsTest
1 parent 92c3ac6 commit 6f23c88

File tree

5 files changed

+65
-13
lines changed

5 files changed

+65
-13
lines changed

app/code/Magento/Tax/Model/ResourceModel/Calculation/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Tax\Model\ResourceModel\Calculation;
77

88
/**
9-
* Tax rate resource model
9+
* Tax rule resource model
1010
*
1111
* @author Magento Core Team <[email protected]>
1212
*/

dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiDataFixture.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected function _getFixtures($scope, \PHPUnit\Framework\TestCase $test)
100100
* Execute single fixture script
101101
*
102102
* @param string|array $fixture
103+
* @throws \Throwable
103104
*/
104105
protected function _applyOneFixture($fixture)
105106
{
@@ -110,9 +111,13 @@ protected function _applyOneFixture($fixture)
110111
require $fixture;
111112
}
112113
} catch (\Exception $e) {
113-
echo 'Exception occurred when running the '
114-
. (is_array($fixture) || is_scalar($fixture) ? json_encode($fixture) : 'callback')
115-
. ' fixture: ', PHP_EOL, $e;
114+
throw new \Exception(
115+
sprintf(
116+
"Exception occurred when running the %s fixture: \n%s",
117+
(\is_array($fixture) || is_scalar($fixture) ? json_encode($fixture) : 'callback'),
118+
$e->getMessage()
119+
)
120+
);
116121
}
117122
$this->_appliedFixtures[] = $fixture;
118123
}

dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Product/Edit/JsTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,18 @@ public function testGetAllRatesByProductClassJson()
2929
/** @var \Magento\Catalog\Block\Adminhtml\Product\Edit\Js $block */
3030
$block = $objectManager->create(\Magento\Catalog\Block\Adminhtml\Product\Edit\Js::class);
3131
$jsonResult = $block->getAllRatesByProductClassJson();
32-
$decodedResult = json_decode($jsonResult);
33-
$this->assertNotEmpty($decodedResult, 'Resulting JSON is invalid.');
34-
$taxClassesArray = (array)$decodedResult;
32+
$this->assertJson($jsonResult, 'Resulting JSON is invalid.');
33+
$decodedResult = json_decode($jsonResult, true);
34+
$this->assertNotNull($decodedResult, 'Cannot decode resulting JSON.');
3535
$noneTaxClass = 0;
3636
$defaultProductTaxClass = 2;
3737
$expectedProductTaxClasses = array_unique(
3838
array_merge($fixtureTaxRule->getProductTaxClasses(), [$defaultProductTaxClass, $noneTaxClass])
3939
);
40-
$this->assertCount(
41-
count($expectedProductTaxClasses),
42-
$taxClassesArray,
43-
'Invalid quantity of rates for tax classes.'
44-
);
4540
foreach ($expectedProductTaxClasses as $taxClassId) {
4641
$this->assertArrayHasKey(
4742
"value_{$taxClassId}",
48-
$taxClassesArray,
43+
$decodedResult,
4944
"Rates for tax class with ID '{$taxClassId}' is missing."
5045
);
5146
}

dev/tests/integration/testsuite/Magento/Tax/_files/tax_classes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@
3838
\Magento\Tax\Model\ClassModel::TAX_CLASS_TYPE_PRODUCT
3939
)->save();
4040

41+
// Tax class created but not used in the rule to ensure that unused tax classes are handled properly
42+
$productTaxClass3 = $objectManager->create(
43+
\Magento\Tax\Model\ClassModel::class
44+
)->setClassName(
45+
'ProductTaxClass3'
46+
)->setClassType(
47+
\Magento\Tax\Model\ClassModel::TAX_CLASS_TYPE_PRODUCT
48+
)->save();
49+
4150
$taxRate = [
4251
'tax_country_id' => 'US',
4352
'tax_region_id' => '12',
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
/** @var $objectManager \Magento\TestFramework\ObjectManager */
9+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
10+
11+
$taxRules = [
12+
'Test Rule',
13+
'Test Rule Duplicate',
14+
];
15+
$taxClasses = [
16+
'ProductTaxClass1',
17+
'ProductTaxClass2',
18+
'ProductTaxClass3',
19+
'CustomerTaxClass1',
20+
'CustomerTaxClass2',
21+
];
22+
23+
24+
$taxRuleResource = $objectManager->get(\Magento\Tax\Model\ResourceModel\Calculation\Rule::class);
25+
foreach ($taxRules as $taxRuleCode) {
26+
$taxRule = $objectManager->create(\Magento\Tax\Model\Calculation\Rule::class);
27+
$taxRuleResource->load($taxRule, $taxRuleCode, 'code');
28+
$taxRuleResource->delete($taxRule);
29+
}
30+
31+
/** @var \Magento\Tax\Model\ResourceModel\TaxClass $resourceModel */
32+
$resourceModel = $objectManager->get(\Magento\Tax\Model\ResourceModel\TaxClass::class);
33+
34+
foreach ($taxClasses as $taxClass) {
35+
try {
36+
/** @var \Magento\Tax\Model\ClassModel $taxClassEntity */
37+
$taxClassEntity = $objectManager->create(\Magento\Tax\Model\ClassModel::class);
38+
$resourceModel->load($taxClassEntity, $taxClass, 'class_name');
39+
$resourceModel->delete($taxClassEntity);
40+
} catch (\Magento\Framework\Exception\CouldNotDeleteException $couldNotDeleteException) {
41+
// It's okay if the entity already wiped from the database
42+
}
43+
}

0 commit comments

Comments
 (0)