Skip to content

Commit 991156b

Browse files
committed
MAGETWO-83992: Unable to delete Fixed Tax Attribute from attribute set
1 parent c01a841 commit 991156b

File tree

4 files changed

+115
-36
lines changed

4 files changed

+115
-36
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/AttributeTest.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -150,40 +150,4 @@ private function getProductAttributeValues($attribute, $product)
150150

151151
return $connection->fetchAll($select);
152152
}
153-
154-
/**
155-
* Test to delete entity attribute with type "Fixed Product Tax".
156-
*
157-
* @magentoDataFixture Magento/Catalog/_files/fixed_product_attribute.php
158-
* @return void
159-
*/
160-
public function testDeleteEntityFixedTax()
161-
{
162-
/* @var EavAttribute $attribute */
163-
$attribute = $this->objectManager->get(EavAttribute::class);
164-
$attribute->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'fixed_product_attribute');
165-
166-
$entityEavAttributeRow = $this->getEavEntityAttributeRow(
167-
$attribute->getEntityTypeId(),
168-
4,
169-
$attribute->getId()
170-
);
171-
$this->assertNotEmpty(
172-
$entityEavAttributeRow['entity_attribute_id'],
173-
'The record is absent in table `eav_entity_attribute` for `fixed_product_attribute`'
174-
);
175-
176-
$attribute->setData('entity_attribute_id', $entityEavAttributeRow['entity_attribute_id']);
177-
$this->model->deleteEntity($attribute);
178-
179-
$entityEavAttributeRow = $this->getEavEntityAttributeRow(
180-
$attribute->getEntityTypeId(),
181-
4,
182-
$attribute->getId()
183-
);
184-
$this->assertEmpty(
185-
$entityEavAttributeRow,
186-
'The record is not remove from table `eav_entity_attribute` for `fixed_product_attribute`'
187-
);
188-
}
189153
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Model\ResourceModel;
10+
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Eav\Model\Entity\Attribute as EavAttribute;
13+
use Magento\Framework\EntityManager\MetadataPool;
14+
15+
/**
16+
* Test class for Catalog attribute resource model.
17+
*
18+
* @see Magento\Catalog\Model\ResourceModel\Attribute
19+
*/
20+
class AttributeTest extends \PHPUnit\Framework\TestCase
21+
{
22+
/**
23+
* @var \Magento\Catalog\Model\ResourceModel\Attribute
24+
*/
25+
private $model;
26+
27+
/**
28+
* @var \Magento\Catalog\Model\ResourceModel\Product
29+
*/
30+
protected $productResource;
31+
32+
/**
33+
* @var ProductRepositoryInterface
34+
*/
35+
private $productRepository;
36+
37+
/**
38+
* @var MetadataPool
39+
*/
40+
private $metadataPool;
41+
42+
/**
43+
* @var \Magento\Framework\ObjectManagerInterface
44+
*/
45+
protected $objectManager;
46+
47+
protected function setUp()
48+
{
49+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
50+
$this->model = $this->objectManager->get(
51+
\Magento\Catalog\Model\ResourceModel\Attribute::class
52+
);
53+
$this->productResource = $this->objectManager->get(
54+
\Magento\Catalog\Model\ResourceModel\Product::class
55+
);
56+
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
57+
$this->metadataPool = $this->objectManager->get(MetadataPool::class);
58+
}
59+
60+
/**
61+
* Retrieve eav attribute row.
62+
*
63+
* @param int $entityTypeId
64+
* @param int $attributeSetId
65+
* @param int $attributeId
66+
* @return array|false
67+
*/
68+
private function getEavEntityAttributeRow($entityTypeId, $attributeSetId, $attributeId)
69+
{
70+
$connection = $this->productResource->getConnection();
71+
$select = $connection->select()
72+
->from($this->productResource->getTable('eav_entity_attribute'))
73+
->where('attribute_set_id=?', $attributeSetId)
74+
->where('attribute_id=?', $attributeId)
75+
->where('entity_type_id=?', $entityTypeId);
76+
77+
return $connection->fetchRow($select);
78+
}
79+
80+
/**
81+
* Test to delete entity attribute with type "Fixed Product Tax".
82+
*
83+
* @magentoDataFixture Magento/Weee/_files/fixed_product_attribute.php
84+
* @return void
85+
*/
86+
public function testDeleteEntityFixedTax()
87+
{
88+
/* @var EavAttribute $attribute */
89+
$attribute = $this->objectManager->get(EavAttribute::class);
90+
$attribute->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'fixed_product_attribute');
91+
92+
$entityEavAttributeRow = $this->getEavEntityAttributeRow(
93+
$attribute->getEntityTypeId(),
94+
4,
95+
$attribute->getId()
96+
);
97+
$this->assertNotEmpty(
98+
$entityEavAttributeRow['entity_attribute_id'],
99+
'The record is absent in table `eav_entity_attribute` for `fixed_product_attribute`'
100+
);
101+
102+
$attribute->setData('entity_attribute_id', $entityEavAttributeRow['entity_attribute_id']);
103+
$this->model->deleteEntity($attribute);
104+
105+
$entityEavAttributeRow = $this->getEavEntityAttributeRow(
106+
$attribute->getEntityTypeId(),
107+
4,
108+
$attribute->getId()
109+
);
110+
$this->assertEmpty(
111+
$entityEavAttributeRow,
112+
'The record is not remove from table `eav_entity_attribute` for `fixed_product_attribute`'
113+
);
114+
}
115+
}

0 commit comments

Comments
 (0)