Skip to content

Commit f2619d5

Browse files
author
Sergey Semenov
committed
Merge remote-tracking branch 'origin/MAGETWO-51993' into BUGS
2 parents 163f0fc + 38a16b5 commit f2619d5

File tree

4 files changed

+278
-0
lines changed

4 files changed

+278
-0
lines changed

app/code/Magento/Wishlist/Block/Customer/Sidebar.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
namespace Magento\Wishlist\Block\Customer;
1111

12+
use Magento\Catalog\Model\Product;
13+
use Magento\Framework\Pricing\Render;
14+
1215
class Sidebar extends \Magento\Wishlist\Block\AbstractBlock
1316
{
1417
/**
@@ -20,4 +23,56 @@ public function getTitle()
2023
{
2124
return __('My Wish List');
2225
}
26+
27+
/**
28+
* Return HTML block content
29+
*
30+
* @param Product $product
31+
* @param string $priceType
32+
* @param string $renderZone
33+
* @param array $arguments
34+
* @return string
35+
*/
36+
public function getProductPriceHtml(
37+
Product $product,
38+
$priceType,
39+
$renderZone = Render::ZONE_ITEM_LIST,
40+
array $arguments = []
41+
) {
42+
if (!isset($arguments['zone'])) {
43+
$arguments['zone'] = $renderZone;
44+
}
45+
46+
$price = '';
47+
48+
$priceRender = $this->getPriceRender();
49+
if ($priceRender) {
50+
$price = $priceRender->render($priceType, $product, $arguments);
51+
}
52+
53+
return $price;
54+
}
55+
56+
/**
57+
* Get price render block
58+
*
59+
* @return Render
60+
*/
61+
private function getPriceRender()
62+
{
63+
/** @var Render $priceRender */
64+
$priceRender = $this->getLayout()->getBlock('product.price.render.default');
65+
if (!$priceRender) {
66+
$priceRender = $this->getLayout()->createBlock(
67+
'Magento\Framework\Pricing\Render',
68+
'product.price.render.default',
69+
[
70+
'data' => [
71+
'price_render_handle' => 'catalog_product_prices',
72+
],
73+
]
74+
);
75+
}
76+
return $priceRender;
77+
}
2378
}

app/code/Magento/Wishlist/Pricing/Render/ConfiguredPriceBox.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Wishlist\Pricing\Render;
77

