83 $this->actionContextMock = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
84 ->disableOriginalConstructor()
86 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)
87 ->disableOriginalConstructor()
89 $this->urlDecoderMock = $this->getMockBuilder(\
Magento\Framework\Url\DecoderInterface::class)
90 ->disableOriginalConstructor()
92 $this->objectManagerMock = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)
93 ->disableOriginalConstructor()
95 $this->templateFilterMock = $this->getMockBuilder(\
Magento\Cms\Model\Template\Filter::class)
96 ->disableOriginalConstructor()
98 $this->imageAdapterFactoryMock = $this->getMockBuilder(\
Magento\Framework\Image\AdapterFactory::class)
99 ->disableOriginalConstructor()
101 $this->imageAdapterMock = $this->getMockBuilder(\
Magento\Framework\Image\Adapter\AdapterInterface::class)
102 ->disableOriginalConstructor()
109 'refreshImageDimensions',
111 'createPngFromString',
120 $this->responseMock = $this->getMockBuilder(\
Magento\Framework\
App\ResponseInterface::class)
121 ->disableOriginalConstructor()
122 ->setMethods([
'setHeader',
'setBody',
'sendResponse'])
124 $this->wysiwygConfigMock = $this->getMockBuilder(\
Magento\Cms\Model\Wysiwyg\Config::class)
125 ->disableOriginalConstructor()
127 $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
128 ->disableOriginalConstructor()
130 $this->rawFactoryMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\RawFactory::class)
131 ->setMethods([
'create'])
132 ->disableOriginalConstructor()
134 $this->rawMock = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Raw::class)
135 ->disableOriginalConstructor()
138 $this->actionContextMock->expects($this->any())
139 ->method(
'getRequest')
140 ->willReturn($this->requestMock);
141 $this->actionContextMock->expects($this->any())
142 ->method(
'getResponse')
143 ->willReturn($this->responseMock);
144 $this->actionContextMock->expects($this->any())
145 ->method(
'getObjectManager')
146 ->willReturn($this->objectManagerMock);
148 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
150 \
Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::class,
152 'context' => $this->actionContextMock,
153 'urlDecoder' => $this->urlDecoderMock,
154 'resultRawFactory' => $this->rawFactoryMock
164 $mimeType =
'image/jpeg';
165 $imageBody =
'abcdefghijklmnopqrstuvwxyz0123456789';
168 $this->imageAdapterMock->expects($this->once())
170 ->with(self::IMAGE_PATH);
171 $this->imageAdapterMock->expects($this->once())
172 ->method(
'getMimeType')
173 ->willReturn($mimeType);
174 $this->rawMock->expects($this->once())
175 ->method(
'setHeader')
176 ->with(
'Content-Type', $mimeType)
178 $this->rawMock->expects($this->once())
179 ->method(
'setContents')
182 $this->imageAdapterMock->expects($this->once())
184 ->willReturn($imageBody);
185 $this->rawFactoryMock->expects($this->any())
187 ->willReturn($this->rawMock);
191 $this->wysiwygDirective->execute()
200 $exception = new \Exception(
'epic fail');
201 $placeholderPath =
'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
202 $mimeType =
'image/png';
203 $imageBody =
'0123456789abcdefghijklmnopqrstuvwxyz';
206 $this->imageAdapterMock->expects($this->at(0))
208 ->with(self::IMAGE_PATH)
209 ->willThrowException($exception);
210 $this->wysiwygConfigMock->expects($this->once())
211 ->method(
'getSkinImagePlaceholderPath')
212 ->willReturn($placeholderPath);
213 $this->imageAdapterMock->expects($this->at(1))
215 ->with($placeholderPath);
216 $this->imageAdapterMock->expects($this->once())
217 ->method(
'getMimeType')
218 ->willReturn($mimeType);
219 $this->rawMock->expects($this->once())
220 ->method(
'setHeader')
221 ->with(
'Content-Type', $mimeType)
223 $this->rawMock->expects($this->once())
224 ->method(
'setContents')
227 $this->imageAdapterMock->expects($this->once())
229 ->willReturn($imageBody);
230 $this->loggerMock->expects($this->once())
233 $this->rawFactoryMock->expects($this->any())
235 ->willReturn($this->rawMock);
239 $this->wysiwygDirective->execute()
245 $directiveParam =
'e3ttZWRpYSB1cmw9Ind5c2l3eWcvYnVubnkuanBnIn19';
246 $directive =
'{{media url="wysiwyg/image.jpg"}}';
248 $this->requestMock->expects($this->once())
250 ->with(
'___directive')
251 ->willReturn($directiveParam);
252 $this->urlDecoderMock->expects($this->once())
254 ->with($directiveParam)
255 ->willReturn($directive);
256 $this->objectManagerMock->expects($this->once())
258 ->with(\
Magento\Cms\Model\Template\Filter::class)
259 ->willReturn($this->templateFilterMock);
260 $this->templateFilterMock->expects($this->once())
263 ->willReturn(self::IMAGE_PATH);
264 $this->objectManagerMock->expects($this->any())
268 [\
Magento\Framework\Image\AdapterFactory::class, $this->imageAdapterFactoryMock],
269 [\
Magento\Cms\Model\Wysiwyg\Config::class, $this->wysiwygConfigMock],
270 [\Psr\Log\LoggerInterface::class, $this->loggerMock]
273 $this->imageAdapterFactoryMock->expects($this->once())
275 ->willReturn($this->imageAdapterMock);