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()
132 $fullPath =
'path/to/file';
134 $file = $this->getMockBuilder(\
Magento\Framework\View\Design\Theme\FileInterface::class)->getMock();
135 $customization = $this->getMockBuilder(\
Magento\Framework\View\Design\Theme\Customization::class)
136 ->disableOriginalConstructor()
138 $theme = $this->getMockBuilder(\
Magento\Framework\View\Design\ThemeInterface::class)
139 ->setMethods([
'getCustomization'])
140 ->getMockForAbstractClass();
141 $file->expects($this->once())
142 ->method(
'getContent')
143 ->willReturn(
'some_content');
144 $file->expects($this->once())
145 ->method(
'getFilename')
147 $file->expects($this->once())
148 ->method(
'getFullPath')
149 ->willReturn($fullPath);
150 $theme->expects($this->once())
151 ->method(
'getCustomization')
152 ->willReturn($customization);
153 $customization->expects($this->once())
154 ->method(
'getFilesByType')
155 ->with(\
Magento\Theme\Model\Theme\Customization\File\CustomCss::TYPE)
156 ->willReturn([$file]);
157 $this->request->expects($this->any())
160 ->willReturn($themeId);
161 $themeFactory = $this->getMockBuilder(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class)
162 ->setMethods([
'create'])
163 ->disableOriginalConstructor()
165 $this->objectManager->expects($this->any())
167 ->with(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class)
168 ->willReturn($themeFactory);
169 $themeFactory->expects($this->once())
173 $this->fileFactory->expects($this->once())
176 ->willReturn($this->getMockBuilder(\
Magento\Framework\
App\ResponseInterface::class)->getMock());
178 $this->assertInstanceOf(\
Magento\Framework\
App\ResponseInterface::class, $this->controller->execute());
184 $refererUrl =
'referer/url';
186 $this->request->expects($this->any())
189 ->willReturn($themeId);
190 $themeFactory = $this->getMockBuilder(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class)
191 ->setMethods([
'create'])
192 ->disableOriginalConstructor()
194 $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
195 $this->objectManager->expects($this->any())
197 ->with(\Psr\Log\LoggerInterface::class)
199 $this->objectManager->expects($this->any())
201 ->with(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class)
202 ->willReturn($themeFactory);
203 $themeFactory->expects($this->once())
207 $this->messageManager->expects($this->once())
208 ->method(
'addException');
209 $logger->expects($this->once())
210 ->method(
'critical');
211 $this->redirect->expects($this->once())
212 ->method(
'getRefererUrl')
213 ->willReturn($refererUrl);
214 $this->response->expects($this->once())
215 ->method(
'setRedirect')
218 $this->controller->execute();
testExecuteInvalidArgument()