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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Test\Unit\Model;
use Magento\Backend\Model\AdminPathConfig;
use Magento\Store\Model\Store;
class AdminPathConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $coreConfig;
/**
* @var \Magento\Backend\App\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $backendConfig;
/**
* @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $url;
/**
* @var AdminPathConfig
*/
protected $adminPathConfig;
protected function setUp()
{
$this->coreConfig = $this->getMockForAbstractClass(
\Magento\Framework\App\Config\ScopeConfigInterface::class,
[],
'',
false
);
$this->backendConfig = $this->getMockForAbstractClass(
\Magento\Backend\App\ConfigInterface::class,
[],
'',
false
);
$this->url = $this->getMockForAbstractClass(
\Magento\Framework\UrlInterface::class,
[],
'',
false,
true,
true,
['getBaseUrl']
);
$this->adminPathConfig = new AdminPathConfig($this->coreConfig, $this->backendConfig, $this->url);
}
public function testGetCurrentSecureUrl()
{
$request = $this->getMockForAbstractClass(
\Magento\Framework\App\RequestInterface::class,
[],
'',
false,
true,
true,
['getPathInfo']
);
$request->expects($this->once())->method('getPathInfo')->willReturn('/info');
$this->url->expects($this->once())->method('getBaseUrl')->with('link', true)->willReturn('localhost/');
$this->assertEquals('localhost/info', $this->adminPathConfig->getCurrentSecureUrl($request));
}
/**
* @param $unsecureBaseUrl
* @param $useSecureInAdmin
* @param $secureBaseUrl
* @param $useCustomUrl
* @param $customUrl
* @param $expected
* @dataProvider shouldBeSecureDataProvider
*/
public function testShouldBeSecure(
$unsecureBaseUrl,
$useSecureInAdmin,
$secureBaseUrl,
$useCustomUrl,
$customUrl,
$expected
) {
$coreConfigValueMap = $this->returnValueMap([
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl],
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl],
['admin/url/custom', 'default', null, $customUrl],
]);
$backendConfigFlagsMap = $this->returnValueMap([
[\Magento\Store\Model\Store::XML_PATH_SECURE_IN_ADMINHTML, $useSecureInAdmin],
['admin/url/use_custom', $useCustomUrl],
]);
$this->coreConfig->expects($this->atLeast(1))->method('getValue')
->will($coreConfigValueMap);
$this->coreConfig->expects($this->atMost(2))->method('getValue')
->will($coreConfigValueMap);
$this->backendConfig->expects($this->atMost(2))->method('isSetFlag')
->will($backendConfigFlagsMap);
$this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure(''));
}
/**
* @return array
*/
public function shouldBeSecureDataProvider()
{
return [
['http://localhost/', false, 'default', false, '', false],
['http://localhost/', true, 'default', false, '', false],
['https://localhost/', false, 'default', false, '', true],
['https://localhost/', true, 'default', false, '', true],
['http://localhost/', false, 'https://localhost/', false, '', false],
['http://localhost/', true, 'https://localhost/', false, '', true],
['https://localhost/', true, 'https://localhost/', false, '', true],
];
}
public function testGetDefaultPath()
{
$this->backendConfig->expects($this->once())
->method('getValue')
->with('web/default/admin')
->willReturn('default/path');
$this->assertEquals('default/path', $this->adminPathConfig->getDefaultPath());
}
}