48 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
50 $this->contextMock = $this->createMock(\
Magento\Backend\Block\Template\Context::class);
52 $this->requestMock = $this->getMockBuilder(
55 ->disableOriginalConstructor()
58 $this->contextMock->expects($this->any())
59 ->method(
'getRequest')
60 ->will($this->returnValue($this->requestMock));
62 $this->urlBuilderMock = $this->getMockBuilder(
63 \
Magento\Framework\UrlInterface::class
65 ->disableOriginalConstructor()
68 $this->storeManagerMock = $this->getMockBuilder(
69 \
Magento\Store\Model\StoreManagerInterface::class
71 ->disableOriginalConstructor()
74 $this->contextMock->expects($this->any())
75 ->method(
'getStoreManager')
76 ->will($this->returnValue($this->storeManagerMock));
78 $this->storeMock = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
79 ->disableOriginalConstructor()
82 $this->contextMock->expects($this->any())
83 ->method(
'getUrlBuilder')
84 ->will($this->returnValue($this->urlBuilderMock));
86 $this->category = $this->objectManager->getObject(
87 \
Magento\Catalog\Block\Adminhtml\Category\AbstractCategory::class,
89 'context' => $this->contextMock,
101 $saveUrl =
'save URL';
102 $params = [
'_current' =>
false,
'_query' =>
false,
'store' =>
$storeId];
104 $this->requestMock->expects($this->once())->method(
'getParam')->with(
'store')->willReturn(
$storeId);
105 $this->storeManagerMock->expects($this->once())
108 ->willReturn($this->storeMock);
109 $this->storeMock->expects($this->once())->method(
'getId')->willReturn(
$storeId);
111 $this->urlBuilderMock->expects($this->once())
113 ->with(
'catalog/*/save',
$params)
114 ->willReturn($saveUrl);
116 $this->assertEquals($saveUrl, $this->category->getSaveUrl());
121 $this->category->setData(
'root_ids', [
'ids']);
122 $this->storeManagerMock->expects($this->never())->method(
'getGroups');
124 $this->assertEquals([
'ids'], $this->category->getRootIds());
129 $this->storeManagerMock->expects($this->once())->method(
'getGroups')->willReturn([$this->storeMock]);
130 $this->storeMock->expects($this->once())->method(
'getRootCategoryId')->willReturn(
'storeId');
132 $this->assertEquals([\
Magento\Catalog\Model\Category::TREE_ROOT_ID,
'storeId'], $this->category->getRootIds());
testGetRootIdsFromCache()
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]