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
@@ -62,12 +62,10 @@ protected function setUp(): void
62
62
->method ('get ' )
63
63
->with (ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME )
64
64
->willReturn ($ this ->_defaultFrontName );
65
- $ this ->uri = $ this ->createMock (Uri::class);
66
-
65
+ $ this ->uri = $ this ->createPartialMock (Uri::class, ['parse ' ]);
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,24 @@ 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 );
151
-
152
- $ urlParts = [];
153
- $ this ->uri ->expects ($ this ->once ())
154
- ->method ('parse ' )
155
- ->willReturnCallback (
156
- function ($ url ) use (&$ urlParts ) {
157
- $ urlParts = parse_url ($ url );
158
- }
159
- );
160
- $ this ->uri ->expects ($ this ->once ())
161
- ->method ('getScheme ' )
162
- ->willReturnCallback (
163
- function () use (&$ urlParts ) {
164
- return array_key_exists ('scheme ' , $ urlParts ) ? $ urlParts ['scheme ' ] : '' ;
165
- }
166
- );
167
- $ this ->uri ->expects ($ this ->once ())
168
- ->method ('getHost ' )
169
- ->willReturnCallback (
170
- function () use (&$ urlParts ) {
171
- return array_key_exists ('host ' , $ urlParts ) ? $ urlParts ['host ' ] : '' ;
172
- }
149
+ ->willReturnMap (
150
+ [
151
+ ['HTTP_HOST ' , null , $ host ],
152
+ ]
173
153
);
174
- $ this ->uri ->expects ($ this ->once ())
175
- ->method ('getPort ' )
154
+ $ this ->request ->method ('isSecure ' )
155
+ ->willReturn ($ isHttps );
156
+
157
+ $ this ->uri ->method ('parse ' )
176
158
->willReturnCallback (
177
- function () use (& $ urlParts ) {
178
- return array_key_exists ( ' port ' , $ urlParts ) ? $ urlParts [ ' port ' ] : '' ;
179
- }
159
+ fn ( $ url ) => $ this -> uri -> setScheme ( parse_url ( $ url , PHP_URL_SCHEME ))
160
+ -> setHost ( parse_url ( $ url , PHP_URL_HOST ))
161
+ -> setPort ( parse_url ( $ url , PHP_URL_PORT ))
180
162
);
181
163
182
- $ this ->assertEquals ($ this ->model ->isHostBackend (), $ expectedValue );
164
+ $ this ->assertEquals ($ expectedValue , $ this ->model ->isHostBackend ());
183
165
}
184
166
185
167
/**
@@ -192,11 +174,8 @@ public function testIsHostBackendWithEmptyHost(): void
192
174
$ this ->request ->expects ($ this ->any ())
193
175
->method ('getServer ' )
194
176
->willReturn ('magento2.loc ' );
195
- $ this ->uri ->expects ($ this ->once ())
196
- ->method ('getHost ' )
197
- ->willReturn (null );
198
177
199
- $ this ->assertEquals ($ this ->model ->isHostBackend (), false );
178
+ $ this ->assertFalse ($ this ->model ->isHostBackend ());
200
179
}
201
180
202
181
/**
@@ -208,62 +187,71 @@ public static function hostsDataProvider(): array
208
187
'withoutPort ' => [
209
188
'url ' => 'http://magento2.loc/ ' ,
210
189
'host ' => 'magento2.loc ' ,
190
+ 'isHttps ' => false ,
211
191
'useCustomAdminUrl ' => '0 ' ,
212
192
'customAdminUrl ' => '' ,
213
193
'expectedValue ' => true
214
194
],
215
195
'withPort ' => [
216
196
'url ' => 'http://magento2.loc:8080/ ' ,
217
197
'host ' => 'magento2.loc:8080 ' ,
198
+ 'isHttps ' => false ,
218
199
'useCustomAdminUrl ' => '0 ' ,
219
200
'customAdminUrl ' => '' ,
220
201
'expectedValue ' => true
221
202
],
222
203
'withStandartPortInUrlWithoutPortInHost ' => [
223
204
'url ' => 'http://magento2.loc:80/ ' ,
224
205
'host ' => 'magento2.loc ' ,
206
+ 'isHttps ' => false ,
225
207
'useCustomAdminUrl ' => '0 ' ,
226
208
'customAdminUrl ' => '' ,
227
209
'expectedValue ' => true
228
210
],
229
211
'withoutStandartPortInUrlWithPortInHost ' => [
230
212
'url ' => 'https://magento2.loc/ ' ,
231
213
'host ' => 'magento2.loc:443 ' ,
214
+ 'isHttps ' => true ,
232
215
'useCustomAdminUrl ' => '0 ' ,
233
216
'customAdminUrl ' => '' ,
234
217
'expectedValue ' => true
235
218
],
236
219
'differentHosts ' => [
237
220
'url ' => 'http://m2.loc/ ' ,
238
221
'host ' => 'magento2.loc ' ,
222
+ 'isHttps ' => false ,
239
223
'useCustomAdminUrl ' => '0 ' ,
240
224
'customAdminUrl ' => '' ,
241
225
'expectedValue ' => false
242
226
],
243
227
'differentPortsOnOneHost ' => [
244
228
'url ' => 'http://magento2.loc/ ' ,
245
229
'host ' => 'magento2.loc:8080 ' ,
230
+ 'isHttps ' => false ,
246
231
'useCustomAdminUrl ' => '0 ' ,
247
232
'customAdminUrl ' => '' ,
248
233
'expectedValue ' => false
249
234
],
250
235
'withCustomAdminUrl ' => [
251
236
'url ' => 'http://magento2.loc/ ' ,
252
237
'host ' => 'myhost.loc ' ,
238
+ 'isHttps ' => true ,
253
239
'useCustomAdminUrl ' => '1 ' ,
254
240
'customAdminUrl ' => 'https://myhost.loc/ ' ,
255
241
'expectedValue ' => true
256
242
],
257
243
'withCustomAdminUrlWrongHost ' => [
258
244
'url ' => 'http://magento2.loc/ ' ,
259
245
'host ' => 'SomeOtherHost.loc ' ,
246
+ 'isHttps ' => false ,
260
247
'useCustomAdminUrl ' => '1 ' ,
261
248
'customAdminUrl ' => 'https://myhost.loc/ ' ,
262
249
'expectedValue ' => false
263
250
],
264
251
'withEmptyHost ' => [
265
252
'url ' => 'http://magento2.loc/ ' ,
266
253
'host ' => null ,
254
+ 'isHttps ' => false ,
267
255
'useCustomAdminUrl ' => '0 ' ,
268
256
'customAdminUrl ' => '' ,
269
257
'expectedValue ' => false
0 commit comments