71 protected function setUp()
73 $context = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
74 ->disableOriginalConstructor()
76 $this->request = $this->getMockBuilder(\
Magento\Framework\
App\RequestInterface::class)->getMock();
77 $this->redirect = $this->getMockBuilder(\
Magento\Framework\
App\
Response\RedirectInterface::class)->getMock();
78 $this->response = $this->getMockBuilder(\
Magento\Framework\
App\ResponseInterface::class)
79 ->setMethods([
'sendResponse',
'setRedirect'])
81 $this->objectManager = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)->getMock();
82 $this->messageManager = $this->getMockBuilder(\
Magento\Framework\Message\ManagerInterface::class)->getMock();
83 $this->resultFactory = $this->getMockBuilder(\
Magento\Framework\Controller\ResultFactory::class)
84 ->disableOriginalConstructor()
86 $context->expects($this->any())
87 ->method(
'getRequest')
88 ->willReturn($this->request);
89 $context->expects($this->any())
90 ->method(
'getRedirect')
91 ->willReturn($this->redirect);
92 $context->expects($this->any())
93 ->method(
'getResponse')
94 ->willReturn($this->response);
95 $context->expects($this->any())
96 ->method(
'getObjectManager')
97 ->willReturn($this->objectManager);
98 $context->expects($this->any())
99 ->method(
'getMessageManager')
100 ->willReturn($this->messageManager);
101 $context->expects($this->any())
102 ->method(
'getResultFactory')
103 ->willReturn($this->resultFactory);
105 $this->registry = $this->getMockBuilder(
106 \
Magento\Framework\Registry::class
107 )->disableOriginalConstructor()->getMock();
108 $this->fileFactory = $this->getMockBuilder(\
Magento\Framework\
App\
Response\Http\FileFactory::class)
109 ->disableOriginalConstructor()
111 $this->repository = $this->getMockBuilder(\
Magento\Framework\View\Asset\Repository::class)
112 ->disableOriginalConstructor()
114 $this->filesystem = $this->getMockBuilder(\
Magento\Framework\Filesystem::class)
115 ->disableOriginalConstructor()
131 $fileParam =
'/path/to/file.ext';
133 $sourceFile =
'/source/file.ext';
134 $relPath =
'file.ext';
136 $this->request->expects($this->any())
140 [
'theme_id',
null, $themeId],
141 [
'file',
null, $fileParam],
144 $file = $this->getMockBuilder(\
Magento\Framework\View\Asset\File::class)
145 ->disableOriginalConstructor()
147 $theme = $this->getMockBuilder(\
Magento\Framework\View\Design\ThemeInterface::class)
148 ->setMethods([
'getId',
'load'])
149 ->getMockForAbstractClass();
150 $urlDecoder = $this->getMockBuilder(\
Magento\Framework\Url\DecoderInterface::class)->getMock();
151 $directoryRead = $this->getMockBuilder(\
Magento\Framework\Filesystem\Directory\ReadInterface::class)->getMock();
152 $this->objectManager->expects($this->any())
154 ->with(\
Magento\Framework\Url\DecoderInterface::class)
155 ->willReturn($urlDecoder);
156 $this->objectManager->expects($this->any())
158 ->with(\
Magento\Framework\View\Design\ThemeInterface::class)
160 $urlDecoder->expects($this->once())
163 ->willReturn($fileId);
164 $theme->expects($this->once())
168 $theme->expects($this->once())
170 ->willReturn($themeId);
171 $this->repository->expects($this->once())
172 ->method(
'createAsset')
173 ->with($fileId, [
'themeModel' =>
$theme])
175 $this->filesystem->expects($this->once())
176 ->method(
'getDirectoryRead')
178 ->willReturn($directoryRead);
179 $file->expects($this->once())
180 ->method(
'getSourceFile')
181 ->willReturn($sourceFile);
182 $directoryRead->expects($this->once())
183 ->method(
'getRelativePath')
185 ->willReturn($relPath);
186 $this->fileFactory->expects($this->once())
189 ->willReturn($this->getMockBuilder(\
Magento\Framework\
App\ResponseInterface::class)->getMock());
191 $this->assertInstanceOf(\
Magento\Framework\
App\ResponseInterface::class, $this->controller->execute());
197 $fileParam =
'/path/to/file.ext';
199 $refererUrl =
'referer/url';
201 $this->request->expects($this->any())
205 [
'theme_id',
null, $themeId],
206 [
'file',
null, $fileParam],
209 $theme = $this->getMockBuilder(\
Magento\Framework\View\Design\ThemeInterface::class)
210 ->setMethods([
'getId',
'load'])
211 ->getMockForAbstractClass();
212 $urlDecoder = $this->getMockBuilder(\
Magento\Framework\Url\DecoderInterface::class)->getMock();
213 $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
214 $this->objectManager->expects($this->any())
218 [\
Magento\Framework\Url\DecoderInterface::class, $urlDecoder],
219 [\Psr\Log\LoggerInterface::class,
$logger],
222 $this->objectManager->expects($this->any())
224 ->with(\
Magento\Framework\View\Design\ThemeInterface::class)
226 $urlDecoder->expects($this->once())
229 ->willReturn($fileId);
230 $theme->expects($this->once())
234 $theme->expects($this->once())
237 $this->messageManager->expects($this->once())
238 ->method(
'addException');
239 $logger->expects($this->once())
240 ->method(
'critical');
241 $this->redirect->expects($this->once())
242 ->method(
'getRefererUrl')
243 ->willReturn($refererUrl);
244 $this->response->expects($this->once())
245 ->method(
'setRedirect')
248 $this->controller->execute();
testExecuteInvalidArgument()