Skip to content

Commit ddc3799

Browse files
ENGCOM-5569: implement rss feed image size based on view.xml file #23533
- Merge Pull Request #23533 from sunilit42/magento2:2.3-develop-local - Merged commits: 1. 5853484 2. 5bb1358 3. 3a2f5c4 4. 521e950 5. 06a91b8 6. 9e497bf 7. 3e655f7 8. 4755552 9. 13a7c75 10. f968f85 11. 2f9d572 12. e8ca488 13. 9f088cf 14. af94999 15. 1fa9615 16. 70afacd 17. d6bd1d6 18. 0413854 19. f3ef0ce 20. 9775528 21. c086ab2 22. c4906f1 23. 04d3451 24. 9c0ca37 25. 52b9939 26. f301d5f
2 parents 4b9913f + f301d5f commit ddc3799

File tree

2 files changed

+79
-33
lines changed

2 files changed

+79
-33
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212
/**
1313
* Class Category
14+
*
1415
* @package Magento\Catalog\Block\Rss
16+
*
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1618
*/
1719
class Category extends \Magento\Framework\View\Element\AbstractBlock implements DataProviderInterface
1820
{
19-
/**
20-
* @var \Magento\Catalog\Model\CategoryFactory
21-
*/
21+
/**
22+
* @var \Magento\Catalog\Model\CategoryFactory
23+
*/
2224
protected $categoryFactory;
2325

2426
/**
@@ -50,7 +52,6 @@ class Category extends \Magento\Framework\View\Element\AbstractBlock implements
5052
* @var CategoryRepositoryInterface
5153
*/
5254
protected $categoryRepository;
53-
5455
/**
5556
* @param \Magento\Framework\View\Element\Template\Context $context
5657
* @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
@@ -83,6 +84,8 @@ public function __construct(
8384
}
8485

8586
/**
87+
* Set Block cache key
88+
*
8689
* @return void
8790
*/
8891
protected function _construct()
@@ -97,7 +100,9 @@ protected function _construct()
97100
}
98101

99102
/**
100-
* {@inheritdoc}
103+
* Get info about category by category id
104+
*
105+
* @return array
101106
*/
102107
public function getRssData()
103108
{
@@ -116,7 +121,9 @@ public function getRssData()
116121
$newUrl = $category->getUrl();
117122
$title = $category->getName();
118123
$data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
119-
124+
$attributes = $this->_viewConfig
125+
->getViewConfig()
126+
->getMediaAttributes('Magento_Catalog', $this->imageHelper::MEDIA_TYPE_CONFIG_NODE, 'rss_thumbnail');
120127
/** @var $product \Magento\Catalog\Model\Product */
121128
foreach ($this->rssModel->getProductCollection($category, $this->getStoreId()) as $product) {
122129
$product->setAllowedInRss(true);
@@ -130,7 +137,7 @@ public function getRssData()
130137

131138
$description = '
132139
<table><tr>
133-
<td><a href="%s"><img src="%s" border="0" align="left" height="75" width="75"></a></td>
140+
<td><a href="%s"><img src="%s" border="0" align="left" height="%s" width="%s"></a></td>
134141
<td style="text-decoration:none;">%s %s</td>
135142
</tr></table>
136143
';
@@ -139,6 +146,8 @@ public function getRssData()
139146
$description,
140147
$product->getProductUrl(),
141148
$this->imageHelper->init($product, 'rss_thumbnail')->getUrl(),
149+
isset($attributes['height']) ? $attributes['height'] : 75,
150+
isset($attributes['width']) ? $attributes['width'] : 75,
142151
$product->getDescription(),
143152
$product->getAllowedPriceInRss() ? $this->renderPriceHtml($product) : ''
144153
);
@@ -187,6 +196,8 @@ protected function renderPriceHtml(\Magento\Catalog\Model\Product $product)
187196
}
188197

189198
/**
199+
* Get current Store Id
200+
*
190201
* @return int
191202
*/
192203
protected function getStoreId()
@@ -199,6 +210,8 @@ protected function getStoreId()
199210
}
200211

201212
/**
213+
* Cache lifetime for RSS feed
214+
*
202215
* @return int
203216
*/
204217
public function getCacheLifetime()
@@ -207,7 +220,9 @@ public function getCacheLifetime()
207220
}
208221

209222
/**
210-
* {@inheritdoc}
223+
* Retrieve rss feed enable for category page
224+
*
225+
* @return bool
211226
*/
212227
public function isAllowed()
213228
{
@@ -218,6 +233,8 @@ public function isAllowed()
218233
}
219234

220235
/**
236+
* Get category feed collection
237+
*
221238
* @return array
222239
*/
223240
public function getFeeds()
@@ -257,7 +274,9 @@ public function getFeeds()
257274
}
258275

