Skip to content

Commit 7615d2f

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-61628' into 2.0-prs
2 parents 1b2c266 + e1994e0 commit 7615d2f

File tree

3 files changed

+121
-39
lines changed
  • app/code/Magento

3 files changed

+121
-39
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Controller\Adminhtml\Category;
77

8+
use Magento\Store\Model\StoreManagerInterface;
9+
810
/**
911
* Class Save
1012
*/
@@ -25,6 +27,11 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
2527
*/
2628
protected $layoutFactory;
2729

30+
/**
31+
* @var StoreManagerInterface
32+
*/
33+
private $storeManager;
34+
2835
/**
2936
* Constructor
3037
*
@@ -82,6 +89,9 @@ public function execute()
8289
}
8390

8491
$storeId = $this->getRequest()->getParam('store');
92+
$store = $this->getStoreManager()->getStore($storeId);
93+
$this->getStoreManager()->setCurrentStore($store->getCode());
94+
8595
$refreshTree = false;
8696
$data = $this->getRequest()->getPostValue();
8797
if ($data) {
@@ -90,9 +100,7 @@ public function execute()
90100
$parentId = $this->getRequest()->getParam('parent');
91101
if (!$parentId) {
92102
if ($storeId) {
93-
$parentId = $this->_objectManager->get(
94-
'Magento\Store\Model\StoreManagerInterface'
95-
)->getStore(
103+
$parentId = $this->getStoreManager()->getStore(
96104
$storeId
97105
)->getRootCategoryId();
98106
} else {
@@ -211,4 +219,18 @@ public function execute()
211219
$redirectParams
212220
);
213221
}
222+
223+
/**
224+
* Get StoreManager object
225+
*
226+
* @return StoreManagerInterface
227+
*/
228+
private function getStoreManager()
229+
{
230+
if ($this->storeManager == null) {
231+
$this->storeManager = $this->_objectManager->get(StoreManagerInterface::class);
232+
}
233+
234+
return $this->storeManager;
235+
}
214236
}

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function setUp()
8787
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
8888

