From a91b5514fb577b815f5bd2b326e99139e3fe8fdc Mon Sep 17 00:00:00 2001 From: Venkata Uppalapati <vuppalapati@magento.com> Date: Tue, 27 Dec 2016 11:51:27 -0600 Subject: [PATCH] MAGETWO-59785: Incorrect URLs in sitemap when generated from admin with 'Use Secure URLs in Admin' = Yes Modified sitemap unit test to cover the fix changes. --- .../Sitemap/Test/Unit/Model/SitemapTest.php | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php index f94a2051047..6affe7a93b3 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,33 @@ 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 +522,6 @@ class SitemapTest extends \PHPUnit_Framework_TestCase '_getBaseDir', '_getFileObject', '_afterSave', - '_getStoreBaseUrl', '_getCurrentDateTime', '_getCategoryItemsCollection', '_getProductItemsCollection', @@ -562,7 +593,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 +641,13 @@ 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 +655,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase 'categoryFactory' => $categoryFactory, 'productFactory' => $productFactory, 'cmsFactory' => $cmsFactory, + 'storeManager' => $this->_storeManagerMock, 'sitemapData' => $this->_helperMockSitemap, 'filesystem' => $this->_filesystemMock ] -- GitLab