34 $this->serviceModel = $this->createMock(\
Magento\Theme\Model\Uploader\Service::class);
35 $this->themeFactory = $this->createMock(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class);
36 $this->jsonHelper = $this->createMock(\
Magento\Framework\Json\Helper\Data::class);
37 $this->logger = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class, [],
'',
false);
38 $this->themeCustomization = $this->getMockForAbstractClass(
39 \
Magento\Framework\View\Design\Theme\CustomizationInterface::class,
50 $this->customizationJs = $this->createMock(\
Magento\Framework\View\Design\Theme\Customization\File\Js::class);
57 $this->_request->expects($this->at(0))
60 ->willReturn($themeId);
62 $this->_objectManagerMock
63 ->expects($this->at(0))
65 ->with(\
Magento\Theme\Model\Uploader\Service::class)
66 ->willReturn($this->serviceModel);
67 $this->_objectManagerMock
68 ->expects($this->at(1))
70 ->with(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class)
71 ->willReturn($this->themeFactory);
72 $this->_objectManagerMock
73 ->expects($this->at(2))
75 ->with(\
Magento\Framework\View\Design\Theme\Customization\File\Js::class)
76 ->willReturn($this->customizationJs);
77 $this->_objectManagerMock
78 ->expects($this->at(3))
80 ->with(\
Magento\Framework\Json\Helper\Data::class)
81 ->willReturn($this->jsonHelper);
83 $this->themeFactory->expects($this->once())
87 ->expects($this->once())
88 ->method(
'jsonEncode')
89 ->with([
'error' =>
true,
'message' =>
"We cannot find a theme with id \"$themeId\"."])
90 ->willReturn(
'{"error":"true","message":"We cannot find a theme with id "' . $themeId .
'"."}');
91 $this->response->expects($this->once())
92 ->method(
'representJson')
93 ->with(
'{"error":"true","message":"We cannot find a theme with id "' . $themeId .
'"."}');
95 $this->_model->execute();
102 $this->_request->expects($this->at(0))
105 ->willReturn($themeId);
107 $this->_objectManagerMock->expects($this->at(0))
109 ->with(\
Magento\Theme\Model\Uploader\Service::class)
110 ->willReturn($this->serviceModel);
111 $this->_objectManagerMock->expects($this->at(1))
113 ->with(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class)
114 ->willReturn($this->themeFactory);
115 $this->_objectManagerMock
116 ->expects($this->at(2))
118 ->with(\
Magento\Framework\View\Design\Theme\Customization\File\Js::class)
119 ->willReturn($this->customizationJs);
120 $this->_objectManagerMock
121 ->expects($this->at(4))
123 ->with(\
Magento\Framework\Json\Helper\Data::class)
124 ->willReturn($this->jsonHelper);
126 $this->themeFactory->expects($this->once())
128 ->willThrowException(
new \Exception(
'Message'));
130 $this->_objectManagerMock->expects($this->at(3))
132 ->with(\Psr\Log\LoggerInterface::class)
133 ->willReturn($this->logger);
134 $this->logger->expects($this->once())
135 ->method(
'critical');
137 $this->jsonHelper->expects($this->once())
138 ->method(
'jsonEncode')
139 ->with([
'error' =>
true,
'message' =>
'We can\'t upload the JS file right now.'])
140 ->willReturn(
'{"error":"true","message":"We can\'t upload the JS file right now."}');
141 $this->response->expects($this->once())
142 ->method(
'representJson')
143 ->with(
'{"error":"true","message":"We can\'t upload the JS file right now."}');
145 $this->_model->execute();
151 $theme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class, [],
'',
false);
152 $jsFile = $this->getMockForAbstractClass(
153 \
Magento\Framework\View\Design\Theme\FileInterface::class,
167 $this->_request->expects($this->at(0))
170 ->willReturn($themeId);
172 $this->_objectManagerMock->expects($this->at(0))
174 ->with(\
Magento\Theme\Model\Uploader\Service::class)
175 ->willReturn($this->serviceModel);
176 $this->_objectManagerMock->expects($this->at(1))
178 ->with(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class)
179 ->willReturn($this->themeFactory);
180 $this->_objectManagerMock->expects($this->at(2))
182 ->with(\
Magento\Framework\View\Design\Theme\Customization\File\Js::class)
183 ->willReturn($this->customizationJs);
184 $this->_objectManagerMock->expects($this->at(4))
186 ->with(\
Magento\Framework\Json\Helper\Data::class)
187 ->willReturn($this->jsonHelper);
189 $this->themeFactory->expects($this->once())
193 ->expects($this->once())
194 ->method(
'uploadJsFile')
195 ->with(
'js_files_uploader')
196 ->willReturn([
'filename' =>
'filename',
'content' =>
'content']);
197 $this->customizationJs
198 ->expects($this->once())
200 ->willReturn($jsFile);
201 $jsFile->expects($this->once())
204 $jsFile->expects($this->once())
205 ->method(
'setFileName')
207 $jsFile->expects($this->once())
209 ->with(
'content',
'content');
210 $jsFile->expects($this->once())
213 $this->_objectManagerMock->expects($this->once())
216 \
Magento\Framework\View\Design\Theme\CustomizationInterface::class,
219 ->willReturn($this->themeCustomization);
220 $this->themeCustomization
221 ->expects($this->once())
222 ->method(
'getFilesByType')
223 ->with(\
Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE)
224 ->willReturn([$jsFile]);
225 $this->themeCustomization
226 ->expects($this->once())
227 ->method(
'generateFileInfo')
229 ->willReturn([
'fileOne' => [
'name' =>
'name']]);
232 ->expects($this->once())
233 ->method(
'jsonEncode')
234 ->with([
'error' =>
false,
'files' => [
'fileOne' => [
'name' =>
'name']]])
235 ->willReturn(
'{"error":false,"files":{"fileOne":{"name":"name"}}}');
236 $this->response->expects($this->once())
237 ->method(
'representJson')
238 ->with(
'{"error":false,"files":{"fileOne":{"name":"name"}}}');
240 $this->_model->execute();
testExecuteWithoutTheme()
testExecuteWithException()