Skip to content

Commit 3f4c7f0

Browse files
committed
Issue 35964: add unit test
1 parent ef9d24a commit 3f4c7f0

File tree

4 files changed

+131
-1
lines changed

4 files changed

+131
-1
lines changed

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,31 @@ public function canShowPriceInfoDataProvider()
310310
[false, ['product_calculations' => 0], false],
311311
];
312312
}
313+
314+
/**
315+
* @dataProvider getValueHtmlWithoutShipmentSeparatelyDataProvider
316+
*/
317+
public function testGetValueHtmlWithoutShipmentSeparately($qty)
318+
{
319+
$model = $this->getMockBuilder(Renderer::class)
320+
->disableOriginalConstructor()
321+
->setMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
322+
->getMock();
323+
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
324+
$model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);
325+
$model->expects($this->any())->method('isChildCalculated')->willReturn(true);
326+
$model->expects($this->any())->method('getSelectionAttributes')->willReturn(['qty' => $qty]);
327+
$this->assertSame($qty . ' x Test', $model->getValueHtml($this->orderItem));
328+
}
329+
330+
/**
331+
* @return array
332+
*/
333+
public function getValueHtmlWithoutShipmentSeparatelyDataProvider()
334+
{
335+
return [
336+
[1],
337+
[1.5],
338+
];
339+
}
313340
}

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,31 @@ public function canShowPriceInfoDataProvider()
224224
[false, ['product_calculations' => 0], false],
225225
];
226226
}
227+
228+
/**
229+
* @dataProvider getValueHtmlWithoutShipmentSeparatelyDataProvider
230+
*/
231+
public function testGetValueHtmlWithoutShipmentSeparately($qty)
232+
{
233+
$model = $this->getMockBuilder(Renderer::class)
234+
->disableOriginalConstructor()
235+
->setMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
236+
->getMock();
237+
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
238+
$model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);
239+
$model->expects($this->any())->method('isChildCalculated')->willReturn(true);
240+
$model->expects($this->any())->method('getSelectionAttributes')->willReturn(['qty' => $qty]);
241+
$this->assertSame($qty . ' x Test', $model->getValueHtml($this->orderItem));
242+
}
243+
244+
/**
245+
* @return array
246+
*/
247+
public function getValueHtmlWithoutShipmentSeparatelyDataProvider()
248+
{
249+
return [
250+
[1],
251+
[1.5],
252+
];
253+
}
227254
}

app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,41 @@ public function canShowPriceInfoDataProvider()
286286
[false, ['product_calculations' => 0], false],
287287
];
288288
}
289+
290+
/**
291+
* @dataProvider getValueHtmlWithAttributesDataProvider
292+
*/
293+
public function testGetValueHtmlWithAttributes($qty)
294+
{
295+
$price = 100;
296+
$orderModel = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
297+
->disableOriginalConstructor()
298+
->onlyMethods(['formatPrice'])
299+
->getMock();
300+
$orderModel->expects($this->any())->method('formatPrice')->willReturn($price);
301+
302+
$model = $this->getMockBuilder(Renderer::class)
303+
->disableOriginalConstructor()
304+
->setMethods(['getOrder', 'getSelectionAttributes', 'escapeHtml'])
305+
->getMock();
306+
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
307+
$model->expects($this->any())->method('getOrder')->willReturn($orderModel);
308+
$model->expects($this->any())->method('getSelectionAttributes')
309+
->willReturn([
310+
'qty' => $qty ,
311+
'price' => $price,
312+
]);
313+
$this->assertSame($qty . ' x Test ' . $price, $model->getValueHtml($this->orderItem));
314+
}
315+
316+
/**
317+
* @return array
318+
*/
319+
public function getValueHtmlWithAttributesDataProvider()
320+
{
321+
return [
322+
[1],
323+
[1.5],
324+
];
325+
}
289326
}

app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Bundle\Test\Unit\Model\Sales\Order\Pdf\Items;
99

1010
use Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment;
11+
use Magento\Framework\Filter\FilterManager;
1112
use Magento\Framework\Serialize\Serializer\Json;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use Magento\Sales\Model\Order\Creditmemo;
@@ -33,20 +34,30 @@ class AbstractItemsTest extends TestCase
3334
*/
3435
private $orderItemMock;
3536

37+
/**
38+
* @var FilterManager|MockObject
39+
*/
40+
private $filterManagerMock;
41+
3642
protected function setUp(): void
3743
{
3844
$this->orderItemMock = $this->getMockBuilder(Item::class)
3945
->addMethods(['getOrderItem', 'getOrderItemId'])
4046
->onlyMethods(['getProductOptions', 'getParentItem', 'getId'])
4147
->disableOriginalConstructor()
4248
->getMock();
49+
$this->filterManagerMock = $this->getMockBuilder(FilterManager::class)
50+
->disableOriginalConstructor()
51+
->setMethods(['stripTags', 'sprintf'])
52+
->getMock();
4353

4454
$objectManager = new ObjectManager($this);
4555
$this->serializerMock = $this->createMock(Json::class);
4656
$this->model = $objectManager->getObject(
4757
Shipment::class,
4858
[
49-
'serializer' => $this->serializerMock
59+
'serializer' => $this->serializerMock,
60+
'filterManager' => $this->filterManagerMock,
5061
]
5162
);
5263
}
@@ -358,4 +369,32 @@ public function canShowPriceInfoDataProvider()
358369
[false, ['product_calculations' => 0], false],
359370
];
360371
}
372+
373+
/**
374+
* @dataProvider getValueHtmlWithoutShipmentSeparatelyDataProvider
375+
*/
376+
public function testGetValueHtmlWithoutShipmentSeparately($qty)
377+
{
378+
$this->filterManagerMock->expects($this->any())->method('stripTags')->willReturn('Test');
379+
$this->filterManagerMock->expects($this->any())->method('sprintf')->willReturn($qty);
380+
$this->orderItemMock->expects($this->any())->method('getProductOptions')
381+
->willReturn([
382+
'shipment_type' => 1,
383+
'bundle_selection_attributes' => [],
384+
]);
385+
$this->serializerMock->expects($this->any())->method('unserialize')
386+
->willReturn(['qty' => $qty]);
387+
$this->assertSame($qty . ' x Test', $this->model->getValueHtml($this->orderItemMock));
388+
}
389+
390+
/**
391+
* @return array
392+
*/
393+
public function getValueHtmlWithoutShipmentSeparatelyDataProvider()
394+
{
395+
return [
396+
[1],
397+
[1.5],
398+
];
399+
}
361400
}

0 commit comments

Comments
 (0)