@@ -30,14 +30,9 @@ class TreeTest extends \PHPUnit_Framework_TestCase
30
30
*/
31
31
protected $ _collectionFactory ;
32
32
33
- /**
34
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
35
- */
36
- protected $ _objectHelper ;
37
-
38
33
protected function setUp ()
39
34
{
40
- $ this -> _objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
35
+ $ objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
41
36
$ select = $ this ->getMock ('Zend_Db_Select ' , [], [], '' , false );
42
37
$ select ->expects ($ this ->once ())->method ('from ' )->with ('catalog_category_entity ' );
43
38
$ connection = $ this ->getMock ('Magento\Framework\DB\Adapter\AdapterInterface ' );
@@ -76,7 +71,7 @@ protected function setUp()
76
71
'' ,
77
72
false
78
73
);
79
- $ this ->_model = $ this -> _objectHelper ->getObject (
74
+ $ this ->_model = $ objectHelper ->getObject (
80
75
'Magento\Catalog\Model\Resource\Category\Tree ' ,
81
76
[
82
77
'resource ' => $ this ->_resource ,
@@ -133,8 +128,9 @@ public function testCallCleaningDuringSetCollection()
133
128
$ this ->assertEquals ($ model , $ model ->setCollection ($ this ->getCollectionMock ()));
134
129
}
135
130
136
- protected function getConfiguredResource ()
131
+ public function testAddCollectionData ()
137
132
{
133
+ $ objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
138
134
$ select = $ this ->getMock ('Zend_Db_Select ' , [], [], '' , false );
139
135
$ select ->expects ($ this ->any ())->method ('from ' )->will ($ this ->returnSelf ());
140
136
$ select ->expects ($ this ->any ())->method ('join ' )->will ($ this ->returnSelf ());
@@ -149,11 +145,26 @@ protected function getConfiguredResource()
149
145
$ resource ->expects ($ this ->any ())->method ('getConnection ' )->will ($ this ->returnValue ($ connection ));
150
146
$ resource ->expects ($ this ->any ())->method ('getTableName ' )->will ($ this ->returnArgument (0 ));
151
147
152
- return $ resource ;
153
- }
148
+ $ eventManager = $ this ->getMock ('Magento\Framework\Event\ManagerInterface ' , [], [], '' , false );
149
+ $ attributeConfig = $ this ->getMock (
150
+ 'Magento\Catalog\Model\Attribute\Config ' ,
151
+ [],
152
+ [],
153
+ '' ,
154
+ false
155
+ );
156
+
157
+ $ attributes = ['attribute_one ' , 'attribute_two ' ];
158
+ $ attributeConfig ->expects (
159
+ $ this ->once ()
160
+ )->method (
161
+ 'getAttributeNames '
162
+ )->with (
163
+ 'catalog_category '
164
+ )->will (
165
+ $ this ->returnValue ($ attributes )
166
+ );
154
167
155
- protected function getConfiguredCollectionFactory ()
156
- {
157
168
$ collection = $ this ->getMock ('Magento\Catalog\Model\Resource\Category\Collection ' , [], [], '' , false );
158
169
$ collection ->expects ($ this ->never ())->method ('getAllIds ' )->will ($ this ->returnValue ([]));
159
170
$ collectionFactory = $ this ->getMock (
@@ -165,52 +176,20 @@ protected function getConfiguredCollectionFactory()
165
176
);
166
177
$ collectionFactory ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ collection ));
167
178
168
- return $ collectionFactory ;
169
- }
170
-
171
- protected function getConfiguredStoreManager ()
172
- {
173
179
$ store = $ this ->getMock ('Magento\Store\Model\Store ' , [], [], '' , false );
174
180
$ store ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue (1 ));
175
181
176
182
$ storeManager = $ this ->getMockForAbstractClass ('Magento\Store\Model\StoreManagerInterface ' );
177
183
$ storeManager ->expects ($ this ->any ())->method ('getStore ' )->will ($ this ->returnValue ($ store ));
178
184
179
- return $ storeManager ;
180
- }
181
-
182
- protected function getConfiguredAttributeConfig ()
183
- {
184
- $ attributeConfig = $ this ->getMock (
185
- 'Magento\Catalog\Model\Attribute\Config ' ,
186
- [],
187
- [],
188
- '' ,
189
- false
190
- );
191
-
192
- $ attributes = ['attribute_one ' , 'attribute_two ' ];
193
- $ attributeConfig
194
- ->expects ($ this ->once ())
195
- ->method ('getAttributeNames ' )
196
- ->with ('catalog_category ' )
197
- ->willReturn ($ attributes );
198
-
199
- return $ attributeConfig ;
200
- }
201
-
202
- public function testAddCollectionData ()
203
- {
204
- $ eventManager = $ this ->getMock ('Magento\Framework\Event\ManagerInterface ' , [], [], '' , false );
205
-
206
- $ model = $ this ->_objectHelper ->getObject (
185
+ $ model = $ objectHelper ->getObject (
207
186
'Magento\Catalog\Model\Resource\Category\Tree ' ,
208
187
[
209
- 'storeManager ' => $ this -> getConfiguredStoreManager () ,
210
- 'resource ' => $ this -> getConfiguredResource () ,
188
+ 'storeManager ' => $ storeManager ,
189
+ 'resource ' => $ resource ,
211
190
'eventManager ' => $ eventManager ,
212
- 'attributeConfig ' => $ this -> getConfiguredAttributeConfig () ,
213
- 'collectionFactory ' => $ this -> getConfiguredCollectionFactory ()
191
+ 'attributeConfig ' => $ attributeConfig ,
192
+ 'collectionFactory ' => $ collectionFactory
214
193
]
215
194
);
216
195
@@ -222,47 +201,4 @@ public function testAddCollectionData()
222
201
223
202
$ this ->assertSame ($ model , $ model ->addCollectionData (null , false , [], false , true ));
224
203
}
225
-
226
- public function testAddCollectionDataWhenThereIsCurrentCategoryInRegistry ()
227
- {
228
- $ eventManager = $ this ->getMock ('Magento\Framework\Event\ManagerInterface ' , [], [], '' , false );
229
-
230
- $ category = $ this ->getMock ('Magento\Catalog\Model\Category ' , [], [], '' , false );
231
- $ category
232
- ->expects ($ this ->atLeastOnce ())
233
- ->method ('getId ' )
234
- ->willReturn (12 );
235
-
236
- $ registry = $ this ->getMock ('Magento\Framework\Registry ' , [], [], '' , false );
237
- $ registry
238
- ->expects ($ this ->once ())
239
- ->method ('registry ' )
240
- ->with ('current_category ' )
241
- ->willReturn ($ category );
242
-
243
- $ model = $ this ->_objectHelper ->getObject (
244
- 'Magento\Catalog\Model\Resource\Category\Tree ' ,
245
- [
246
- 'storeManager ' => $ this ->getConfiguredStoreManager (),
247
- 'resource ' => $ this ->getConfiguredResource (),
248
- 'eventManager ' => $ eventManager ,
249
- 'attributeConfig ' => $ this ->getConfiguredAttributeConfig (),
250
- 'collectionFactory ' => $ this ->getConfiguredCollectionFactory (),
251
- 'registry ' => $ registry
252
- ]
253
- );
254
-
255
- $ nodeMock = $ this ->getMock ('\Magento\Framework\Data\Tree\Node ' , ['getId ' , 'getPath ' , '__call ' ], [], '' , false );
256
- $ nodeMock ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue (12 ));
257
- $ nodeMock ->expects ($ this ->once ())->method ('getPath ' )->will ($ this ->returnValue ([]));
258
- $ nodeMock
259
- ->expects ($ this ->once ())
260
- ->method ('__call ' )
261
- ->with ('setIsCurrentItem ' , [true ])
262
- ->willReturn (true );
263
-
264
- $ model ->addNode ($ nodeMock );
265
-
266
- $ this ->assertSame ($ model , $ model ->addCollectionData (null , false , [], false , true ));
267
- }
268
204
}
0 commit comments