1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2013 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
@@ -63,11 +63,9 @@ protected function setUp(): void
63
63
->with (ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME )
64
64
->willReturn ($ this ->_defaultFrontName );
65
65
$ this ->uri = $ this ->createMock (Uri::class);
66
-
67
66
$ this ->request = $ this ->createMock (Http::class);
68
-
69
67
$ this ->configMock = $ this ->createMock (Config::class);
70
- $ this ->scopeConfigMock = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
68
+ $ this ->scopeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
71
69
$ this ->model = new FrontNameResolver (
72
70
$ this ->configMock ,
73
71
$ deploymentConfigMock ,
@@ -111,6 +109,7 @@ public function testIfCustomPathNotUsed(): void
111
109
/**
112
110
* @param string $url
113
111
* @param string|null $host
112
+ * @param bool $isHttps
114
113
* @param string $useCustomAdminUrl
115
114
* @param string $customAdminUrl
116
115
* @param bool $expectedValue
@@ -121,12 +120,12 @@ public function testIfCustomPathNotUsed(): void
121
120
public function testIsHostBackend (
122
121
string $ url ,
123
122
?string $ host ,
123
+ bool $ isHttps ,
124
124
string $ useCustomAdminUrl ,
125
125
string $ customAdminUrl ,
126
126
bool $ expectedValue
127
127
): void {
128
- $ this ->scopeConfigMock ->expects ($ this ->exactly (2 ))
129
- ->method ('getValue ' )
128
+ $ this ->scopeConfigMock ->method ('getValue ' )
130
129
->willReturnMap (
131
130
[
132
131
[Store::XML_PATH_UNSECURE_BASE_URL , ScopeInterface::SCOPE_STORE , null , $ url ],
@@ -145,41 +144,42 @@ public function testIsHostBackend(
145
144
]
146
145
);
147
146
148
- $ this ->request ->expects ($ this ->any ())
147
+ $ this ->request ->expects ($ this ->atLeastOnce ())
149
148
->method ('getServer ' )
150
- ->willReturn ($ host );
149
+ ->willReturnMap (
150
+ [
151
+ ['HTTP_HOST ' , null , $ host ],
152
+ ['REQUEST_SCHEME ' , null , $ isHttps ? 'https ' : 'http ' ],
153
+ ]
154
+ );
151
155
152
156
$ urlParts = [];
153
- $ this ->uri ->expects ($ this ->once ())
154
- ->method ('parse ' )
157
+ $ this ->uri ->method ('parse ' )
155
158
->willReturnCallback (
156
159
function ($ url ) use (&$ urlParts ) {
157
160
$ urlParts = parse_url ($ url );
158
161
}
159
162
);
160
- $ this ->uri ->expects ($ this ->once ())
161
- ->method ('getScheme ' )
163
+ $ this ->uri ->method ('getScheme ' )
162
164
->willReturnCallback (
163
165
function () use (&$ urlParts ) {
164
166
return array_key_exists ('scheme ' , $ urlParts ) ? $ urlParts ['scheme ' ] : '' ;
165
167
}
166
168
);
167
- $ this ->uri ->expects ($ this ->once ())
168
- ->method ('getHost ' )
169
+ $ this ->uri ->method ('getHost ' )
169
170
->willReturnCallback (
170
171
function () use (&$ urlParts ) {
171
172
return array_key_exists ('host ' , $ urlParts ) ? $ urlParts ['host ' ] : '' ;
172
173
}
173
174
);
174
- $ this ->uri ->expects ($ this ->once ())
175
- ->method ('getPort ' )
175
+ $ this ->uri ->method ('getPort ' )
176
176
->willReturnCallback (
177
177
function () use (&$ urlParts ) {
178
178
return array_key_exists ('port ' , $ urlParts ) ? $ urlParts ['port ' ] : '' ;
179
179
}
180
180
);
181
181
182
- $ this ->assertEquals ($ this ->model ->isHostBackend (), $ expectedValue );
182
+ $ this ->assertEquals ($ expectedValue , $ this ->model ->isHostBackend ());
183
183
}
184
184
185
185
/**
@@ -208,62 +208,71 @@ public static function hostsDataProvider(): array
208
208
'withoutPort ' => [
209
209
'url ' => 'http://magento2.loc/ ' ,
210
210
'host ' => 'magento2.loc ' ,
211
+ 'isHttps ' => false ,
211
212
'useCustomAdminUrl ' => '0 ' ,
212
213
'customAdminUrl ' => '' ,
213
214
'expectedValue ' => true
214
215
],
215
216
'withPort ' => [
216
217
'url ' => 'http://magento2.loc:8080/ ' ,
217
218
'host ' => 'magento2.loc:8080 ' ,
219
+ 'isHttps ' => false ,
218
220
'useCustomAdminUrl ' => '0 ' ,
219
221
'customAdminUrl ' => '' ,
220
222
'expectedValue ' => true
221
223
],
222
224
'withStandartPortInUrlWithoutPortInHost ' => [
223
225
'url ' => 'http://magento2.loc:80/ ' ,
224
226
'host ' => 'magento2.loc ' ,
227
+ 'isHttps ' => false ,
225
228
'useCustomAdminUrl ' => '0 ' ,
226
229
'customAdminUrl ' => '' ,
227
230
'expectedValue ' => true
228
231
],
229
232
'withoutStandartPortInUrlWithPortInHost ' => [
230
233
'url ' => 'https://magento2.loc/ ' ,
231
- 'host ' => 'magento2.loc:443 ' ,
234
+ 'host ' => 'magento2.loc ' ,
235
+ 'isHttps ' => true ,
232
236
'useCustomAdminUrl ' => '0 ' ,
233
237
'customAdminUrl ' => '' ,
234
238
'expectedValue ' => true
235
239
],
236
240
'differentHosts ' => [
237
241
'url ' => 'http://m2.loc/ ' ,
238
242
'host ' => 'magento2.loc ' ,
243
+ 'isHttps ' => false ,
239
244
'useCustomAdminUrl ' => '0 ' ,
240
245
'customAdminUrl ' => '' ,
241
246
'expectedValue ' => false
242
247
],
243
248
'differentPortsOnOneHost ' => [
244
249
'url ' => 'http://magento2.loc/ ' ,
245
250
'host ' => 'magento2.loc:8080 ' ,
251
+ 'isHttps ' => false ,
246
252
'useCustomAdminUrl ' => '0 ' ,
247
253
'customAdminUrl ' => '' ,
248
254
'expectedValue ' => false
249
255
],
250
256
'withCustomAdminUrl ' => [
251
257
'url ' => 'http://magento2.loc/ ' ,
252
258
'host ' => 'myhost.loc ' ,
259
+ 'isHttps ' => true ,
253
260
'useCustomAdminUrl ' => '1 ' ,
254
261
'customAdminUrl ' => 'https://myhost.loc/ ' ,
255
262
'expectedValue ' => true
256
263
],
257
264
'withCustomAdminUrlWrongHost ' => [
258
265
'url ' => 'http://magento2.loc/ ' ,
259
266
'host ' => 'SomeOtherHost.loc ' ,
267
+ 'isHttps ' => false ,
260
268
'useCustomAdminUrl ' => '1 ' ,
261
269
'customAdminUrl ' => 'https://myhost.loc/ ' ,
262
270
'expectedValue ' => false
263
271
],
264
272
'withEmptyHost ' => [
265
273
'url ' => 'http://magento2.loc/ ' ,
266
274
'host ' => null ,
275
+ 'isHttps ' => false ,
267
276
'useCustomAdminUrl ' => '0 ' ,
268
277
'customAdminUrl ' => '' ,
269
278
'expectedValue ' => false
0 commit comments