Skip to content

Commit 3fe1635

Browse files
author
Sergii Kovalenko
committed
Merge branch '2.2-develop' of https://github.com/magento/magento2ce into MAGETWO-71231
2 parents 71cf26f + 4e4039f commit 3fe1635

File tree

5 files changed

+6955
-373
lines changed

5 files changed

+6955
-373
lines changed

app/code/Magento/Eav/Model/Entity/AttributeLoader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public function loadAllAttributes(AbstractEntity $resource, DataObject $object =
6969
* Check and init default attributes
7070
*/
7171
$defaultAttributesCodes = array_diff($resource->getDefaultAttributes(), $attributeCodes);
72+
73+
$resource->unsetAttributes();
74+
7275
foreach ($defaultAttributesCodes as $attributeCode) {
7376
$resource->addAttribute($this->_getDefaultAttribute($resource, $attributeCode));
7477
}

app/code/Magento/Eav/Test/Unit/Model/Entity/AttributeLoaderTest.php

Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Eav\Model\Attribute;
99
use Magento\Eav\Model\Config;
1010
use Magento\Eav\Model\Entity\AbstractEntity;
11-
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1211
use Magento\Eav\Model\Entity\AttributeLoader;
1312
use Magento\Eav\Model\Entity\Type;
1413
use Magento\Framework\DataObject;
@@ -41,87 +40,75 @@ class AttributeLoaderTest extends \PHPUnit_Framework_TestCase
4140
*/
4241
private $attributeLoader;
4342

43+
/**
44+
* @inheritdoc
45+
*/
4446
protected function setUp()
4547
{
46-
$this->configMock = $this->getMock(Config::class, [], [], '', false);
47-
$this->objectManagerMock = $this->getMock(ObjectManagerInterface::class);
48-
$this->entityMock = $this->getMock(AbstractEntity::class, [], [], '', false);
49-
$this->entityTypeMock = $this->getMock(Type::class, [], [], '', false);
48+
$this->configMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
49+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
50+
->setMethods(['create'])
51+
->disableOriginalConstructor()->getMockForAbstractClass();
52+
$this->entityMock = $this->getMockBuilder(AbstractEntity::class)->disableOriginalConstructor()->getMock();
53+
$this->entityTypeMock = $this->getMockBuilder(Type::class)->disableOriginalConstructor()->getMock();
5054
$this->attributeLoader = new AttributeLoader(
5155
$this->configMock,
5256
$this->objectManagerMock
5357
);
5458
}
5559

60+
/**
61+
* Test for loadAllAttributes method.
62+
*
63+
* @return void
64+
*/
5665
public function testLoadAllAttributes()
5766
{
58-
$defaultAttributes = ['bar'];
67+
$attributeCode = 'bar';
5968
$entityTypeId = 1;
6069
$dataObject = new DataObject();
61-
$this->entityMock->expects($this->any())
62-
->method('getEntityType')
63-
->willReturn($this->entityTypeMock);
64-
65-
$this->entityMock->expects($this->once())
66-
->method('getDefaultAttributes')
67-
->willReturn($defaultAttributes);
68-
$this->entityTypeMock->expects($this->any())
69-
->method('getId')
70-
->willReturn($entityTypeId);
71-
$attributeMock = $this->getMock(
72-
\Magento\Eav\Model\Attribute::class,
73-
[
74-
'setAttributeCode',
75-
'setBackendType',
76-
'setIsGlobal',
77-
'setEntityType',
78-
'setEntityTypeId'
79-
],
80-
[],
81-
'',
82-
false
83-
);
84-
$this->configMock->expects($this->once())
85-
->method('getEntityAttributes')
86-
->willReturn(['bar' => $attributeMock]);
87-
$this->entityMock->expects($this->once())
88-
->method('addAttribute')
89-
->with($attributeMock);
70+
$this->entityMock->expects($this->atLeastOnce())->method('getEntityType')->willReturn($this->entityTypeMock);
71+
$this->entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn([$attributeCode]);
72+
$this->entityTypeMock->expects($this->atLeastOnce())->method('getId')->willReturn($entityTypeId);
73+
$this->configMock->expects($this->once())->method('getEntityAttributes')->willReturn([]);
74+
$this->entityMock->expects($this->once())->method('unsetAttributes')->willReturnSelf();
75+
$this->entityTypeMock->expects($this->once())
76+
->method('getAttributeModel')->willReturn(\Magento\Eav\Model\Entity::DEFAULT_ATTRIBUTE_MODEL);
77+
$attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute::class)
78+
->setMethods(['setAttributeCode', 'setBackendType', 'setIsGlobal', 'setEntityType', 'setEntityTypeId'])
79+
->disableOriginalConstructor()->getMock();
80+
$this->objectManagerMock->expects($this->once())
81+
->method('create')->with(\Magento\Eav\Model\Entity::DEFAULT_ATTRIBUTE_MODEL)->willReturn($attributeMock);
82+
$attributeMock->expects($this->once())->method('setAttributeCode')->with($attributeCode)->willReturnSelf();
83+
$attributeMock->expects($this->once())->method('setBackendType')
84+
->with(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::TYPE_STATIC)->willReturnSelf();
85+
$attributeMock->expects($this->once())->method('setIsGlobal')->with(1)->willReturnSelf();
86+
$attributeMock->expects($this->once())->method('setEntityType')->with($this->entityTypeMock)->willReturnSelf();
87+
$attributeMock->expects($this->once())->method('setEntityTypeId')->with($entityTypeId)->willReturnSelf();
88+
$this->entityMock->expects($this->once())->method('addAttribute')->with($attributeMock)->willReturnSelf();
9089
$this->attributeLoader->loadAllAttributes($this->entityMock, $dataObject);
9190
}
9291

