9 use \Magento\Framework\App\Area;
14 class AreaTest extends \PHPUnit\Framework\TestCase
74 private $defaultRenderer;
79 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
80 $this->loggerMock = $this->getMockBuilder(\Psr\
Log\LoggerInterface::class)
81 ->disableOriginalConstructor()
83 $this->eventManagerMock = $this->getMockBuilder(\
Magento\Framework\
Event\ManagerInterface::class)
84 ->disableOriginalConstructor()
86 $this->translatorMock = $this->getMockBuilder(\
Magento\Framework\TranslateInterface::class)
87 ->disableOriginalConstructor()
90 ->disableOriginalConstructor()
92 $this->objectManagerMock = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)
93 ->disableOriginalConstructor()
95 $this->designMock = $this->getMockBuilder(\
Magento\Framework\
App\DesignInterface::class)
96 ->disableOriginalConstructor()
98 $this->scopeResolverMock = $this->getMockBuilder(\
Magento\Framework\
App\ScopeResolverInterface::class)
99 ->disableOriginalConstructor()
101 $scopeMock = $this->getMockBuilder(\
Magento\Framework\
App\ScopeInterface::class)
102 ->disableOriginalConstructor()
104 $scopeMock->expects($this->any())
106 ->will($this->returnValue(self::SCOPE_ID));
107 $this->scopeResolverMock->expects($this->any())
109 ->will($this->returnValue($scopeMock));
110 $this->designExceptionsMock = $this->getMockBuilder(\
Magento\Framework\
View\DesignExceptions::class)
111 ->disableOriginalConstructor()
115 $this->
object = $this->objectManager->getObject(
118 'logger' => $this->loggerMock,
119 'objectManager' => $this->objectManagerMock,
120 'eventManager' => $this->eventManagerMock,
121 'translator' => $this->translatorMock,
122 'diConfigLoader' => $this->diConfigLoaderMock,
123 'design' => $this->designMock,
124 'scopeResolver' => $this->scopeResolverMock,
125 'designExceptions' => $this->designExceptionsMock,
126 'areaCode' => $this->areaCode,
138 $this->verifyLoadConfig();
144 $this->translatorMock->expects($this->once())
145 ->method(
'loadData');
146 $renderMock = $this->getMockBuilder(\
Magento\Framework\
Phrase\RendererInterface::class)
147 ->disableOriginalConstructor()
149 $this->objectManagerMock->expects($this->once())
152 ->will($this->returnValue($renderMock));
159 ->disableOriginalConstructor()
161 $this->objectManagerMock->expects($this->once())
163 ->with(\
Magento\Framework\
View\DesignInterface::class)
167 ->with($this->areaCode)
170 ->method(
'setDefaultDesignTheme');
176 $this->objectManagerMock->expects($this->never())
177 ->method(
'configure');
178 $this->objectManagerMock->expects($this->never())
180 $this->
object->load(
'unknown part');
185 $this->verifyLoadConfig();
186 $this->translatorMock->expects($this->once())
187 ->method(
'loadData');
188 $renderMock = $this->getMockBuilder(\
Magento\Framework\
Phrase\RendererInterface::class)
189 ->disableOriginalConstructor()
192 ->disableOriginalConstructor()
196 ->with($this->areaCode)
199 ->method(
'setDefaultDesignTheme');
200 $this->objectManagerMock->expects($this->exactly(2))
202 ->will($this->returnValueMap(
204 [\
Magento\Framework\
Phrase\RendererInterface::class, $renderMock],
208 $this->
object->load();
211 private function verifyLoadConfig()
213 $configs = [
'dummy configs'];
214 $this->diConfigLoaderMock->expects($this->once())
216 ->with($this->areaCode)
217 ->will($this->returnValue($configs));
218 $this->objectManagerMock->expects($this->once())
219 ->method(
'configure')
225 $this->designExceptionsMock->expects($this->never())
226 ->method(
'getThemeByRequest');
227 $this->designMock->expects($this->once())
228 ->method(
'loadChange')
229 ->with(self::SCOPE_ID)
232 ->disableOriginalConstructor()
234 $this->objectManagerMock->expects($this->once())
236 ->with(\
Magento\Framework\
View\DesignInterface::class)
238 $this->designMock->expects($this->once())
239 ->method(
'changeDesign')
242 $this->
object->detectDesign();
253 $this->designExceptionsMock->expects($this->once())
254 ->method(
'getThemeByRequest')
255 ->will($this->returnValue(
$value));
257 ->disableOriginalConstructor()
260 ->method(
'setDesignTheme');
261 $this->objectManagerMock->expects($this->once())
263 ->with(\
Magento\Framework\
View\DesignInterface::class)
265 $this->designMock->expects($this->exactly($callNum2))
266 ->method(
'loadChange')
267 ->with(self::SCOPE_ID)
269 $this->designMock->expects($this->exactly($callNum2))
270 ->method(
'changeDesign')
273 $requestMock = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
274 ->disableOriginalConstructor()
276 $this->
object->detectDesign($requestMock);
292 $exception = new \Exception(
'exception');
293 $this->designExceptionsMock->expects($this->once())
294 ->method(
'getThemeByRequest')
295 ->will($this->throwException($exception));
297 ->disableOriginalConstructor()
300 ->method(
'setDesignTheme');
301 $this->objectManagerMock->expects($this->once())
303 ->with(\
Magento\Framework\
View\DesignInterface::class)
305 $this->designMock->expects($this->once())
306 ->method(
'loadChange')
307 ->with(self::SCOPE_ID)
309 $this->designMock->expects($this->once())
310 ->method(
'changeDesign')
313 $requestMock = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
314 ->disableOriginalConstructor()
316 $this->loggerMock->expects($this->once())
319 $this->
object->detectDesign($requestMock);
detectDesignByRequestDataProvider()
testDetectDesignByRequestWithException()
static setRenderer(RendererInterface $renderer)
testDetectDesignByRequest($value, $callNum, $callNum2)