-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathDesignExceptionsTest.php
84 lines (70 loc) · 2.79 KB
/
DesignExceptionsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Test\Unit;
use Magento\Framework\Test\Unit\TestFramework\Helper\ObjectManager as ObjectManagerHelper;
class DesignExceptionsTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Framework\View\DesignExceptions */
protected $designExceptions;
/** @var ObjectManagerHelper */
protected $objectManagerHelper;
/** @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $scopeConfigMock;
/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $requestMock;
/** @var string */
protected $exceptionConfigPath = 'exception_path';
/** @var string */
protected $scopeType = 'scope_type';
protected function setUp()
{
$this->scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
$this->requestMock = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false);
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->designExceptions = $this->objectManagerHelper->getObject(
'Magento\Framework\View\DesignExceptions',
[
'scopeConfig' => $this->scopeConfigMock,
'exceptionConfigPath' => $this->exceptionConfigPath,
'scopeType' => $this->scopeType
]
);
}
/**
* @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));
}
/**
* @return array
*/
public function getThemeByRequestDataProvider()
{
return [
[false, false, false],
['iphone', false, false],
['iphone', true, false],
['iphone', true, 'matched', [['regexp' => '/iphone/', 'value' => 'matched']]],
['explorer', true, false, [['regexp' => '/iphone/', 'value' => 'matched']]],
];
}
}