11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2013 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
@@ -62,12 +62,10 @@ protected function setUp(): void
6262 ->method ('get ' )
6363 ->with (ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME )
6464 ->willReturn ($ this ->_defaultFrontName );
65- $ this ->uri = $ this ->createMock (Uri::class);
66-
65+ $ this ->uri = $ this ->createPartialMock (Uri::class, ['parse ' ]);
6766 $ this ->request = $ this ->createMock (Http::class);
68-
6967 $ this ->configMock = $ this ->createMock (Config::class);
70- $ this ->scopeConfigMock = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
68+ $ this ->scopeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
7169 $ this ->model = new FrontNameResolver (
7270 $ this ->configMock ,
7371 $ deploymentConfigMock ,
@@ -111,6 +109,7 @@ public function testIfCustomPathNotUsed(): void
111109 /**
112110 * @param string $url
113111 * @param string|null $host
112+ * @param bool $isHttps
114113 * @param string $useCustomAdminUrl
115114 * @param string $customAdminUrl
116115 * @param bool $expectedValue
@@ -121,12 +120,12 @@ public function testIfCustomPathNotUsed(): void
121120 public function testIsHostBackend (
122121 string $ url ,
123122 ?string $ host ,
123+ bool $ isHttps ,
124124 string $ useCustomAdminUrl ,
125125 string $ customAdminUrl ,
126126 bool $ expectedValue
127127 ): void {
128- $ this ->scopeConfigMock ->expects ($ this ->exactly (2 ))
129- ->method ('getValue ' )
128+ $ this ->scopeConfigMock ->method ('getValue ' )
130129 ->willReturnMap (
131130 [
132131 [Store::XML_PATH_UNSECURE_BASE_URL , ScopeInterface::SCOPE_STORE , null , $ url ],
@@ -145,41 +144,24 @@ public function testIsHostBackend(
145144 ]
146145 );
147146
148- $ this ->request ->expects ($ this ->any ())
147+ $ this ->request ->expects ($ this ->atLeastOnce ())
149148 ->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+ ]
173153 );
174- $ this ->uri ->expects ($ this ->once ())
175- ->method ('getPort ' )
154+ $ this ->request ->method ('isSecure ' )
155+ ->willReturn ($ isHttps );
156+
157+ $ this ->uri ->method ('parse ' )
176158 ->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 ))
180162 );
181163
182- $ this ->assertEquals ($ this ->model ->isHostBackend (), $ expectedValue );
164+ $ this ->assertEquals ($ expectedValue , $ this ->model ->isHostBackend ());
183165 }
184166
185167 /**
@@ -192,11 +174,8 @@ public function testIsHostBackendWithEmptyHost(): void
192174 $ this ->request ->expects ($ this ->any ())
193175 ->method ('getServer ' )
194176 ->willReturn ('magento2.loc ' );
195- $ this ->uri ->expects ($ this ->once ())
196- ->method ('getHost ' )
197- ->willReturn (null );
198177
199- $ this ->assertEquals ($ this ->model ->isHostBackend (), false );
178+ $ this ->assertFalse ($ this ->model ->isHostBackend ());
200179 }
201180
202181 /**
@@ -208,62 +187,71 @@ public static function hostsDataProvider(): array
208187 'withoutPort ' => [
209188 'url ' => 'http://magento2.loc/ ' ,
210189 'host ' => 'magento2.loc ' ,
190+ 'isHttps ' => false ,
211191 'useCustomAdminUrl ' => '0 ' ,
212192 'customAdminUrl ' => '' ,
213193 'expectedValue ' => true
214194 ],
215195 'withPort ' => [
216196 'url ' => 'http://magento2.loc:8080/ ' ,
217197 'host ' => 'magento2.loc:8080 ' ,
198+ 'isHttps ' => false ,
218199 'useCustomAdminUrl ' => '0 ' ,
219200 'customAdminUrl ' => '' ,
220201 'expectedValue ' => true
221202 ],
222203 'withStandartPortInUrlWithoutPortInHost ' => [
223204 'url ' => 'http://magento2.loc:80/ ' ,
224205 'host ' => 'magento2.loc ' ,
206+ 'isHttps ' => false ,
225207 'useCustomAdminUrl ' => '0 ' ,
226208 'customAdminUrl ' => '' ,
227209 'expectedValue ' => true
228210 ],
229211 'withoutStandartPortInUrlWithPortInHost ' => [
230212 'url ' => 'https://magento2.loc/ ' ,
231213 'host ' => 'magento2.loc:443 ' ,
214+ 'isHttps ' => true ,
232215 'useCustomAdminUrl ' => '0 ' ,
233216 'customAdminUrl ' => '' ,
234217 'expectedValue ' => true
235218 ],
236219 'differentHosts ' => [
237220 'url ' => 'http://m2.loc/ ' ,
238221 'host ' => 'magento2.loc ' ,
222+ 'isHttps ' => false ,
239223 'useCustomAdminUrl ' => '0 ' ,
240224 'customAdminUrl ' => '' ,
241225 'expectedValue ' => false
242226 ],
243227 'differentPortsOnOneHost ' => [
244228 'url ' => 'http://magento2.loc/ ' ,
245229 'host ' => 'magento2.loc:8080 ' ,
230+ 'isHttps ' => false ,
246231 'useCustomAdminUrl ' => '0 ' ,
247232 'customAdminUrl ' => '' ,
248233 'expectedValue ' => false
249234 ],
250235 'withCustomAdminUrl ' => [
251236 'url ' => 'http://magento2.loc/ ' ,
252237 'host ' => 'myhost.loc ' ,
238+ 'isHttps ' => true ,
253239 'useCustomAdminUrl ' => '1 ' ,
254240 'customAdminUrl ' => 'https://myhost.loc/ ' ,
255241 'expectedValue ' => true
256242 ],
257243 'withCustomAdminUrlWrongHost ' => [
258244 'url ' => 'http://magento2.loc/ ' ,
259245 'host ' => 'SomeOtherHost.loc ' ,
246+ 'isHttps ' => false ,
260247 'useCustomAdminUrl ' => '1 ' ,
261248 'customAdminUrl ' => 'https://myhost.loc/ ' ,
262249 'expectedValue ' => false
263250 ],
264251 'withEmptyHost ' => [
265252 'url ' => 'http://magento2.loc/ ' ,
266253 'host ' => null ,
254+ 'isHttps ' => false ,
267255 'useCustomAdminUrl ' => '0 ' ,
268256 'customAdminUrl ' => '' ,
269257 'expectedValue ' => false
0 commit comments