11
11
use Magento \Catalog \Model \Category as CategoryModel ;
12
12
use Magento \Catalog \Model \CategoryFactory ;
13
13
use Magento \Catalog \Model \CategoryRepository ;
14
+ use Magento \Catalog \Model \CategoryRepository \PopulateWithValues ;
14
15
use Magento \Framework \Api \ExtensibleDataObjectConverter ;
15
16
use Magento \Framework \DataObject ;
16
17
use Magento \Framework \EntityManager \EntityMetadata ;
@@ -63,6 +64,11 @@ class CategoryRepositoryTest extends TestCase
63
64
*/
64
65
protected $ metadataPoolMock ;
65
66
67
+ /**
68
+ * @var MockObject
69
+ */
70
+ protected $ populateWithValuesMock ;
71
+
66
72
protected function setUp (): void
67
73
{
68
74
$ this ->categoryFactoryMock = $ this ->createPartialMock (
@@ -94,6 +100,12 @@ protected function setUp(): void
94
100
->with (CategoryInterface::class)
95
101
->willReturn ($ metadataMock );
96
102
103
+ $ this ->populateWithValuesMock = $ this
104
+ ->getMockBuilder (PopulateWithValues::class)
105
+ ->setMethods (['execute ' ])
106
+ ->disableOriginalConstructor ()
107
+ ->getMock ();
108
+
97
109
$ this ->model = (new ObjectManager ($ this ))->getObject (
98
110
CategoryRepository::class,
99
111
[
@@ -102,6 +114,7 @@ protected function setUp(): void
102
114
'storeManager ' => $ this ->storeManagerMock ,
103
115
'metadataPool ' => $ this ->metadataPoolMock ,
104
116
'extensibleDataObjectConverter ' => $ this ->extensibleDataObjectConverterMock ,
117
+ 'populateWithValues ' => $ this ->populateWithValuesMock ,
105
118
]
106
119
);
107
120
}
@@ -202,7 +215,7 @@ public function testFilterExtraFieldsOnUpdateCategory($categoryId, $categoryData
202
215
->method ('toNestedArray ' )
203
216
->willReturn ($ categoryData );
204
217
$ categoryMock ->expects ($ this ->once ())->method ('validate ' )->willReturn (true );
205
- $ categoryMock -> expects ($ this ->once ())->method ('addData ' )->with ($ dataForSave );
218
+ $ this -> populateWithValuesMock -> expects ($ this ->once ())->method ('execute ' )->with ($ categoryMock , $ dataForSave );
206
219
$ this ->categoryResourceMock ->expects ($ this ->once ())
207
220
->method ('save ' )
208
221
->willReturn (DataObject::class);
@@ -230,11 +243,11 @@ public function testCreateNewCategory()
230
243
231
244
$ categoryMock ->expects ($ this ->once ())->method ('getParentId ' )->willReturn ($ parentCategoryId );
232
245
$ parentCategoryMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('path ' );
233
- $ categoryMock ->expects ($ this ->once ())->method ('addData ' )->with ($ dataForSave );
234
246
$ categoryMock ->expects ($ this ->once ())->method ('validate ' )->willReturn (true );
235
247
$ this ->categoryResourceMock ->expects ($ this ->once ())
236
248
->method ('save ' )
237
249
->willReturn (DataObject::class);
250
+ $ this ->populateWithValuesMock ->expects ($ this ->once ())->method ('execute ' )->with ($ categoryMock , $ dataForSave );
238
251
$ this ->assertEquals ($ categoryMock , $ this ->model ->save ($ categoryMock ));
239
252
}
240
253
0 commit comments