63 $this->requestMock = $this->createMock(\
Magento\Framework\
App\Request\Http::class);
64 $this->viewMock = $this->createPartialMock(\
Magento\Framework\
App\View::class, [
'getLayout']);
65 $this->objectManagerMock = $this->createMock(\
Magento\Framework\
ObjectManager\ObjectManager::class);
66 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
68 $context = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
69 ->setMethods([
'getRequest',
'getResponse',
'getMessageManager',
'getSession'])
74 'response' => $this->responseMock,
75 'request' => $this->requestMock,
76 'view' => $this->viewMock,
77 'objectManager' => $this->objectManagerMock
83 $this->resultJson = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
84 ->disableOriginalConstructor()
86 $resultJsonFactory = $this->getMockBuilder(\
Magento\Framework\Controller\Result\JsonFactory::class)
87 ->disableOriginalConstructor()
88 ->setMethods([
'create'])
90 $resultJsonFactory->expects($this->atLeastOnce())
92 ->willReturn($this->resultJson);
94 $this->layoutMock = $this->createPartialMock(\
Magento\Framework\View\Layout::class, [
'createBlock']);
96 $layoutFactory = $this->getMockBuilder(\
Magento\Framework\View\LayoutFactory::class)
97 ->disableOriginalConstructor()
98 ->setMethods([
'create'])
100 $layoutFactory->expects($this->any())
102 ->willReturn($this->layoutMock);
104 $context->expects($this->once())->method(
'getRequest')->will($this->returnValue($this->requestMock));
105 $context->expects($this->once())->method(
'getResponse')->will($this->returnValue($this->responseMock));
106 $this->registryMock = $this->createMock(\
Magento\Framework\Registry::class);
107 $this->controller = new \Magento\Catalog\Controller\Adminhtml\Category\Widget\CategoriesJson(
117 $this->chooserBlockMock = $this->createMock(\
Magento\Catalog\Block\Adminhtml\Category\Widget\Chooser::class);
118 $this->layoutMock->expects($this->once())->method(
'createBlock')->will(
119 $this->returnValue($this->chooserBlockMock)
128 $this->requestMock->expects($this->any())->method(
'getPost')->will($this->returnValue($testCategoryId));
129 $categoryMock = $this->createMock(\
Magento\Catalog\Model\Category::class);
130 $categoryMock->expects($this->once())->method(
'load')->will($this->returnValue($categoryMock));
131 $categoryMock->expects($this->once())->method(
'getId')->will($this->returnValue($testCategoryId));
132 $this->objectManagerMock->expects($this->once())->method(
'create')
133 ->with($this->equalTo(\
Magento\Catalog\Model\Category::class))->will($this->returnValue($categoryMock));
135 $this->chooserBlockMock->expects($this->once())->method(
'setSelectedCategories')->will(
136 $this->returnValue($this->chooserBlockMock)
138 $testHtml =
'<div>Some test html</div>';
139 $this->chooserBlockMock->expects($this->once())->method(
'getTreeJson')->will($this->returnValue($testHtml));
140 $this->resultJson->expects($this->once())->method(
'setJsonData')->with($testHtml)->willReturnSelf();
141 $this->controller->execute();