7
7
8
8
use Magento \Backend \App \Area \FrontNameResolver ;
9
9
use Magento \Backend \Setup \ConfigOptionsList ;
10
+ use Magento \Framework \App \DeploymentConfig ;
11
+ use Magento \Store \Model \ScopeInterface ;
12
+ use Magento \Store \Model \Store ;
10
13
11
14
class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
12
15
{
13
16
/**
14
17
* @var \Magento\Backend\App\Area\FrontNameResolver
15
18
*/
16
- protected $ _model ;
19
+ protected $ model ;
17
20
18
21
/**
19
- * @var \PHPUnit_Framework_MockObject_MockObject
22
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\Config
20
23
*/
21
- protected $ _configMock ;
24
+ protected $ configMock ;
25
+
26
+ /**
27
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
28
+ */
29
+ protected $ scopeConfigMock ;
22
30
23
31
/**
24
32
* @var string
@@ -27,19 +35,20 @@ class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
27
35
28
36
protected function setUp ()
29
37
{
30
- $ deploymentConfigMock = $ this ->getMock ('\Magento\Framework\App\DeploymentConfig ' , [], [], '' , false );
38
+ /** @var \PHPUnit_Framework_MockObject_MockObject|DeploymentConfig $deploymentConfigMock */
39
+ $ deploymentConfigMock = $ this ->getMock ('Magento\Framework\App\DeploymentConfig ' , [], [], '' , false );
31
40
$ deploymentConfigMock ->expects ($ this ->once ())
32
41
->method ('get ' )
33
42
->with (ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME )
34
43
->will ($ this ->returnValue ($ this ->_defaultFrontName ));
35
- $ this ->_configMock = $ this ->getMock ('\ Magento\Backend\App\Config ' , [], [], '' , false );
36
- $ configMock = $ this ->getMock ('\ Magento\Framework\App\Config\ScopeConfigInterface ' , [], [], '' , false );
37
- $ this ->_model = new FrontNameResolver ($ this ->_configMock , $ deploymentConfigMock , $ configMock );
44
+ $ this ->configMock = $ this ->getMock ('Magento\Backend\App\Config ' , [], [], '' , false );
45
+ $ this -> scopeConfigMock = $ this ->getMock ('Magento\Framework\App\Config\ScopeConfigInterface ' , [], [], '' , false );
46
+ $ this ->model = new FrontNameResolver ($ this ->configMock , $ deploymentConfigMock , $ this -> scopeConfigMock );
38
47
}
39
48
40
49
public function testIfCustomPathUsed ()
41
50
{
42
- $ this ->_configMock ->expects (
51
+ $ this ->configMock ->expects (
43
52
$ this ->at (0 )
44
53
)->method (
45
54
'getValue '
@@ -48,7 +57,7 @@ public function testIfCustomPathUsed()
48
57
)->will (
49
58
$ this ->returnValue (true )
50
59
);
51
- $ this ->_configMock ->expects (
60
+ $ this ->configMock ->expects (
52
61
$ this ->at (1 )
53
62
)->method (
54
63
'getValue '
@@ -57,12 +66,12 @@ public function testIfCustomPathUsed()
57
66
)->will (
58
67
$ this ->returnValue ('expectedValue ' )
59
68
);
60
- $ this ->assertEquals ('expectedValue ' , $ this ->_model ->getFrontName ());
69
+ $ this ->assertEquals ('expectedValue ' , $ this ->model ->getFrontName ());
61
70
}
62
71
63
72
public function testIfCustomPathNotUsed ()
64
73
{
65
- $ this ->_configMock ->expects (
74
+ $ this ->configMock ->expects (
66
75
$ this ->once ()
67
76
)->method (
68
77
'getValue '
@@ -71,6 +80,58 @@ public function testIfCustomPathNotUsed()
71
80
)->will (
72
81
$ this ->returnValue (false )
73
82
);
74
- $ this ->assertEquals ($ this ->_defaultFrontName , $ this ->_model ->getFrontName ());
83
+ $ this ->assertEquals ($ this ->_defaultFrontName , $ this ->model ->getFrontName ());
84
+ }
85
+
86
+ /**
87
+ * @param $url
88
+ * @param $host
89
+ * @dataProvider hostsDataProvider
90
+ */
91
+ public function testIsHostBackend ($ url , $ host , $ expectedValue )
92
+ {
93
+ $ backendUrl = $ url ;
94
+ $ _SERVER ['HTTP_HOST ' ] = $ host ;
95
+ $ this ->scopeConfigMock ->expects ($ this ->once ())
96
+ ->method ('getValue ' )
97
+ ->with (Store::XML_PATH_UNSECURE_BASE_URL , ScopeInterface::SCOPE_STORE )
98
+ ->willReturn ($ backendUrl );
99
+ $ this ->assertEquals ($ this ->model ->isHostBackend (), $ expectedValue );
100
+ }
101
+
102
+ public function hostsDataProvider ()
103
+ {
104
+ return [
105
+ 'withoutPort ' => [
106
+ 'url ' => 'http://magento2.loc/ ' ,
107
+ 'host ' => 'magento2.loc ' ,
108
+ 'expectedValue ' => true
109
+ ],
110
+ 'withPort ' => [
111
+ 'url ' => 'http://magento2.loc:8080/ ' ,
112
+ 'host ' => 'magento2.loc:8080 ' ,
113
+ 'expectedValue ' => true
114
+ ],
115
+ 'withStandartPortInUrlWithoutPortInHost ' => [
116
+ 'url ' => 'http://magento2.loc:80/ ' ,
117
+ 'host ' => 'magento2.loc ' ,
118
+ 'expectedValue ' => true
119
+ ],
120
+ 'withoutStandartPortInUrlWithPortInHost ' => [
121
+ 'url ' => 'https://magento2.loc/ ' ,
122
+ 'host ' => 'magento2.loc:443 ' ,
123
+ 'expectedValue ' => true
124
+ ],
125
+ 'differentHosts ' => [
126
+ 'url ' => 'http://m2.loc/ ' ,
127
+ 'host ' => 'magento2.loc ' ,
128
+ 'expectedValue ' => false
129
+ ],
130
+ 'differentPortsOnOneHost ' => [
131
+ 'url ' => 'http://magento2.loc/ ' ,
132
+ 'host ' => 'magento2.loc:8080 ' ,
133
+ 'expectedValue ' => false
134
+ ]
135
+ ];
75
136
}
76
137
}
0 commit comments