Skip to content

Commit f903a36

Browse files
author
Joan He
committed
MAGETWO-64216: Add integration test of \Magento\Eav\Model\Entity\AttributeLoader
1 parent 623e989 commit f903a36

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Eav\Model\Entity;
7+
8+
use Magento\Framework\DataObject;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\TestFramework\Helper\CacheCleaner;
11+
12+
/**
13+
* @magentoAppIsolation enabled
14+
* @magentoDbIsolation enabled
15+
*/
16+
class AttributeLoaderTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var AttributeLoader
20+
*/
21+
private $attributeLoader;
22+
23+
/**
24+
* @var \Magento\Framework\ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
protected function setUp()
29+
{
30+
CacheCleaner::cleanAll();
31+
$this->objectManager = Bootstrap::getObjectManager();
32+
$this->attributeLoader = $this->objectManager->get(AttributeLoader::class);
33+
}
34+
35+
/**
36+
* @param int $expectedNumOfAttributesByCode
37+
* @param int $expectedNumOfAttributesByTable
38+
* @param DataObject|null $object
39+
* @dataProvider loadAllAttributesDataProvider
40+
*/
41+
public function testLoadAllAttributesTheFirstTime(
42+
$expectedNumOfAttributesByCode,
43+
$expectedNumOfAttributesByTable,
44+
$object
45+
) {
46+
/** @var \Magento\Catalog\Model\ResourceModel\Category $categoryResourceModel */
47+
$categoryResourceModel = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Category::class);
48+
49+
// Create an attribute not in any attribute set
50+
$entityTypeId = $categoryResourceModel->getEntityType()->getEntityTypeId();
51+
/** @var \Magento\Eav\Model\Entity\Attribute $attribute */
52+
$attribute = $this->objectManager->create(\Magento\Eav\Model\Entity\Attribute::class);
53+
$attribute->setData(
54+
[
55+
'attribute_code' => 'test_attribute',
56+
'entity_type_id' => $entityTypeId,
57+
'backend_type' => 'varchar',
58+
'is_required' => 0,
59+
'is_user_defined' => 1,
60+
'is_unique' => 0,
61+
]
62+
);
63+
$attribute->save();
64+
65+
// Before load all attributes
66+
$attributesByCode = $categoryResourceModel->getAttributesByCode();
67+
$attributesByTable = $categoryResourceModel->getAttributesByTable();
68+
$this->assertEquals(0, count($attributesByCode));
69+
$this->assertEquals(0, count($attributesByTable));
70+
71+
// Load all attributes
72+
$categoryResourceModel2 = $this->attributeLoader->loadAllAttributes(
73+
$categoryResourceModel,
74+
$object
75+
);
76+
$attributesByCode2 = $categoryResourceModel2->getAttributesByCode();
77+
$attributesByTable2 = $categoryResourceModel2->getAttributesByTable();
78+
$this->assertEquals($expectedNumOfAttributesByCode, count($attributesByCode2));
79+
$this->assertEquals($expectedNumOfAttributesByTable, count($attributesByTable2));
80+
}
81+
82+
public function loadAllAttributesDataProvider()
83+
{
84+
return [
85+
[
86+
40,
87+
5,
88+
null
89+
],
90+
[
91+
39,
92+
5,
93+
new DataObject(
94+
[
95+
'attribute_set_id' => 3,
96+
'store_id' => 0
97+
]
98+
),
99+
],
100+
[
101+
39,
102+
5,
103+
new DataObject(
104+
[
105+
'attribute_set_id' => 3,
106+
'store_id' => 10
107+
]
108+
),
109+
],
110+
];
111+
}
112+
}

0 commit comments

Comments
 (0)