8+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
9+
810
class ConfiguredPriceBox extends \Magento\Catalog\Pricing\Render\ConfiguredPriceBox
911
{
1012
/**
@@ -14,4 +16,21 @@ protected function getCacheLifetime()
1416
{
1517
return null;
1618
}
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
protected function _prepareLayout()
24+
{
25+
/** @var $price \Magento\Catalog\Pricing\Price\ConfiguredPrice */
26+
$price = $this->getPrice();
27+
28+
/** @var $renderBlock \Magento\Catalog\Pricing\Render */
29+
$renderBlock = $this->getRenderBlock();
30+
if (!$renderBlock && $this->getItem() instanceof ItemInterface) {
31+
$price->setItem($this->getItem());
32+
}
33+
34+
return parent::_prepareLayout();
35+
}
1736
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Wishlist\Test\Unit\Block\Customer;
7+
8+
use Magento\Framework\Pricing\Render;
9+
use Magento\Wishlist\Block\Customer\Sidebar;
10+
11+
class SidebarTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Catalog\Block\Product\Context|\PHPUnit_Framework_MockObject_MockObject
15+
*/
16+
private $productContext;
17+
18+
/**
19+
* @var \Magento\Framework\App\Http\Context|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $httpContext;
22+
23+
/**
24+
* @var Sidebar
25+
*/
26+
private $block;
27+
28+
/**
29+
* @var \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $layout;
32+
33+
protected function setUp()
34+
{
35+
$this->layout = $this->getMockBuilder('Magento\Framework\View\LayoutInterface')
36+
->getMockForAbstractClass();
37+
38+
$this->productContext = $this->getMockBuilder('Magento\Catalog\Block\Product\Context')
39+
->disableOriginalConstructor()
40+
->getMock();
41+
$this->productContext->expects($this->any())
42+
->method('getLayout')
43+
->willReturn($this->layout);
44+
45+
$this->httpContext = $this->getMockBuilder('Magento\Framework\App\Http\Context')
46+
->disableOriginalConstructor()
47+
->getMock();
48+
49+
$this->block = new Sidebar(
50+
$this->productContext,
51+
$this->httpContext
52+
);
53+
}
54+
55+
public function testGetProductPriceHtml()
56+
{
57+
$priceType = 'wishlist_configured_price';
58+
$expected = 'block content';
59+
60+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
61+
->disableOriginalConstructor()
62+
->getMock();
63+
64+
$renderMock = $this->getMockBuilder('\Magento\Framework\Pricing\Render')
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$renderMock->expects($this->once())
68+
->method('render')
69+
->with($priceType, $productMock, ['zone' => Render::ZONE_ITEM_LIST])
70+
->willReturn($expected);
71+
72+
$this->layout->expects($this->once())
73+
->method('getBlock')
74+
->with('product.price.render.default')
75+
->willReturn($renderMock);
76+
$this->layout->expects($this->never())
77+
->method('createBlock');
78+
79+
$result = $this->block->getProductPriceHtml($productMock, $priceType, Render::ZONE_ITEM_LIST);
80+
$this->assertEquals($expected, $result);
81+
}
82+
83+
public function testGetProductPriceHtmlCreateBlock()
84+
{
85+
$priceType = 'wishlist_configured_price';
86+
$expected = 'block content';
87+
88+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
89+
->disableOriginalConstructor()
90+
->getMock();
91+
92+
$renderMock = $this->getMockBuilder('\Magento\Framework\Pricing\Render')
93+
->disableOriginalConstructor()
94+
->getMock();
95+
$renderMock->expects($this->once())
96+
->method('render')
97+
->with($priceType, $productMock, ['zone' => Render::ZONE_ITEM_LIST])
98+
->willReturn($expected);
99+
100+
$this->layout->expects($this->once())
101+
->method('getBlock')
102+
->with('product.price.render.default')
103+
->willReturn(false);
104+
$this->layout->expects($this->once())
105+
->method('createBlock')
106+
->with(
107+
'Magento\Framework\Pricing\Render',
108+
'product.price.render.default',
109+
['data' => ['price_render_handle' => 'catalog_product_prices']]
110+
)
111+
->willReturn($renderMock);
112+
113+
$result = $this->block->getProductPriceHtml($productMock, $priceType, Render::ZONE_ITEM_LIST);
114+
$this->assertEquals($expected, $result);
115+
}
116+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Wishlist\Test\Unit\Pricing\Render;
7+
8+
use Magento\Wishlist\Pricing\Render\ConfiguredPriceBox;
9+
10+
class ConfiguredPriceBoxTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject
14+
*/
15+
private $templateContext;
16+
17+
/**
18+
* @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $saleableItem;
21+
22+
/**
23+
* @var \Magento\Framework\Pricing\Price\PriceInterface|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $price;
26+
27+
/**
28+
* @var \Magento\Framework\Pricing\Render\RendererPool|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $rendererPool;
31+
32+
/**
33+
* @var ConfiguredPriceBox
34+
*/
35+
private $model;
36+
37+
/**
38+
* @var \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $item;
41+
42+
protected function setUp()
43+
{
44+
$this->templateContext = $this->getMockBuilder('Magento\Framework\View\Element\Template\Context')
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$this->saleableItem = $this->getMockBuilder('Magento\Framework\Pricing\SaleableInterface')
49+
->getMockForAbstractClass();
50+
51+
$this->price = $this->getMockBuilder('Magento\Framework\Pricing\Price\PriceInterface')
52+
->setMethods([
53+
'setItem',
54+
])
55+
->getMockForAbstractClass();
56+
57+
$this->rendererPool = $this->getMockBuilder('Magento\Framework\Pricing\Render\RendererPool')
58+
->disableOriginalConstructor()
59+
->getMock();
60+
61+
$this->item = $this->getMockBuilder('Magento\Catalog\Model\Product\Configuration\Item\ItemInterface')
62+
->getMockForAbstractClass();
63+
64+
$this->model = new ConfiguredPriceBox(
65+
$this->templateContext,
66+
$this->saleableItem,
67+
$this->price,
68+
$this->rendererPool,
69+
['item' => $this->item]
70+
);
71+
}
72+
73+
public function testSetLayout()
74+
{
75+
$layoutMock = $this->getMockBuilder('Magento\Framework\View\LayoutInterface')
76+
->getMockForAbstractClass();
77+
78+
$this->price->expects($this->once())
79+
->method('setItem')
80+
->with($this->item)
81+
->willReturnSelf();
82+
83+
$this->assertInstanceOf(
84+
'Magento\Wishlist\Pricing\Render\ConfiguredPriceBox',
85+
$this->model->setLayout($layoutMock)
86+
);
87+
}
88+
}

0 commit comments

Comments
 (0)