diff --git a/app/code/Magento/Sitemap/Model/Sitemap.php b/app/code/Magento/Sitemap/Model/Sitemap.php index 6e31c255526411d293dc1fd54c0f32a256378e8b..5bd25c978b7c31001e4346b13a9e72eee588e40c 100644 --- a/app/code/Magento/Sitemap/Model/Sitemap.php +++ b/app/code/Magento/Sitemap/Model/Sitemap.php @@ -586,7 +586,9 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel */ protected function _getStoreBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LINK) { - return rtrim($this->_storeManager->getStore($this->getStoreId())->getBaseUrl($type), '/') . '/'; + $store = $this->_storeManager->getStore($this->getStoreId()); + $isSecure = $store->isUrlSecure(); + return rtrim($store->getBaseUrl($type, $isSecure), '/') . '/'; } /** diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php index 8daa4d6e9331a2a533a19189b99e5b7821719157..65b55f3e8dc87c1019a4b08d7f96b8b1ec0ff7f8 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php @@ -50,6 +50,11 @@ class SitemapTest extends \PHPUnit_Framework_TestCase */ protected $_fileMock; + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $storeManagerMock; + /** * Set helper mocks, create resource model mock */ @@ -473,6 +478,20 @@ class SitemapTest extends \PHPUnit_Framework_TestCase $model = $this->_getModelMock(true); + $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + ->setMethods(['isFrontUrlSecure', 'getBaseUrl']) + ->disableOriginalConstructor() + ->getMock(); + $storeMock->expects($this->atLeastOnce())->method('isFrontUrlSecure')->willReturn(false); + $storeMock->expects($this->atLeastOnce()) + ->method('getBaseUrl') + ->with($this->isType('string'), false) + ->willReturn('http://store.com/'); + $this->storeManagerMock->expects($this->atLeastOnce()) + ->method('getStore') + ->with(1) + ->willReturn($storeMock); + return $model; } @@ -490,7 +509,6 @@ class SitemapTest extends \PHPUnit_Framework_TestCase '_getBaseDir', '_getFileObject', '_afterSave', - '_getStoreBaseUrl', '_getCurrentDateTime', '_getCategoryItemsCollection', '_getProductItemsCollection', @@ -562,7 +580,6 @@ class SitemapTest extends \PHPUnit_Framework_TestCase )->getMock(); $model->expects($this->any())->method('_getResource')->will($this->returnValue($this->_resourceMock)); - $model->expects($this->any())->method('_getStoreBaseUrl')->will($this->returnValue('http://store.com/')); $model->expects( $this->any() )->method( @@ -611,6 +628,10 @@ class SitemapTest extends \PHPUnit_Framework_TestCase )->disableOriginalConstructor()->getMock(); $cmsFactory->expects($this->any())->method('create')->will($this->returnValue($this->_sitemapCmsPageMock)); + $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class) + ->setMethods(['getStore']) + ->getMockForAbstractClass(); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $constructArguments = $objectManager->getConstructArguments( \Magento\Sitemap\Model\Sitemap::class, @@ -618,6 +639,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase 'categoryFactory' => $categoryFactory, 'productFactory' => $productFactory, 'cmsFactory' => $cmsFactory, + 'storeManager' => $this->storeManagerMock, 'sitemapData' => $this->_helperMockSitemap, 'filesystem' => $this->_filesystemMock ]