From 7da80b420e71d514a6581e00e4974ef4326f7ac2 Mon Sep 17 00:00:00 2001
From: Venkata Uppalapati <vuppalapati@magento.com>
Date: Tue, 3 Jan 2017 16:03:16 -0600
Subject: [PATCH] MAGETWO-59785: Incorrect URLs in sitemap when generated from
 admin with 'Use Secure URLs in Admin' = Yes Used API methods. Reformatted the
 code.

---
 app/code/Magento/Sitemap/Model/Sitemap.php    |  5 ++-
 .../Sitemap/Test/Unit/Model/SitemapTest.php   | 45 +++++++------------
 2 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/app/code/Magento/Sitemap/Model/Sitemap.php b/app/code/Magento/Sitemap/Model/Sitemap.php
index a26cbcc58bd..c8d15c7a855 100644
--- a/app/code/Magento/Sitemap/Model/Sitemap.php
+++ b/app/code/Magento/Sitemap/Model/Sitemap.php
@@ -586,8 +586,9 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel
      */
     protected function _getStoreBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LINK)
     {
-        $isSecure = $this->_storeManager->getStore($this->getStoreId())->isFrontUrlSecure();
-        return rtrim($this->_storeManager->getStore($this->getStoreId())->getBaseUrl($type, $isSecure), '/') . '/';
+        $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 297161fb9fd..964d12b8ad1 100644
--- a/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php
+++ b/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php
@@ -478,32 +478,19 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
 
         $model = $this->_getModelMock(true);
 
-        $storeMock = $this->getMockBuilder(
-            \Magento\Store\Model\Store::class
-        )->setMethods(
-            ['isFrontUrlSecure', 'getBaseUrl']
-        )->disableOriginalConstructor()->getMock();
+        $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
-        );
+        $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;
     }
@@ -641,11 +628,9 @@ 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();
+        $this->_storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
+            ->setMethods(['getStore'])
+            ->getMockForAbstractClass();
 
         $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
         $constructArguments = $objectManager->getConstructArguments(
-- 
GitLab