/** * @param string $userAgent * @param bool $useConfig * @param bool|string $result * @param array $expressions * @dataProvider getThemeByRequestDataProvider */ public function testGetThemeByRequest($userAgent, $useConfig, $result, $expressions = []) { $this->requestMock->expects($this->once())->method('getServer')->with($this->equalTo('HTTP_USER_AGENT'))->will($this->returnValue($userAgent)); if ($useConfig) { $this->scopeConfigMock->expects($this->once())->method('getValue')->with($this->equalTo($this->exceptionConfigPath), $this->equalTo($this->scopeType))->will($this->returnValue(serialize($expressions))); } $this->assertSame($result, $this->designExceptions->getThemeByRequest($this->requestMock)); }
/** * Test of adding design exceptions to the kay of cache hash * * @param string $cacheType * @param bool $isPageCacheEnabled * @param string|false $result * @param string $uaException * @param string $expected * @dataProvider testAfterGetValueDataProvider */ public function testAfterGetValue($cacheType, $isPageCacheEnabled, $result, $uaException, $expected) { $identifierMock = $this->getMock('Magento\\Framework\\App\\PageCache\\Identifier', [], [], '', false); $this->pageCacheConfigMock->expects($this->once())->method('getType')->will($this->returnValue($cacheType)); $this->pageCacheConfigMock->expects($this->any())->method('isEnabled')->will($this->returnValue($isPageCacheEnabled)); $this->designExceptionsMock->expects($this->any())->method('getThemeByRequest')->will($this->returnValue($uaException)); $this->assertEquals($expected, $this->plugin->afterGetValue($identifierMock, $result)); }
/** * Analyze user-agent information to override custom design settings * * @param \Magento\Framework\App\RequestInterface $request * @return bool */ protected function _applyUserAgentDesignException($request) { try { $theme = $this->_designExceptions->getThemeByRequest($request); if (false !== $theme) { $this->_getDesign()->setDesignTheme($theme); return true; } } catch (\Exception $e) { $this->_logger->critical($e); } return false; }