13
13
use Magento \Eav \Model \AttributeDataFactory ;
14
14
use Magento \Eav \Model \Entity \AbstractEntity ;
15
15
use Magento \Eav \Model \Validator \Attribute \Data ;
16
+ use Magento \Framework \App \ObjectManager ;
16
17
use Magento \Framework \DataObject ;
17
18
use Magento \Framework \Model \AbstractModel ;
18
19
use Magento \Framework \ObjectManagerInterface ;
@@ -35,6 +36,11 @@ class DataTest extends TestCase
35
36
*/
36
37
private $ model ;
37
38
39
+ /**
40
+ * @var \Magento\Eav\Model\Config|MockObject
41
+ */
42
+ private $ eavConfigMock ;
43
+
38
44
/**
39
45
* @inheritdoc
40
46
*/
@@ -49,7 +55,12 @@ protected function setUp(): void
49
55
]
50
56
)
51
57
->getMock ();
52
-
58
+ $ this ->createMock (ObjectManagerInterface::class);
59
+ ObjectManager::setInstance ($ this ->createMock (ObjectManagerInterface::class));
60
+ $ this ->eavConfigMock = $ this ->getMockBuilder (\Magento \Eav \Model \Config::class)
61
+ ->onlyMethods (['getEntityType ' ])
62
+ ->disableOriginalConstructor ()
63
+ ->getMock ();
53
64
$ this ->model = new Data ($ this ->attrDataFactory );
54
65
}
55
66
@@ -205,13 +216,17 @@ public function testIsValidAttributesFromCollection(): void
205
216
'is_visible ' => true ,
206
217
]
207
218
);
219
+ $ entityTypeCode = 'entity_type_code ' ;
208
220
$ collection = $ this ->getMockBuilder (DataObject::class)
209
221
->addMethods (['getItems ' ])->getMock ();
210
222
$ collection ->expects ($ this ->once ())->method ('getItems ' )->willReturn ([$ attribute ]);
211
223
$ entityType = $ this ->getMockBuilder (DataObject::class)
212
- ->addMethods (['getAttributeCollection ' ])
224
+ ->addMethods (['getAttributeCollection ' , ' getEntityTypeCode ' ])
213
225
->getMock ();
226
+ $ entityType ->expects ($ this ->atMost (2 ))->method ('getEntityTypeCode ' )->willReturn ($ entityTypeCode );
214
227
$ entityType ->expects ($ this ->once ())->method ('getAttributeCollection ' )->willReturn ($ collection );
228
+ $ this ->eavConfigMock ->expects ($ this ->once ())->method ('getEntityType ' )
229
+ ->with ($ entityTypeCode )->willReturn ($ entityType );
215
230
$ entity = $ this ->_getEntityMock ();
216
231
$ entity ->expects ($ this ->once ())->method ('getResource ' )->willReturn ($ resource );
217
232
$ entity ->expects ($ this ->once ())->method ('getEntityType ' )->willReturn ($ entityType );
@@ -235,7 +250,7 @@ public function testIsValidAttributesFromCollection(): void
235
250
)->willReturn (
236
251
$ dataModel
237
252
);
238
- $ validator = new Data ($ attrDataFactory );
253
+ $ validator = new Data ($ attrDataFactory, $ this -> eavConfigMock );
239
254
240
255
$ validator ->setData (['attribute ' => 'new_test_data ' ]);
241
256
$ this ->assertTrue ($ validator ->isValid ($ entity ));
0 commit comments