Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DesignExceptionsTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class DesignExceptionsTest extends \PHPUnit\Framework\TestCase
13 {
15  private $designExceptions;
16 
18  private $objectManagerHelper;
19 
21  private $scopeConfigMock;
22 
24  private $requestMock;
25 
27  private $exceptionConfigPath = 'exception_path';
28 
30  private $scopeType = 'scope_type';
31 
33  private $serializerMock;
34 
35  protected function setUp()
36  {
37  $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
38  $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
39  $this->serializerMock = $this->createMock(Json::class);
40 
41  $this->objectManagerHelper = new ObjectManagerHelper($this);
42  $this->designExceptions = $this->objectManagerHelper->getObject(
43  \Magento\Framework\View\DesignExceptions::class,
44  [
45  'scopeConfig' => $this->scopeConfigMock,
46  'exceptionConfigPath' => $this->exceptionConfigPath,
47  'scopeType' => $this->scopeType,
48  'serializer' => $this->serializerMock,
49  ]
50  );
51  }
52 
61  public function testGetThemeByRequest($userAgent, $configValue, $callNum, $result, $expressions = [])
62  {
63  $this->requestMock->expects($this->once())
64  ->method('getServer')
65  ->with($this->equalTo('HTTP_USER_AGENT'))
66  ->will($this->returnValue($userAgent));
67 
68  if ($userAgent) {
69  $this->scopeConfigMock->expects($this->once())
70  ->method('getValue')
71  ->with($this->equalTo($this->exceptionConfigPath), $this->equalTo($this->scopeType))
72  ->will($this->returnValue($configValue));
73  }
74 
75  $this->serializerMock->expects($this->exactly($callNum))
76  ->method('unserialize')
77  ->with($configValue)
78  ->willReturn($expressions);
79 
80  $this->assertSame($result, $this->designExceptions->getThemeByRequest($this->requestMock));
81  }
82 
87  {
88  return [
89  [false, null, 0, false],
90  ['iphone', null, 0, false],
91  ['iphone', 'serializedExpressions1', 1, false],
92  ['iphone', 'serializedExpressions2', 1, 'matched', [['regexp' => '/iphone/', 'value' => 'matched']]],
93  ['explorer', 'serializedExpressions3', 1, false, [['regexp' => '/iphone/', 'value' => 'matched']]],
94  ];
95  }
96 }
testGetThemeByRequest($userAgent, $configValue, $callNum, $result, $expressions=[])
$expressions
Definition: side-menu.phtml:10