92+
/**
93+
* Test for loadAllAttributes method with attribute codes present in default attributes.
94+
*
95+
* @return void
96+
*/
9397
public function testLoadAllAttributesAttributeCodesPresentInDefaultAttributes()
9498
{
95-
$attributeMock = $this->getMock(
96-
\Magento\Eav\Model\Attribute::class,
97-
[
98-
'setAttributeCode',
99-
'setBackendType',
100-
'setIsGlobal',
101-
'setEntityType',
102-
'setEntityTypeId'
103-
],
104-
[],
105-
'',
106-
false
107-
);
108-
$attributeCodes = ['bar'=>$attributeMock];
99+
$attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Attribute::class)
100+
->disableOriginalConstructor()->getMock();
101+
$attributeCodes = ['bar' => $attributeMock];
109102
$defaultAttributes = ['bar'];
110103
$dataObject = new DataObject();
111-
$this->entityMock->expects($this->any())
112-
->method('getEntityType')
113-
->willReturn($this->entityTypeMock);
104+
$this->entityMock->expects($this->once())->method('getEntityType')->willReturn($this->entityTypeMock);
114105
$this->configMock->expects($this->once())
115-
->method('getEntityAttributes')
116-
->willReturn($attributeCodes, $dataObject);
117-
$this->entityMock->expects($this->once())
118-
->method('getDefaultAttributes')
119-
->willReturn($defaultAttributes);
106+
->method('getEntityAttributes')->willReturn($attributeCodes);
107+
$this->entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn($defaultAttributes);
108+
$this->entityMock->expects($this->once())->method('unsetAttributes')->willReturnSelf();
120109
$this->entityMock->expects($this->atLeastOnce())
121-
->method('addAttribute')->with($attributeMock);
122-
123-
$this->objectManagerMock->expects($this->never())
124-
->method('create');
110+
->method('addAttribute')->with($attributeMock)->willReturnSelf();
111+
$this->objectManagerMock->expects($this->never())->method('create');
125112
$this->attributeLoader->loadAllAttributes($this->entityMock, $dataObject);
126113
}
127114
}

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function testSaveActionCategoryWithDangerRequest()
339339
);
340340
$this->dispatch('backend/catalog/category/save');
341341
$this->assertSessionMessages(
342-
$this->equalTo(['The value of attribute "is_active" must be set']),
342+
$this->equalTo(['The value of attribute "name" must be set']),
343343
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
344344
);
345345
}

0 commit comments

Comments
 (0)