Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RenderTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Pricing\Render;
9 
13 class RenderTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $model;
19 
23  protected $priceLayout;
24 
28  protected $price;
29 
33  protected $amount;
34 
38  protected $saleableItem;
39 
43  protected $renderPool;
44 
45  protected function setUp()
46  {
47  $this->priceLayout = $this->getMockBuilder(\Magento\Framework\Pricing\Render\Layout::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50 
51  $this->price = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
52  ->disableOriginalConstructor()
53  ->getMockForAbstractClass();
54 
55  $this->amount = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\Base::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $this->saleableItem = $this->getMockBuilder(\Magento\Framework\Pricing\SaleableInterface::class)
60  ->disableOriginalConstructor()
61  ->getMockForAbstractClass();
62 
63  $this->renderPool = $this->getMockBuilder(\Magento\Framework\Pricing\Render\RendererPool::class)
64  ->disableOriginalConstructor()
65  ->getMock();
66 
67  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
68  $this->model = $objectManager->getObject(
69  \Magento\Framework\Pricing\Render::class,
70  [
71  'priceLayout' => $this->priceLayout
72  ]
73  );
74  }
75 
76  public function testSetLayout()
77  {
78  $priceRenderHandle = 'price_render_handle';
79 
80  $this->priceLayout->expects($this->once())
81  ->method('addHandle')
82  ->with($priceRenderHandle);
83 
84  $this->priceLayout->expects($this->once())
85  ->method('loadLayout');
86 
87  $layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
88  $this->model->setPriceRenderHandle($priceRenderHandle);
89  $this->model->setLayout($layout);
90  }
91 
95  public function testRenderWithoutRenderList()
96  {
97  $priceType = 'final';
98  $arguments = ['param' => 1];
99  $result = '';
100 
101  $this->priceLayout->expects($this->once())
102  ->method('getBlock')
103  ->with('render.product.prices')
104  ->will($this->returnValue(false));
105 
106  $this->assertEquals($result, $this->model->render($priceType, $this->saleableItem, $arguments));
107  }
108 
109  public function testRender()
110  {
111  $priceType = 'final';
112  $arguments = ['param' => 1];
113  $result = 'simple.final';
114 
115  $pricingRender = $this->createMock(\Magento\Framework\Pricing\Render::class);
116  $this->renderPool->expects($this->once())
117  ->method('createPriceRender')
118  ->will($this->returnValue($pricingRender));
119  $pricingRender->expects($this->once())
120  ->method('toHtml')
121  ->will($this->returnValue('simple.final'));
122  $this->priceLayout->expects($this->once())
123  ->method('getBlock')
124  ->with('render.product.prices')
125  ->will($this->returnValue($this->renderPool));
126  $this->assertEquals($result, $this->model->render($priceType, $this->saleableItem, $arguments));
127  }
128 
129  public function testRenderDefault()
130  {
131  $priceType = 'special';
132  $arguments = ['param' => 15];
133  $result = 'default.special';
134  $pricingRender = $this->createMock(\Magento\Framework\Pricing\Render::class);
135  $this->renderPool->expects($this->once())
136  ->method('createPriceRender')
137  ->will($this->returnValue($pricingRender));
138  $pricingRender->expects($this->once())
139  ->method('toHtml')
140  ->will($this->returnValue('default.special'));
141  $this->priceLayout->expects($this->once())
142  ->method('getBlock')
143  ->with('render.product.prices')
144  ->will($this->returnValue($this->renderPool));
145 
146  $this->assertEquals($result, $this->model->render($priceType, $this->saleableItem, $arguments));
147  }
148 
149  public function testRenderDefaultDefault()
150  {
151  $priceType = 'final';
152  $arguments = ['param' => 15];
153  $result = 'default.default';
154 
155  $pricingRender = $this->createMock(\Magento\Framework\Pricing\Render::class);
156  $this->renderPool->expects($this->once())
157  ->method('createPriceRender')
158  ->will($this->returnValue($pricingRender));
159  $pricingRender->expects($this->once())
160  ->method('toHtml')
161  ->will($this->returnValue('default.default'));
162  $this->priceLayout->expects($this->once())
163  ->method('getBlock')
164  ->with('render.product.prices')
165  ->will($this->returnValue($this->renderPool));
166 
167  $this->assertEquals($result, $this->model->render($priceType, $this->saleableItem, $arguments));
168  }
169 
170  public function testAmountRender()
171  {
172  $arguments = ['param' => 15];
173  $expectedResult = 'default.default';
174 
175  $pricingRender = $this->createMock(
176  \Magento\Framework\Pricing\Render\Amount::class
177  );
178  $this->renderPool->expects($this->once())
179  ->method('createAmountRender')
180  ->with(
181  $this->equalTo($this->amount),
182  $this->equalTo($this->saleableItem),
183  $this->equalTo($this->price),
184  $this->equalTo($arguments)
185  )
186  ->will($this->returnValue($pricingRender));
187  $pricingRender->expects($this->once())
188  ->method('toHtml')
189  ->will($this->returnValue('default.default'));
190  $this->priceLayout->expects($this->once())
191  ->method('getBlock')
192  ->with('render.product.prices')
193  ->will($this->returnValue($this->renderPool));
194 
195  $result = $this->model->renderAmount($this->amount, $this->price, $this->saleableItem, $arguments);
196  $this->assertEquals($expectedResult, $result);
197  }
198 
204  {
205  $this->priceLayout->expects($this->once())
206  ->method('getBlock')
207  ->with('render.product.prices')
208  ->will($this->returnValue(false));
209 
210  $this->model->renderAmount($this->amount, $this->price, $this->saleableItem);
211  }
212 }
if( $block->displayPriceExclTax()||$block->displayBothPrices())(__('Excl. Tax')) ?>"> <?php if ($block -> displayPriceWithWeeeDetails()): ?> <span class="cart-tax-total" data-mage-init=' Magento Weee Helper Data Magento Weee Helper Data title amount
Definition: unit.phtml:68
$objectManager
Definition: bootstrap.php:17
$priceType
Definition: msrp.phtml:18
$arguments