Skip to content

Commit 06a91b8

Browse files
committed
fixed unit test issue
1 parent 521e950 commit 06a91b8

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

app/code/Magento/Catalog/Block/Rss/Category.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
*/
1717
class Category extends \Magento\Framework\View\Element\AbstractBlock implements DataProviderInterface
1818
{
19-
/**
20-
* @var \Magento\Framework\Config\View
21-
*/
22-
private $configView;
23-
24-
/**
19+
/**
2520
* @var \Magento\Catalog\Model\CategoryFactory
2621
*/
2722
protected $categoryFactory;
@@ -56,6 +51,16 @@ class Category extends \Magento\Framework\View\Element\AbstractBlock implements
5651
*/
5752
protected $categoryRepository;
5853

54+
/**
55+
* @var \Magento\Framework\View\ConfigInterface
56+
*/
57+
protected $viewConfig;
58+
59+
/**
60+
* @var \Magento\Framework\Config\View
61+
*/
62+
protected $configView;
63+
5964
/**
6065
* @param \Magento\Framework\View\Element\Template\Context $context
6166
* @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
@@ -64,6 +69,7 @@ class Category extends \Magento\Framework\View\Element\AbstractBlock implements
6469
* @param \Magento\Catalog\Helper\Image $imageHelper
6570
* @param \Magento\Customer\Model\Session $customerSession
6671
* @param CategoryRepositoryInterface $categoryRepository
72+
* @param \Magento\Framework\View\ConfigInterface $viewConfig
6773
* @param array $data
6874
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6975
*/
@@ -75,6 +81,7 @@ public function __construct(
7581
\Magento\Catalog\Helper\Image $imageHelper,
7682
\Magento\Customer\Model\Session $customerSession,
7783
CategoryRepositoryInterface $categoryRepository,
84+
\Magento\Framework\View\ConfigInterface $viewConfig,
7885
array $data = []
7986
) {
8087
$this->imageHelper = $imageHelper;
@@ -84,6 +91,7 @@ public function __construct(
8491
$this->rssUrlBuilder = $rssUrlBuilder;
8592
$this->storeManager = $context->getStoreManager();
8693
$this->categoryRepository = $categoryRepository;
94+
$this->viewConfig = $viewConfig;
8795
parent::__construct($context, $data);
8896
}
8997

@@ -124,7 +132,7 @@ public function getRssData()
124132

125133
$attributes = $this->getConfigView()
126134
->getMediaAttributes('Magento_Catalog', $this->imageHelper::MEDIA_TYPE_CONFIG_NODE, 'rss_thumbnail');
127-
135+
128136
/** @var $product \Magento\Catalog\Model\Product */
129137
foreach ($this->rssModel->getProductCollection($category, $this->getStoreId()) as $product) {
130138
$product->setAllowedInRss(true);
@@ -275,12 +283,14 @@ public function isAuthRequired()
275283
}
276284

277285
/**
286+
* Retrieve config view
287+
*
278288
* @return \Magento\Framework\Config\View
279289
*/
280-
private function getConfigView()
290+
protected function getConfigView()
281291
{
282292
if (!$this->configView) {
283-
$this->configView = $this->_viewConfig->getViewConfig();
293+
$this->configView = $this->viewConfig->getViewConfig();
284294
}
285295
return $this->configView;
286296
}

app/code/Magento/Catalog/Test/Unit/Block/Rss/CategoryTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class CategoryTest extends \PHPUnit\Framework\TestCase
7272
* @var \Magento\Catalog\Api\CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
7373
*/
7474
protected $categoryRepository;
75+
76+
/**
77+
* @var \Magento\Framework\View\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
78+
*/
79+
protected $viewConfig;
7580

7681
/**
7782
* @var array
@@ -115,6 +120,8 @@ protected function setUp()
115120
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
116121
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
117122
$this->categoryRepository = $this->createMock(\Magento\Catalog\Api\CategoryRepositoryInterface::class);
123+
$this->viewConfig = $this->getMockBuilder(\Magento\Framework\View\ConfigInterface::class)
124+
->getMockForAbstractClass();
118125
$objectManagerHelper = new ObjectManagerHelper($this);
119126
$this->block = $objectManagerHelper->getObject(
120127
\Magento\Catalog\Block\Rss\Category::class,
@@ -130,6 +137,7 @@ protected function setUp()
130137
'customerSession' => $this->customerSession,
131138
'storeManager' => $this->storeManager,
132139
'categoryRepository' => $this->categoryRepository,
140+
'viewConfig' => $this->viewConfig,
133141
]
134142
);
135143
}
@@ -144,6 +152,14 @@ public function testGetRssData()
144152
->will($this->returnValue('http://magento.com/category-name.html'));
145153

146154
$this->categoryRepository->expects($this->once())->method('get')->will($this->returnValue($category));
155+
156+
$configViewMock = $this->getMockBuilder(\Magento\Framework\Config\View::class)
157+
->disableOriginalConstructor()
158+
->getMock();
159+
160+
$this->viewConfig->expects($this->once())
161+
->method('getViewConfig')
162+
->willReturn($configViewMock);
147163

148164
$product = $this->getMockBuilder(\Magento\catalog\Model\Product::class)
149165
->setMethods([

0 commit comments

Comments
 (0)