Skip to content

Commit 86674b4

Browse files
committed
Merge pull request #342 from magento-tango/S53_bugs
[Tango][S53] BF + ZF1 update
2 parents 27b0b2b + 6c36272 commit 86674b4

File tree

34 files changed

+1298
-104
lines changed

34 files changed

+1298
-104
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/form/container.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require([
3636
summaryElement.trigger('click');
3737
}
3838
}
39+
$(element).trigger('highlight.validate');
3940
}
4041
});
4142

app/code/Magento/Catalog/Block/Adminhtml/Category/Widget/Chooser.php

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public function getCategoryCollection()
172172
*
173173
* @param bool|null $expanded
174174
* @return string
175+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
175176
*/
176177
public function getLoadTreeUrl($expanded = null)
177178
{

app/code/Magento/Catalog/Block/Product/NewProduct.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public function __construct(
6767
$context,
6868
$data
6969
);
70-
$this->_isScopePrivate = true;
7170
}
7271

7372
/**

app/code/Magento/Catalog/Block/Product/Widget/NewWidget.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function _getProductCollection()
5252
switch ($this->getDisplayType()) {
5353
case self::DISPLAY_TYPE_NEW_PRODUCTS:
5454
$collection = parent::_getProductCollection()
55-
->setPageSize($this->getProductsPerPage())
55+
->setPageSize($this->getPageSize())
5656
->setCurPage($this->getCurrentPage());
5757
break;
5858
default:
@@ -76,7 +76,7 @@ protected function _getRecentlyAddedProductsCollection()
7676
$collection = $this->_addProductAttributesAndPrices($collection)
7777
->addStoreFilter()
7878
->addAttributeToSort('created_at', 'desc')
79-
->setPageSize($this->getProductsPerPage())
79+
->setPageSize($this->getPageSize())
8080
->setCurPage($this->getCurrentPage());
8181
return $collection;
8282
}
@@ -122,7 +122,7 @@ public function getDisplayType()
122122
}
123123

124124
/**
125-
* Retrieve how much products should be displayed
125+
* Retrieve how many products should be displayed
126126
*
127127
* @return int
128128
*/
@@ -135,7 +135,7 @@ public function getProductsCount()
135135
}
136136

137137
/**
138-
* Retrieve how much products should be displayed
138+
* Retrieve how many products should be displayed
139139
*
140140
* @return int
141141
*/
@@ -160,6 +160,16 @@ public function showPager()
160160
return (bool)$this->getData('show_pager');
161161
}
162162