8989
$this->contextMock = $this->getMock(
90-
'Magento\Backend\App\Action\Context',
90+
\Magento\Backend\App\Action\Context::class,
9191
[
9292
'getTitle',
9393
'getRequest',
@@ -102,47 +102,47 @@ protected function setUp()
102102
false
103103
);
104104
$this->resultRedirectFactoryMock = $this->getMock(
105-
'Magento\Backend\Model\View\Result\RedirectFactory',
105+
\Magento\Backend\Model\View\Result\RedirectFactory::class,
106106
['create'],
107107
[],
108108
'',
109109
false
110110
);
111111
$this->resultRawFactoryMock = $this->getMock(
112-
'Magento\Framework\Controller\Result\RawFactory',
112+
\Magento\Framework\Controller\Result\RawFactory::class,
113113
[],
114114
[],
115115
'',
116116
false
117117
);
118118
$this->resultJsonFactoryMock = $this->getMock(
119-
'Magento\Framework\Controller\Result\JsonFactory',
119+
\Magento\Framework\Controller\Result\JsonFactory::class,
120120
['create'],
121121
[],
122122
'',
123123
false
124124
);
125125
$this->layoutFactoryMock = $this->getMock(
126-
'Magento\Framework\View\LayoutFactory',
126+
\Magento\Framework\View\LayoutFactory::class,
127127
['create'],
128128
[],
129129
'',
130130
false
131131
);
132132
$this->requestMock = $this->getMockForAbstractClass(
133-
'Magento\Framework\App\RequestInterface',
133+
\Magento\Framework\App\RequestInterface::class,
134134
[],
135135
'',
136136
false,
137137
true,
138138
true,
139139
['getParam', 'getPost', 'getPostValue']
140140
);
141-
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
141+
$this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
142142
->disableOriginalConstructor()
143143
->getMock();
144144
$this->eventManagerMock = $this->getMockForAbstractClass(
145-
'Magento\Framework\Event\ManagerInterface',
145+
\Magento\Framework\Event\ManagerInterface::class,
146146
[],
147147
'',
148148
false,
@@ -151,13 +151,13 @@ protected function setUp()
151151
['dispatch']
152152
);
153153
$this->responseMock = $this->getMockForAbstractClass(
154-
'Magento\Framework\App\ResponseInterface',
154+
\Magento\Framework\App\ResponseInterface::class,
155155
[],
156156
'',
157157
false
158158
);
159159
$this->messageManagerMock = $this->getMockForAbstractClass(
160-
'Magento\Framework\Message\ManagerInterface',
160+
\Magento\Framework\Message\ManagerInterface::class,
161161
[],
162162
'',
163163
false,
@@ -177,7 +177,7 @@ protected function setUp()
177177
->willReturn($this->resultRedirectFactoryMock);
178178

179179
$this->save = $this->objectManager->getObject(
180-
'Magento\Catalog\Controller\Adminhtml\Category\Save',
180+
\Magento\Catalog\Controller\Adminhtml\Category\Save::class,
181181
[
182182
'context' => $this->contextMock,
183183
'resultRawFactory' => $this->resultRawFactoryMock,
@@ -212,7 +212,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
212212
* |\PHPUnit_Framework_MockObject_MockObject $resultRedirectMock
213213
*/
214214
$resultRedirectMock = $this->getMock(
215-
'Magento\Backend\Model\View\Result\Redirect',
215+
\Magento\Backend\Model\View\Result\Redirect::class,
216216
[],
217217
[],
218218
'',
@@ -223,7 +223,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
223223
* |\PHPUnit_Framework_MockObject_MockObject $blockMock
224224
*/
225225
$blockMock = $this->getMock(
226-
'Magento\Framework\View\Element\Messages',
226+
\Magento\Framework\View\Element\Messages::class,
227227
['setMessages', 'getGroupedHtml'],
228228
[],
229229
'',
@@ -234,7 +234,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
234234
* |\PHPUnit_Framework_MockObject_MockObject $categoryMock
235235
*/
236236
$categoryMock = $this->getMock(
237-
'Magento\Catalog\Model\Category',
237+
\Magento\Catalog\Model\Category::class,
238238
[
239239
'setStoreId',
240240
'load',
@@ -263,7 +263,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
263263
* |\PHPUnit_Framework_MockObject_MockObject $parentCategoryMock
264264
*/
265265
$parentCategoryMock = $this->getMock(
266-
'Magento\Catalog\Model\Category',
266+
\Magento\Catalog\Model\Category::class,
267267
[
268268
'setStoreId',
269269
'load',
@@ -287,7 +287,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
287287
* |\PHPUnit_Framework_MockObject_MockObject $sessionMock
288288
*/
289289
$sessionMock = $this->getMock(
290-
'Magento\Backend\Model\Auth\Session',
290+
\Magento\Backend\Model\Auth\Session::class,
291291
['setActiveTabId'],
292292
[],
293293
'',
@@ -298,7 +298,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
298298
* |\PHPUnit_Framework_MockObject_MockObject $registryMock
299299
*/
300300
$registryMock = $this->getMock(
301-
'Magento\Framework\Registry',
301+
\Magento\Framework\Registry::class,
302302
['register'],
303303
[],
304304
'',
@@ -309,7 +309,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
309309
* |\PHPUnit_Framework_MockObject_MockObject $wysiwygConfigMock
310310
*/
311311
$wysiwygConfigMock = $this->getMock(
312-
'Magento\Cms\Model\Wysiwyg\Config',
312+
\Magento\Cms\Model\Wysiwyg\Config::class,
313313
['setStoreId'],
314314
[],
315315
'',
@@ -320,20 +320,20 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
320320
* |\PHPUnit_Framework_MockObject_MockObject $storeManagerMock
321321
*/
322322
$storeManagerMock = $this->getMockForAbstractClass(
323-
'Magento\Store\Model\StoreManagerInterface',
323+
\Magento\Store\Model\StoreManagerInterface::class,
324324
[],
325325
'',
326326
false,
327327
true,
328328
true,
329-
['getStore', 'getRootCategoryId']
329+
['getStore', 'getRootCategoryId', 'setCurrentStore']
330330
);
331331
/**
332332
* @var \Magento\Framework\View\Layout
333333
* |\PHPUnit_Framework_MockObject_MockObject $layoutMock
334334
*/
335335
$layoutMock = $this->getMockForAbstractClass(
336-
'Magento\Framework\View\Layout',
336+
\Magento\Framework\View\Layout::class,
337337
[],
338338
'',
339339
false,
@@ -346,7 +346,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
346346
* |\PHPUnit_Framework_MockObject_MockObject $resultJsonMock
347347
*/
348348
$resultJsonMock = $this->getMock(
349-
'Magento\Cms\Model\Wysiwyg\Config',
349+
\Magento\Cms\Model\Wysiwyg\Config::class,
350350
['setData'],
351351
[],
352352
'',
@@ -357,13 +357,27 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
357357
* |\PHPUnit_Framework_MockObject_MockObject $messagesMock
358358
*/
359359
$messagesMock = $this->getMock(
360-
'Magento\Framework\Message\Collection',
360+
\Magento\Framework\Message\Collection::class,
361361
[],
362362
[],
363363
'',
364364
false
365365
);
366366

367+
/**
368+
* @var \Magento\Store\Model\Store
369+
* |\PHPUnit_Framework_MockObject_MockObject $storeMock
370+
*/
371+
$storeMock = $this->getMock(
372+
\Magento\Store\Model\Store::class,
373+
[
374+
'getCode',
375+
],
376+
[],
377+
'',
378+
false
379+
);
380+
367381
$this->resultRedirectFactoryMock->expects($this->once())
368382
->method('create')
369383
->will($this->returnValue($resultRedirectMock));
@@ -379,6 +393,15 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
379393
]
380394
)
381395
);
396+
397+
$storeMock->expects($this->once())
398+
->method('getCode')
399+
->will($this->returnValue('admin'));
400+
401+
$storeManagerMock->expects($this->once())
402+
->method('setCurrentStore')
403+
->with('admin');
404+
382405
$this->objectManagerMock->expects($this->atLeastOnce())
383406
->method('create')
384407
->will($this->returnValue($categoryMock));
@@ -387,10 +410,10 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
387410
->will(
388411
$this->returnValueMap(
389412
[
390-
['Magento\Backend\Model\Auth\Session', $sessionMock],
391-
['Magento\Framework\Registry', $registryMock],
392-
['Magento\Cms\Model\Wysiwyg\Config', $wysiwygConfigMock],
393-
['Magento\Store\Model\StoreManagerInterface', $storeManagerMock],
413+
[\Magento\Backend\Model\Auth\Session::class, $sessionMock],
414+
[\Magento\Framework\Registry::class, $registryMock],
415+
[\Magento\Cms\Model\Wysiwyg\Config::class, $wysiwygConfigMock],
416+
[\Magento\Store\Model\StoreManagerInterface::class, $storeManagerMock],
394417
]
395418
)
396419
);
@@ -441,15 +464,23 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
441464

442465
if (!$parentId) {
443466
if ($storeId) {
444-
$storeManagerMock->expects($this->once())
467+
$storeManagerMock->expects($this->exactly(2))
445468
->method('getStore')
446469
->with($storeId)
447-
->will($this->returnSelf());
470+
->willReturnOnConsecutiveCalls(
471+
$storeMock,
472+
$this->returnSelf()
473+
);
448474
$storeManagerMock->expects($this->once())
449475
->method('getRootCategoryId')
450476
->will($this->returnValue($rootCategoryId));
451477
$parentId = $rootCategoryId;
452478
}
479+
} else {
480+
$storeManagerMock->expects($this->once())
481+
->method('getStore')
482+
->with($storeId)
483+
->will($this->returnValue($storeMock));
453484
}
454485
$categoryMock->expects($this->any())
455486
->method('load')
@@ -494,7 +525,7 @@ public function testExecute($categoryId, $storeId, $activeTabId, $parentId)
494525
);
495526

496527
$categoryResource = $this->getMock(
497-
'Magento\Catalog\Model\ResourceModel\Category',
528+
\Magento\Catalog\Model\ResourceModel\Category::class,
498529
[],
499530
[],
500531
'',

0 commit comments

Comments
 (0)