26 private $objectManagerHelper;
41 private $conditionsHelperMock;
46 private $responseMock;
51 private $objectManagerMock;
68 $this->objectManagerHelper =
new ObjectManagerHelper($this);
69 $this->objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
70 $this->viewMock = $this->getMockForAbstractClass(ViewInterface::class);
71 $this->requestMock = $this->getMockForAbstractClass(RequestInterface::class);
72 $this->responseMock = $this->getMockBuilder(ResponseInterface::class)
73 ->setMethods([
'representJson'])
74 ->getMockForAbstractClass();
75 $this->contextMock = $this->getMockBuilder(Context::class)
76 ->disableOriginalConstructor()
78 $this->contextMock->expects($this->once())
80 ->willReturn($this->viewMock);
81 $this->contextMock->expects($this->once())
82 ->method(
'getRequest')
83 ->willReturn($this->requestMock);
84 $this->contextMock->expects($this->once())
85 ->method(
'getResponse')
86 ->willReturn($this->responseMock);
87 $this->contextMock->expects($this->once())
88 ->method(
'getObjectManager')
89 ->willReturn($this->objectManagerMock);
90 $this->conditionsHelperMock = $this->getMockBuilder(ConditionsHelper::class)
91 ->disableOriginalConstructor()
94 $this->loadOptions = $this->objectManagerHelper->getObject(
96 [
'context' => $this->contextMock]
98 $this->objectManagerHelper->setBackwardCompatibleProperty(
101 $this->conditionsHelperMock
108 public function dtestExecuteWithException()
110 $jsonResult =
'{"error":true,"message":"Some error"}';
111 $errorMessage =
'Some error';
114 $jsonDataHelperMock = $this->getMockBuilder(\
Magento\Framework\Json\Helper\Data::class)
115 ->disableOriginalConstructor()
117 $jsonDataHelperMock->expects($this->once())
118 ->method(
'jsonEncode')
119 ->with([
'error' =>
true,
'message' => $errorMessage])
120 ->willReturn($jsonResult);
122 $this->viewMock->expects($this->once())
123 ->method(
'loadLayout')
125 $this->objectManagerMock->expects($this->once())
127 ->with(\
Magento\Framework\Json\Helper\Data::class)
128 ->willReturn($jsonDataHelperMock);
129 $this->responseMock->expects($this->once())
130 ->method(
'representJson')
132 ->willReturnArgument(0);
134 $this->loadOptions->execute();
140 public function testExecute()
142 $widgetType =
'Magento\SomeWidget';
143 $conditionsEncoded =
'encoded conditions';
144 $conditionsDecoded = [
149 $widgetJsonParams =
'{"widget_type":"Magento\\Widget","values":{"title":""Test"", "":}}';
150 $widgetArrayParams = [
151 'widget_type' => $widgetType,
153 'title' =>
'"Test"',
154 'conditions_encoded' => $conditionsEncoded,
157 $resultWidgetArrayParams = [
158 'widget_type' => $widgetType,
161 'conditions_encoded' => $conditionsEncoded,
162 'conditions' => $conditionsDecoded,
167 $jsonDataHelperMock = $this->getMockBuilder(\
Magento\Framework\Json\Helper\Data::class)
168 ->disableOriginalConstructor()
170 $jsonDataHelperMock->expects($this->once())
171 ->method(
'jsonDecode')
172 ->with($widgetJsonParams)
173 ->willReturn($widgetArrayParams);
175 $this->viewMock->expects($this->once())
176 ->method(
'loadLayout');
177 $this->requestMock->expects($this->once())
180 ->willReturn($widgetJsonParams);
181 $this->objectManagerMock->expects($this->once())
183 ->with(\
Magento\Framework\Json\Helper\Data::class)
184 ->willReturn($jsonDataHelperMock);
187 $blockMock = $this->getMockBuilder(\
Magento\Framework\View\Element\BlockInterface::class)
188 ->setMethods([
'setWidgetType',
'setWidgetValues'])
189 ->getMockForAbstractClass();
190 $blockMock->expects($this->once())
191 ->method(
'setWidgetType')
194 $blockMock->expects($this->once())
195 ->method(
'setWidgetValues')
196 ->with($resultWidgetArrayParams[
'values'])
200 $layoutMock = $this->getMockForAbstractClass(\
Magento\Framework\View\LayoutInterface::class);
201 $layoutMock->expects($this->once())
203 ->with(
'wysiwyg_widget.options')
204 ->willReturn($blockMock);
206 $this->conditionsHelperMock->expects($this->once())
208 ->with($conditionsEncoded)
209 ->willReturn($conditionsDecoded);
210 $this->viewMock->expects($this->once())
211 ->method(
'getLayout')
212 ->willReturn($layoutMock);
213 $this->viewMock->expects($this->once())
214 ->method(
'renderLayout');
216 $this->loadOptions->execute();