Skip to content

Commit 4815341

Browse files
author
Joan He
authored
Merge pull request #726 from magento-fearless-kiwis/FearlessKiwis-MAGETWO-59785-IncorrectUrls-in-sitemap
Fearless kiwis magetwo 59785 incorrect urls in sitemap
2 parents b1e56ed + 6d6aeae commit 4815341

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ protected function _getBaseDir()
586586
*/
587587
protected function _getStoreBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LINK)
588588
{
589-
return rtrim($this->_storeManager->getStore($this->getStoreId())->getBaseUrl($type), '/') . '/';
589+
$store = $this->_storeManager->getStore($this->getStoreId());
590+
$isSecure = $store->isUrlSecure();
591+
return rtrim($store->getBaseUrl($type, $isSecure), '/') . '/';
590592
}
591593

592594
/**

app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
5050
*/
5151
protected $_fileMock;
5252

53+
/**
54+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $storeManagerMock;
57+
5358
/**
5459
* Set helper mocks, create resource model mock
5560
*/
@@ -473,6 +478,20 @@ function ($from, $to) {
473478

474479
$model = $this->_getModelMock(true);
475480

481+
$storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
482+
->setMethods(['isFrontUrlSecure', 'getBaseUrl'])
483+
->disableOriginalConstructor()
484+
->getMock();
485+
$storeMock->expects($this->atLeastOnce())->method('isFrontUrlSecure')->willReturn(false);
486+
$storeMock->expects($this->atLeastOnce())
487+
->method('getBaseUrl')
488+
->with($this->isType('string'), false)
489+
->willReturn('http://store.com/');
490+
$this->storeManagerMock->expects($this->atLeastOnce())
491+
->method('getStore')
492+
->with(1)
493+
->willReturn($storeMock);
494+
476495
return $model;
477496
}
478497

@@ -490,7 +509,6 @@ protected function _getModelMock($mockBeforeSave = false)
490509
'_getBaseDir',
491510
'_getFileObject',
492511
'_afterSave',
493-
'_getStoreBaseUrl',
494512
'_getCurrentDateTime',
495513
'_getCategoryItemsCollection',
496514
'_getProductItemsCollection',
@@ -562,7 +580,6 @@ protected function _getModelMock($mockBeforeSave = false)
562580
)->getMock();
563581

564582
$model->expects($this->any())->method('_getResource')->will($this->returnValue($this->_resourceMock));
565-
$model->expects($this->any())->method('_getStoreBaseUrl')->will($this->returnValue('http://store.com/'));
566583
$model->expects(
567584
$this->any()
568585
)->method(
@@ -611,13 +628,18 @@ protected function _getModelConstructorArgs()
611628
)->disableOriginalConstructor()->getMock();
612629
$cmsFactory->expects($this->any())->method('create')->will($this->returnValue($this->_sitemapCmsPageMock));
613630

631+
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
632+
->setMethods(['getStore'])
633+
->getMockForAbstractClass();
634+
614635
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
615636
$constructArguments = $objectManager->getConstructArguments(
616637
\Magento\Sitemap\Model\Sitemap::class,
617638
[
618639
'categoryFactory' => $categoryFactory,
619640
'productFactory' => $productFactory,
620641
'cmsFactory' => $cmsFactory,
642+
'storeManager' => $this->storeManagerMock,
621643
'sitemapData' => $this->_helperMockSitemap,
622644
'filesystem' => $this->_filesystemMock
623645
]

0 commit comments

Comments
 (0)