163+
/**
164+
* Retrieve how many products should be displayed on page
165+
*
166+
* @return int
167+
*/
168+
protected function getPageSize()
169+
{
170+
return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount();
171+
}
172+
163173
/**
164174
* Render pagination HTML
165175
*

app/code/Magento/Catalog/Test/Unit/Block/Product/NewProductTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ public function testGetIdentities()
2727
{
2828
$this->assertEquals([\Magento\Catalog\Model\Product::CACHE_TAG], $this->block->getIdentities());
2929
}
30+
31+
public function testScope()
32+
{
33+
$this->assertFalse($this->block->isScopePrivate());
34+
}
3035
}

app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php

Lines changed: 230 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Block\Product\Widget;
77

8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
use Magento\Catalog\Block\Product\Widget\NewWidget;
10+
11+
/**
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
*/
814
class NewWidgetTest extends \PHPUnit_Framework_TestCase
915
{
1016
/**
@@ -22,26 +28,69 @@ class NewWidgetTest extends \PHPUnit_Framework_TestCase
2228
*/
2329
protected $requestMock;
2430

31+
/** @var \Magento\Backend\Block\Context|\PHPUnit_Framework_MockObject_MockObject */
32+
protected $context;
33+
34+
/** @var ObjectManagerHelper */
35+
protected $objectManager;
36+
37+
/** @var \Magento\Framework\Event\Manager|\PHPUnit_Framework_MockObject_MockObject */
38+
protected $eventManager;
39+
40+
/** @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject */
41+
protected $scopeConfig;
42+
43+
/** @var \Magento\Framework\App\Cache\State|\PHPUnit_Framework_MockObject_MockObject */
44+
protected $cacheState;
45+
46+
/** @var \Magento\Catalog\Model\Config|\PHPUnit_Framework_MockObject_MockObject */
47+
protected $catalogConfig;
48+
49+
/** @var \Magento\Framework\Stdlib\DateTime\Timezone|\PHPUnit_Framework_MockObject_MockObject */
50+
protected $localDate;
51+
52+
/** @var \Magento\Catalog\Model\Resource\Product\Collection|\PHPUnit_Framework_MockObject_MockObject */
53+
protected $productCollection;
54+
2555
protected function setUp()
2656
{
27-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
28-
$contextMock = $this->getMock('Magento\Catalog\Block\Product\Context', [], [], '', false, false);
57+
$this->objectManager = new ObjectManagerHelper($this);
58+
$this->eventManager = $this->getMock('Magento\Framework\Event\Manager', ['dispatch'], [], '', false, false);
59+
$this->scopeConfig = $this->getMock('Magento\Framework\App\Config', ['getValue'], [], '', false, false);
60+
$this->cacheState = $this->getMock('Magento\Framework\App\Cache\State', ['isEnabled'], [], '', false, false);
61+
$this->localDate = $this->getMock('Magento\Framework\Stdlib\DateTime\Timezone', [], [], '', false, false);
62+
$this->catalogConfig = $this->getMockBuilder('Magento\Catalog\Model\Config')
63+
->setMethods(['getProductAttributes'])
64+
->disableOriginalConstructor()
65+
->getMock();
2966
$this->layout = $this->getMock('Magento\Framework\View\Layout', [], [], '', false);
3067
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
3168
->disableOriginalConstructor()
3269
->getMock();
3370

34-
$contextMock->expects($this->once())
71+
$this->context = $this->getMockBuilder('Magento\Catalog\Block\Product\Context')
72+
->setMethods(
73+
[
74+
'getEventManager', 'getScopeConfig', 'getLayout',
75+
'getRequest', 'getCacheState', 'getCatalogConfig',
76+
'getLocaleDate'
77+
]
78+
)
79+
->disableOriginalConstructor()
80+
->disableArgumentCloning()
81+
->getMock();
82+
83+
$this->context->expects($this->any())
3584
->method('getLayout')
36-
->will($this->returnValue($this->layout));
37-
$contextMock->expects($this->once())
85+
->willReturn($this->layout);
86+
$this->context->expects($this->any())
3887
->method('getRequest')
3988
->willReturn($this->requestMock);
4089

41-
$this->block = $objectManager->getObject(
90+
$this->block = $this->objectManager->getObject(
4291
'Magento\Catalog\Block\Product\Widget\NewWidget',
4392
[
44-
'context' => $contextMock
93+
'context' => $this->context
4594
]
4695
);
4796
}
@@ -61,10 +110,10 @@ public function testGetProductPriceHtml()
61110
</span>
62111
</div>';
63112
$type = 'widget-new-list';
64-
$productMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false, false);
113+
$productMock = $this->getMock('Magento\Catalog\Model\Product', ['getId'], [], '', false, false);
65114
$productMock->expects($this->once())
66115
->method('getId')
67-
->will($this->returnValue($id));
116+
->willReturn($id);
68117
$arguments = [
69118
'price_id' => 'old-price-' . $id . '-' . $type,
70119
'display_minimal_price' => true,
@@ -77,12 +126,12 @@ public function testGetProductPriceHtml()
77126
$this->layout->expects($this->once())
78127
->method('getBlock')
79128
->with($this->equalTo('product.price.render.default'))
80-
->will($this->returnValue($priceBoxMock));
129+
->willReturn($priceBoxMock);
81130

82131
$priceBoxMock->expects($this->once())
83132
->method('render')
84133
->with($this->equalTo('final_price'), $this->equalTo($productMock), $this->equalTo($arguments))
85-
->will($this->returnValue($expectedHtml));
134+
->willReturn($expectedHtml);
86135

87136
$result = $this->block->getProductPriceHtml($productMock, $type);
88137
$this->assertEquals($expectedHtml, $result);
@@ -111,4 +160,174 @@ public function getCurrentPageDataProvider()
111160
[10, 10]
112161
];
113162
}
163+
164+
public function testGetProductsCount()
165+
{
166+
$this->assertEquals(10, $this->block->getProductsCount());
167+
$this->block->setProductsCount(2);
168+
$this->assertEquals(2, $this->block->getProductsCount());
169+
}
170+
171+
protected function generalGetProductCollection()
172+
{
173+
$this->eventManager->expects($this->once())->method('dispatch')
174+
->will($this->returnValue(true));
175+
$this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
176+
->willReturn(false);
177+
$this->cacheState->expects($this->atLeastOnce())->method('isEnabled')->withAnyParameters()
178+
->willReturn(false);
179+
$this->catalogConfig->expects($this->once())->method('getProductAttributes')
180+
->willReturn([]);
181+
$this->localDate->expects($this->any())->method('date')
182+
->willReturn(new \DateTime('now', new \DateTimeZone('UTC')));
183+
184+
$this->context->expects($this->once())->method('getEventManager')->willReturn($this->eventManager);
185+
$this->context->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfig);
186+
$this->context->expects($this->once())->method('getCacheState')->willReturn($this->cacheState);
187+
$this->context->expects($this->once())->method('getCatalogConfig')->willReturn($this->catalogConfig);
188+
$this->context->expects($this->once())->method('getLocaleDate')->willReturn($this->localDate);
189+
190+
$this->productCollection = $this->getMockBuilder('Magento\Catalog\Model\Resource\Product\Collection')
191+
->setMethods(
192+
[
193+
'setVisibility', 'addMinimalPrice', 'addFinalPrice',
194+
'addTaxPercents', 'addAttributeToSelect', 'addUrlRewrite',
195+
'addStoreFilter', 'addAttributeToSort', 'setPageSize',
196+
'setCurPage', 'addAttributeToFilter'
197+
]
198+
)
199+
->disableOriginalConstructor()
200+
->getMock();
201+
$this->productCollection->expects($this->once())->method('setVisibility')
202+
->willReturnSelf();
203+
$this->productCollection->expects($this->once())->method('addMinimalPrice')
204+
->willReturnSelf();
205+
$this->productCollection->expects($this->once())->method('addFinalPrice')
206+
->willReturnSelf();
207+
$this->productCollection->expects($this->once())->method('addTaxPercents')
208+
->willReturnSelf();
209+
$this->productCollection->expects($this->once())->method('addAttributeToSelect')
210+
->willReturnSelf();
211+
$this->productCollection->expects($this->once())->method('addUrlRewrite')
212+
->willReturnSelf();
213+
$this->productCollection->expects($this->once())->method('addStoreFilter')
214+
->willReturnSelf();
215+
$this->productCollection->expects($this->once())->method('addAttributeToSort')
216+
->willReturnSelf();
217+
$this->productCollection->expects($this->atLeastOnce())->method('setCurPage')
218+
->willReturnSelf();
219+
$this->productCollection->expects($this->any())->method('addAttributeToFilter')
220+
->willReturnSelf();
221+
}
222+
223+
/**
224+
* @param string $displayType
225+
* @param bool $pagerEnable
226+
* @param int $productsCount
227+
* @param int $productsPerPage
228+
*/
229+
protected function startTestGetProductCollection($displayType, $pagerEnable, $productsCount, $productsPerPage)
230+
{
231+
$productCollectionFactory = $this->getMock(
232+
'Magento\Catalog\Model\Resource\Product\CollectionFactory',
233+
['create'],
234+
[],
235+
'',
236+
false,
237+
false
238+
);
239+
$productCollectionFactory->expects($this->atLeastOnce())->method('create')
240+
->willReturn($this->productCollection);
241+
242+
$this->block = $this->objectManager->getObject(
243+
'Magento\Catalog\Block\Product\Widget\NewWidget',
244+
[
245+
'context' => $this->context,
246+
'productCollectionFactory' => $productCollectionFactory
247+
]
248+
);
249+
250+
if (null === $productsPerPage) {
251+
$this->block->unsetData('products_per_page');
252+
} else {
253+
$this->block->setData('products_per_page', $productsPerPage);
254+
}
255+
256+
$this->block->setData('show_pager', $pagerEnable);
257+
$this->block->setData('display_type', $displayType);
258+
$this->block->setProductsCount($productsCount);
259+
$this->block->toHtml();
260+
}
261+
262+
/**
263+
* Test protected `_getProductCollection` and `getPageSize` methods via public `toHtml` method,
264+
* for display_type == DISPLAY_TYPE_NEW_PRODUCTS.
265+
*
266+
* @param bool $pagerEnable
267+
* @param int $productsCount
268+
* @param int $productsPerPage
269+
* @param int $expectedPageSize
270+
* @dataProvider getProductCollectionDataProvider
271+
*/
272+
public function testGetProductNewCollection($pagerEnable, $productsCount, $productsPerPage, $expectedPageSize)
273+
{
274+
$this->generalGetProductCollection();
275+
276+
$this->productCollection->expects($this->exactly(2))->method('setPageSize')
277+
->withConsecutive(
278+
[$productsCount],
279+
[$expectedPageSize]
280+
)
281+
->willReturnSelf();
282+
283+
$this->startTestGetProductCollection(
284+
NewWidget::DISPLAY_TYPE_NEW_PRODUCTS,
285+
$pagerEnable,
286+
$productsCount,
287+
$productsPerPage
288+
);
289+
}
290+
291+
/**
292+
* Test protected `_getProductCollection` and `getPageSize` methods via public `toHtml` method,
293+
* for display_type == DISPLAY_TYPE_ALL_PRODUCTS.
294+
*
295+
* @param bool $pagerEnable
296+
* @param int $productsCount
297+
* @param int $productsPerPage
298+
* @param int $expectedPageSize
299+
* @dataProvider getProductCollectionDataProvider
300+
*/
301+
public function testGetProductAllCollection($pagerEnable, $productsCount, $productsPerPage, $expectedPageSize)
302+
{
303+
$this->generalGetProductCollection();
304+
305+
$this->productCollection->expects($this->atLeastOnce())->method('setPageSize')->with($expectedPageSize)
306+
->willReturnSelf();
307+
308+
$this->startTestGetProductCollection(
309+
NewWidget::DISPLAY_TYPE_ALL_PRODUCTS,
310+
$pagerEnable,
311+
$productsCount,
312+
$productsPerPage
313+
);
314+
}
315+
316+
public function getProductCollectionDataProvider()
317+
{
318+
return [
319+
[true, 1, null, 5],
320+
[true, 5, null, 5],
321+
[true, 10, null, 5],
322+
[true, 1, 2, 2],
323+
[true, 5, 3, 3],
324+
[true, 10, 7, 7],
325+
[false, 1, null, 1],
326+
[false, 3, null, 3],
327+
[false, 5, null, 5],
328+
[false, 1, 3, 1],
329+
[false, 3, 5, 3],
330+
[false, 5, 10, 5]
331+
];
332+
}
114333
}

app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/widget/tree.phtml

100644100755
File mode changed.

0 commit comments

Comments
 (0)