259276
/**
260-
* {@inheritdoc}
277+
* Check isAuthRequired Required
278+
*
279+
* @return bool
261280
*/
262281
public function isAuthRequired()
263282
{

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

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Test\Unit\Block\Rss;
78

89
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
@@ -73,6 +74,16 @@ class CategoryTest extends \PHPUnit\Framework\TestCase
7374
*/
7475
protected $categoryRepository;
7576

77+
/**
78+
* @var \Magento\Framework\View\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
79+
*/
80+
protected $viewConfig;
81+
82+
/**
83+
* @var \Magento\Framework\Config\View
84+
*/
85+
protected $configView;
86+
7687
/**
7788
* @var array
7889
*/
@@ -115,6 +126,8 @@ protected function setUp()
115126
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
116127
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
117128
$this->categoryRepository = $this->createMock(\Magento\Catalog\Api\CategoryRepositoryInterface::class);
129+
$this->viewConfig = $this->getMockBuilder(\Magento\Framework\View\ConfigInterface::class)
130+
->getMockForAbstractClass();
118131
$objectManagerHelper = new ObjectManagerHelper($this);
119132
$this->block = $objectManagerHelper->getObject(
120133
\Magento\Catalog\Block\Rss\Category::class,
@@ -130,6 +143,7 @@ protected function setUp()
130143
'customerSession' => $this->customerSession,
131144
'storeManager' => $this->storeManager,
132145
'categoryRepository' => $this->categoryRepository,
146+
'viewConfig' => $this->viewConfig,
133147
]
134148
);
135149
}
@@ -145,16 +159,26 @@ public function testGetRssData()
145159

146160
$this->categoryRepository->expects($this->once())->method('get')->will($this->returnValue($category));
147161

162+
$configViewMock = $this->getMockBuilder(\Magento\Framework\Config\View::class)
163+
->disableOriginalConstructor()
164+
->getMock();
165+
166+
$this->viewConfig->expects($this->once())
167+
->method('getViewConfig')
168+
->willReturn($configViewMock);
169+
148170
$product = $this->getMockBuilder(\Magento\catalog\Model\Product::class)
149-
->setMethods([
150-
'__sleep',
151-
'__wakeup',
152-
'getName',
153-
'getAllowedInRss',
154-
'getProductUrl',
155-
'getDescription',
156-
'getAllowedPriceInRss',
157-
])->disableOriginalConstructor()->getMock();
171+
->setMethods(
172+
[
173+
'__sleep',
174+
'__wakeup',
175+
'getName',
176+
'getAllowedInRss',
177+
'getProductUrl',
178+
'getDescription',
179+
'getAllowedPriceInRss'
180+
]
181+
)->disableOriginalConstructor()->getMock();
158182
$product->expects($this->once())->method('getName')->will($this->returnValue('Product Name'));
159183
$product->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true));
160184
$product->expects($this->exactly(2))->method('getProductUrl')
@@ -213,23 +237,23 @@ public function testGetFeeds()
213237
->disableOriginalConstructor()->getMock();
214238

215239
$collection = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Category\Collection::class)
216-
->setMethods([
217-
'addIdFilter',
218-
'addAttributeToSelect',
219-
'addAttributeToSort',
220-
'load',
221-
'addAttributeToFilter',
222-
'getIterator',
223-
])->disableOriginalConstructor()->getMock();
240+
->setMethods(
241+
[
242+
'addIdFilter',
243+
'addAttributeToSelect',
244+
'addAttributeToSort',
245+
'load',
246+
'addAttributeToFilter',
247+
'getIterator'
248+
]
249+
)->disableOriginalConstructor()->getMock();
224250
$collection->expects($this->once())->method('addIdFilter')->will($this->returnSelf());
225251
$collection->expects($this->exactly(3))->method('addAttributeToSelect')->will($this->returnSelf());
226252
$collection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf());
227253
$collection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf());
228254
$collection->expects($this->once())->method('load')->will($this->returnSelf());
229-
$collection->expects($this->once())->method('getIterator')->will($this->returnValue(
230-
new \ArrayIterator([$category])
231-
));
232-
255+
$collection->expects($this->once())->method('getIterator')
256+
->will($this->returnValue(new \ArrayIterator([$category])));
233257
$category->expects($this->once())->method('getId')->will($this->returnValue(1));
234258
$category->expects($this->once())->method('getName')->will($this->returnValue('Category Name'));
235259
$category->expects($this->once())->method('getResourceCollection')->will($this->returnValue($collection));
@@ -250,9 +274,12 @@ public function testGetFeeds()
250274

251275
$this->rssUrlBuilder->expects($this->once())->method('getUrl')
252276
->will($this->returnValue('http://magento.com/category-name.html'));
253-
$feeds = ['group' => 'Categories', 'feeds' => [
254-
['label' => 'Category Name', 'link' => 'http://magento.com/category-name.html'],
255-
]];
277+
$feeds = [
278+
'group' => 'Categories',
279+
'feeds' => [
280+
['label' => 'Category Name', 'link' => 'http://magento.com/category-name.html'],
281+
]
282+
];
256283
$this->assertEquals($feeds, $this->block->getFeeds());
257284
}
258285
}

0 commit comments

Comments
 (0)