11
11
12
12
/**
13
13
* @magentoAppIsolation enabled
14
- * @magentoDataFixture Magento/Catalog /_files/category_attribute .php
14
+ * @magentoDataFixture Magento/Eav /_files/attribute_for_search .php
15
15
*/
16
16
class AttributeLoaderTest extends \PHPUnit_Framework_TestCase
17
17
{
@@ -24,12 +24,28 @@ class AttributeLoaderTest extends \PHPUnit_Framework_TestCase
24
24
* @var \Magento\Framework\ObjectManagerInterface
25
25
*/
26
26
private $ objectManager ;
27
-
27
+
28
+ /**
29
+ * @var \Magento\Eav\Model\Entity\AbstractEntity
30
+ */
31
+ private $ resource ;
32
+
28
33
protected function setUp ()
29
34
{
30
35
CacheCleaner::cleanAll ();
31
36
$ this ->objectManager = Bootstrap::getObjectManager ();
32
37
$ this ->attributeLoader = $ this ->objectManager ->get (AttributeLoader::class);
38
+ $ entityType = $ this ->objectManager ->create (\Magento \Eav \Model \Entity \Type::class)
39
+ ->loadByCode ('test ' );
40
+ $ context = $ this ->objectManager ->get (\Magento \Eav \Model \Entity \Context::class);
41
+ $ this ->resource = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \AbstractEntity::class)
42
+ ->setConstructorArgs ([$ context ])
43
+ ->setMethods (['getEntityType ' , 'getLinkField ' ])
44
+ ->getMock ();
45
+ $ this ->resource ->method ('getEntityType ' )
46
+ ->willReturn ($ entityType );
47
+ $ this ->resource ->method ('getLinkField ' )
48
+ ->willReturn ('link_field ' );
33
49
}
34
50
35
51
/**
@@ -43,50 +59,51 @@ public function testLoadAllAttributesTheFirstTime(
43
59
$ expectedNumOfAttributesByTable ,
44
60
$ object
45
61
) {
46
- /** @var \Magento\Catalog\Model\ResourceModel\Category $categoryResourceModel */
47
- $ categoryResourceModel = $ this ->objectManager ->get (\Magento \Catalog \Model \ResourceModel \Category::class);
48
-
49
62
// Before load all attributes
50
- $ attributesByCode = $ categoryResourceModel ->getAttributesByCode ();
51
- $ attributesByTable = $ categoryResourceModel ->getAttributesByTable ();
63
+ $ attributesByCode = $ this -> resource ->getAttributesByCode ();
64
+ $ attributesByTable = $ this -> resource ->getAttributesByTable ();
52
65
$ this ->assertEquals (0 , count ($ attributesByCode ));
53
66
$ this ->assertEquals (0 , count ($ attributesByTable ));
54
67
55
68
// Load all attributes
56
- $ categoryResourceModel2 = $ this ->attributeLoader ->loadAllAttributes (
57
- $ categoryResourceModel ,
69
+ $ resource2 = $ this ->attributeLoader ->loadAllAttributes (
70
+ $ this -> resource ,
58
71
$ object
59
72
);
60
- $ attributesByCode2 = $ categoryResourceModel2 ->getAttributesByCode ();
61
- $ attributesByTable2 = $ categoryResourceModel2 ->getAttributesByTable ();
73
+ $ attributesByCode2 = $ resource2 ->getAttributesByCode ();
74
+ $ attributesByTable2 = $ resource2 ->getAttributesByTable ();
62
75
$ this ->assertEquals ($ expectedNumOfAttributesByCode , count ($ attributesByCode2 ));
63
76
$ this ->assertEquals ($ expectedNumOfAttributesByTable , count ($ attributesByTable2 ));
64
77
}
65
78
66
79
public function loadAllAttributesDataProvider ()
67
80
{
81
+ /** @var \Magento\Eav\Model\Entity\Type $entityType */
82
+ $ entityType = Bootstrap::getObjectManager ()->create (\Magento \Eav \Model \Entity \Type::class)
83
+ ->loadByCode ('order ' );
84
+ $ attributeSetId = $ entityType ->getDefaultAttributeSetId ();
68
85
return [
69
86
[
70
- 40 ,
71
- 5 ,
87
+ 13 ,
88
+ 2 ,
72
89
null
73
90
],
74
91
[
75
- 39 ,
76
- 5 ,
92
+ 10 ,
93
+ 1 ,
77
94
new DataObject (
78
95
[
79
- 'attribute_set_id ' => 3 ,
96
+ 'attribute_set_id ' => $ attributeSetId ,
80
97
'store_id ' => 0
81
98
]
82
99
),
83
100
],
84
101
[
85
- 39 ,
86
- 5 ,
102
+ 10 ,
103
+ 1 ,
87
104
new DataObject (
88
105
[
89
- 'attribute_set_id ' => 3 ,
106
+ 'attribute_set_id ' => $ attributeSetId ,
90
107
'store_id ' => 10
91
108
]
92
109
),
0 commit comments