44 private $urlModifierMock;
51 $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
52 $this->requestMock = $this->createPartialMock(\
Magento\Framework\
App\Request\Http::class, [
64 $this->filesystemMock = $this->getMockBuilder(\
Magento\Framework\Filesystem::class)
65 ->disableOriginalConstructor()
67 $this->store = $this->objectManagerHelper->getObject(
69 [
'filesystem' => $this->filesystemMock]
72 $this->urlModifierMock = $this->createMock(\
Magento\Framework\Url\ModifierInterface::class);
73 $this->urlModifierMock->expects($this->any())
75 ->willReturnArgument(0);
84 public function testLoad($key, $field)
89 [
'load',
'getIdFieldName',
'__wakeup']
91 $resource->expects($this->atLeastOnce())->method(
'load')
92 ->with($this->isInstanceOf(\
Magento\
Store\Model\Store::class), $this->equalTo($key), $this->equalTo($field))
93 ->will($this->returnSelf());
94 $resource->expects($this->atLeastOnce())->method(
'getIdFieldName')->will($this->returnValue(
'store_id'));
114 public function testSetWebsite()
116 $website = $this->createPartialMock(\
Magento\
Store\Model\Website::class, [
'getId',
'__wakeup']);
117 $website->expects($this->atLeastOnce())->method(
'getId')->will($this->returnValue(2));
121 $this->assertEquals(2,
$model->getWebsiteId());
127 public function testGetWebsite()
130 $website = $this->createMock(\
Magento\Store\Api\Data\WebsiteInterface::class);
133 ->setMethods([
'getById'])
134 ->getMockForAbstractClass();
141 $model = $this->objectManagerHelper->getObject(
142 \
Magento\Store\Model\Store::class,
153 public function testGetWebsiteIfWebsiteIsNotExist()
156 ->setMethods([
'getById'])
157 ->getMockForAbstractClass();
162 $model = $this->objectManagerHelper->getObject(
163 \
Magento\Store\Model\Store::class,
166 $model->setWebsiteId(
null);
168 $this->assertFalse(
$model->getWebsite());
174 public function testGetGroup()
177 $group = $this->createMock(\
Magento\Store\Api\Data\GroupInterface::class);
180 ->setMethods([
'get'])
181 ->getMockForAbstractClass();
188 $model = $this->objectManagerHelper->getObject(
189 \
Magento\Store\Model\Store::class,
200 public function testGetGroupIfGroupIsNotExist()
203 ->setMethods([
'getById'])
204 ->getMockForAbstractClass();
209 $model = $this->objectManagerHelper->getObject(
210 \
Magento\Store\Model\Store::class,
215 $this->assertFalse(
$model->getGroup());
221 public function testGetUrl()
223 $params = [
'_scope_to_url' =>
true];
224 $defaultStore = $this->createPartialMock(\
Magento\Store\Model\Store::class, [
'getId',
'__wakeup']);
225 $defaultStore->expects($this->atLeastOnce())->method(
'getId')->will($this->returnValue(5));
227 $url = $this->getMockForAbstractClass(\
Magento\Framework\UrlInterface::class);
228 $url->expects($this->atLeastOnce())->method(
'setScope')->will($this->returnSelf());
229 $url->expects($this->atLeastOnce())->method(
'getUrl')
230 ->with($this->equalTo(
'test/route'), $this->equalTo(
$params))
231 ->will($this->returnValue(
'http://test/url'));
233 $storeManager = $this->getMockForAbstractClass(\
Magento\Store\Model\StoreManagerInterface::class);
236 ->will($this->returnValue($defaultStore));
239 $model = $this->objectManagerHelper->getObject(
240 \
Magento\Store\Model\Store::class,
244 $this->assertEquals(
'http://test/url',
$model->getUrl(
'test/route'));
260 public function testGetBaseUrl(
$type, $secure, $expectedPath, $expectedBaseUrl)
262 $this->requestMock->expects($this->any())
263 ->method(
'getDistroBaseUrl')
264 ->will($this->returnValue(
'http://distro.com/'));
267 $configMock = $this->getMockForAbstractClass(\
Magento\Framework\
App\Config\ReinitableConfigInterface::class);
268 $configMock->expects($this->atLeastOnce())
270 ->will($this->returnCallback(
271 function (
$path, $scope, $scopeCode) use ($secure, $expectedPath) {
272 $url = $secure ?
'{{base_url}}' :
'http://domain.com/';
277 $model = $this->objectManagerHelper->getObject(
278 \
Magento\Store\Model\Store::class,
280 'config' => $configMock,
281 'request' => $this->requestMock,
282 'isCustomEntryPoint' => !$secure,
285 $model->setCode(
'scopeCode');
287 $this->setUrlModifier(
$model);
289 $this->assertEquals($expectedBaseUrl,
$model->getBaseUrl(
$type, $secure));
301 'web/unsecure/base_url',
302 'http://domain.com/web/unsecure/base_url/' 307 'web/unsecure/base_link_url',
308 'http://domain.com/web/unsecure/base_link_url/index.php/' 313 'web/unsecure/base_link_url',
314 'http://domain.com/web/unsecure/base_link_url/index.php/' 319 'web/unsecure/base_media_url',
320 'http://domain.com/web/unsecure/base_media_url/' 325 'web/unsecure/base_static_url',
326 'http://domain.com/web/unsecure/base_static_url/' 331 'web/unsecure/base_url',
332 'http://domain.com/web/unsecure/base_url/' 337 'web/unsecure/base_url',
338 'http://domain.com/web/unsecure/base_url/' 343 'web/secure/base_url',
344 'http://distro.com/web/secure/base_url/' 352 public function testGetBaseUrlEntryPoint()
354 $expectedPath =
'web/unsecure/base_link_url';
355 $expectedBaseUrl =
'http://domain.com/web/unsecure/base_link_url/test_script.php/';
357 $configMock = $this->getMockForAbstractClass(\
Magento\Framework\
App\
Config\ReinitableConfigInterface::class);
358 $configMock->expects($this->atLeastOnce())
360 ->will($this->returnCallback(
361 function (
$path, $scope, $scopeCode) use ($expectedPath) {
362 return $expectedPath ==
$path ?
'http://domain.com/' .
$path .
'/' :
null;
366 $model = $this->objectManagerHelper->getObject(
367 \
Magento\Store\Model\Store::class,
369 'config' => $configMock,
370 'isCustomEntryPoint' =>
false,
373 $model->setCode(
'scopeCode');
375 $this->setUrlModifier(
$model);
378 $_SERVER[
'SCRIPT_FILENAME'] =
'test_script.php';
381 $model->getBaseUrl(\
Magento\Framework\UrlInterface::URL_TYPE_LINK,
false)
389 public function testGetBaseUrlWrongType()
392 $model = $this->objectManagerHelper->getObject(
393 \
Magento\Store\Model\Store::class
395 $model->getBaseUrl(
'unexpected url type');
406 public function testGetCurrentUrl($secure,
$url, $expected, $fromStore)
408 $defaultStore = $this->createPartialMock(Store::class, [
413 $defaultStore->expects($this->atLeastOnce())->method(
'getId')->will($this->returnValue(5));
414 $defaultStore->expects($this->atLeastOnce())->method(
'isCurrentlySecure')->will($this->returnValue($secure));
416 $sidResolver = $this->getMockForAbstractClass(\
Magento\Framework\Session\SidResolverInterface::class);
417 $sidResolver->expects($this->any())->method(
'getSessionIdQueryParam')->will($this->returnValue(
'SID'));
419 $config = $this->getMockForAbstractClass(\
Magento\Framework\
App\Config\ReinitableConfigInterface::class);
421 $requestString = preg_replace(
422 '/http(s?)\:\/\/[a-z0-9\-]+\//i',
427 ->expects($this->atLeastOnce())
428 ->method(
'getRequestString')
429 ->willReturn($requestString);
430 $this->requestMock->expects($this->atLeastOnce())->method(
'getQueryValue')->will($this->returnValue([
434 $urlMock = $this->getMockForAbstractClass(\
Magento\Framework\UrlInterface::class);
436 ->expects($this->atLeastOnce())
438 ->will($this->returnSelf());
439 $urlMock->expects($this->any())
441 ->will($this->returnValue(str_replace($requestString,
'',
$url)));
443 ->expects($this->atLeastOnce())
445 ->willReturnArgument(0);
447 $storeManager = $this->getMockForAbstractClass(\
Magento\Store\Model\StoreManagerInterface::class);
450 ->will($this->returnValue($defaultStore));
453 $model = $this->objectManagerHelper->getObject(
454 \
Magento\Store\Model\Store::class,
455 [
'storeManager' =>
$storeManager,
'url' => $urlMock,
'request' => $this->requestMock,
'config' =>
$config]
458 $model->setCode(
'scope_code');
460 $this->assertEquals($expected,
$model->getCurrentUrl($fromStore));
472 'http://test/url?SID=sid&___store=scope_code',
477 'http://test/url?SID=sid1&___store=scope',
478 'http://test/url?SID=sid&___store=scope_code',
484 'https://test/url?SID=sid&___store=scope_code',
489 'http://test/u/u.2?___store=scope_code',
491 .
'___store=scope_code&SID=sid&___from_store=old-store',
503 public function testGetBaseCurrency($priceScope, $currencyCode)
509 ->will($this->returnValueMap([
512 \
Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
518 \
Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
525 $currency = $this->createMock(\
Magento\Directory\Model\Currency::class);
526 $currency->expects($this->any())->method(
'load')->with($currencyCode)->will($this->returnSelf());
528 $currencyFactory = $this->createPartialMock(\
Magento\Directory\Model\CurrencyFactory::class, [
'create']);
529 $currencyFactory->expects($this->any())->method(
'create')->will($this->returnValue($currency));
531 $appState = $this->createPartialMock(\
Magento\Framework\
App\State::class, [
'isInstalled']);
532 $appState->expects($this->any())->method(
'isInstalled')->will($this->returnValue(
true));
534 $model = $this->objectManagerHelper->getObject(
536 [
'currencyFactory' => $currencyFactory,
'config' =>
$config,
'appState' => $appState]
538 $model->setCode(
'scope_code');
539 $this->assertEquals($currency,
$model->getBaseCurrency());
556 public function testGetAllowedCurrencies()
558 $currencyPath =
'cur/ren/cy/path';
559 $expectedResult = [
'EUR',
'USD'];
561 $configMock = $this->getMockForAbstractClass(
567 $configMock->expects($this->once())
569 ->with($currencyPath,
'store',
null)
570 ->will($this->returnValue(
'EUR,USD'));
573 $model = $this->objectManagerHelper->getObject(
575 [
'config' => $configMock,
'currencyInstalled' => $currencyPath,]
578 $this->assertEquals($expectedResult,
$model->getAllowedCurrencies());
590 public function testIsCurrentlySecure(
593 $requestSecure =
false,
594 $useSecureInFrontend =
true,
595 $secureBaseUrl =
'https://example.com:443' 598 $configMock = $this->getMockForAbstractClass(\
Magento\Framework\
App\Config\ReinitableConfigInterface::class);
599 $configMock->expects($this->any())
601 ->will($this->returnValueMap([
616 $this->requestMock->expects($this->any())
618 ->willReturn($requestSecure);
620 $this->requestMock->expects($this->any())
621 ->method(
'getServer')
622 ->with($this->equalTo(
'SERVER_PORT'))
626 $model = $this->objectManagerHelper->getObject(
627 \
Magento\Store\Model\Store::class,
628 [
'config' => $configMock,
'request' => $this->requestMock]
632 $this->assertTrue(
$model->isCurrentlySecure(),
"Was expecting this test to show as secure, but it wasn't");
634 $this->assertFalse(
$model->isCurrentlySecure(),
"Was expecting this test to show as not secure!");
644 'secure request, no server setting' => [
true, [],
true],
645 'unsecure request, using registered port' => [
true, 443],
646 'unsecure request, no secure base url registered' => [
false, 443,
false,
true,
null],
647 'unsecure request, not using registered port' => [
false, 80],
648 'unsecure request, using registered port, not using secure in frontend' => [
false, 443,
false,
false],
649 'unsecure request, no secure base url registered, not using secure in frontend' =>
650 [
false, 443,
false,
false,
null],
651 'unsecure request, not using registered port, not using secure in frontend' => [
false, 80,
false,
false],
660 $expectedResult =
'pub/media';
661 $this->filesystemMock->expects($this->once())
664 ->willReturn($expectedResult);
665 $this->assertEquals($expectedResult, $this->store->getBaseMediaDir());
673 $expectedResult =
'pub/static';
674 $this->filesystemMock->expects($this->once())
677 ->willReturn($expectedResult);
678 $this->assertEquals($expectedResult, $this->store->getBaseStaticDir());
694 $this->assertEquals(
'Store View', $this->store->getScopeTypeName());
702 $property = (new \ReflectionClass(get_class(
$model)))
703 ->getProperty(
'urlModifier');
705 $property->setAccessible(
true);
706 $property->setValue(
$model, $this->urlModifierMock);
getBaseCurrencyDataProvider()
getCurrentUrlDataProvider()
isCurrentlySecureDataProvider()
const XML_PATH_SECURE_IN_FRONTEND
const XML_PATH_SECURE_BASE_URL
const URL_TYPE_DIRECT_LINK
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]