Skip to content

Commit 3d6394c

Browse files
committed
ACP2E-1220: Misaligned Column Values in PDF
1 parent 088b434 commit 3d6394c

File tree

2 files changed

+309
-0
lines changed

2 files changed

+309
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Test\Unit\Model\Sales\Order\Pdf\Items;
9+
10+
use Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment;
11+
use Magento\Framework\Data\Collection\AbstractDb;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Filter\FilterManager;
15+
use Magento\Framework\Model\Context;
16+
use Magento\Framework\Model\ResourceModel\AbstractResource;
17+
use Magento\Framework\Registry;
18+
use Magento\Framework\Serialize\Serializer\Json;
19+
use Magento\Framework\Stdlib\StringUtils;
20+
use Magento\Sales\Model\Order;
21+
use Magento\Sales\Model\Order\Pdf\Invoice as InvoicePdf;
22+
use Magento\Tax\Helper\Data;
23+
use PHPUnit\Framework\MockObject\MockObject;
24+
use PHPUnit\Framework\TestCase;
25+
use Zend_Pdf_Page;
26+
27+
/**
28+
* Covers bundle order item invoice print logic
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
*/
31+
class ShipmentTest extends TestCase
32+
{
33+
/**
34+
* @var Shipment|MockObject
35+
*/
36+
private $model;
37+
38+
/**
39+
* @inheritDoc
40+
*/
41+
protected function setUp(): void
42+
{
43+
$contextMock = $this->createMock(Context::class);
44+
$registryMock = $this->createMock(Registry::class);
45+
$this->taxDataMock = $this->createMock(Data::class);
46+
$directoryMock = $this->createMock(Filesystem\Directory\Read::class);
47+
$directoryMock->expects($this->any())->method('getAbsolutePath')->willReturn('');
48+
$filesystemMock = $this->createMock(Filesystem::class);
49+
$filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($directoryMock);
50+
$filterManagerMock = $this->createMock(FilterManager::class);
51+
$stringUtils = new StringUtils();
52+
53+
$resourceMock = $this->createMock(AbstractResource::class);
54+
$collectionMock = $this->createMock(AbstractDb::class);
55+
$serializerMock = $this->createMock(Json::class);
56+
57+
$this->model = $this->getMockBuilder(Shipment::class)
58+
->setConstructorArgs(
59+
[
60+
$contextMock,
61+
$registryMock,
62+
$this->taxDataMock,
63+
$filesystemMock,
64+
$filterManagerMock,
65+
$stringUtils,
66+
$serializerMock,
67+
$resourceMock,
68+
$collectionMock,
69+
[]
70+
]
71+
)
72+
->onlyMethods(
73+
[
74+
'_setFontRegular',
75+
'getChildren',
76+
'isShipmentSeparately',
77+
'isChildCalculated',
78+
'getValueHtml',
79+
'getSelectionAttributes'
80+
]
81+
)
82+
->getMock();
83+
}
84+
85+
/**
86+
* @param array $expected
87+
*
88+
* @return void
89+
* @dataProvider \Magento\Bundle\Test\Unit\Model\Sales\Order\Pdf\Items\ShipmentTestProvider::getData
90+
*/
91+
public function testDrawPrice(array $expected): void
92+
{
93+
$pageMock = $this->createMock(Zend_Pdf_Page::class);
94+
$this->model->setPage($pageMock);
95+
$pdfMock = $this->createMock(InvoicePdf::class);
96+
$pdfMock->expects($this->any())->method('drawLineBlocks')->with(
97+
$pageMock,
98+
$expected,
99+
['table_header' => true]
100+
)->willReturn($pageMock);
101+
$this->model->setPdf($pdfMock);
102+
103+
$this->prepareModel();
104+
$this->model->draw();
105+
}
106+
107+
/**
108+
* Prepare invoice draw model for test execution
109+
*
110+
* @return void
111+
*/
112+
private function prepareModel(): void
113+
{
114+
$parentItem = new DataObject(
115+
[
116+
'sku' => 'bundle-simple',
117+
'name' => 'Bundle',
118+
'order_item' => new DataObject(
119+
[
120+
'sku' => 'bundle-simple',
121+
'name' => 'Bundle',
122+
'product_options' => []
123+
]
124+
)
125+
]
126+
);
127+
128+
$items = [
129+
new DataObject(
130+
[
131+
'name' => 'Simple1',
132+
'sku' => 'simple1',
133+
'price' => '10.00',
134+
'price_incl_tax' => '10.83',
135+
'row_total' => '20.00',
136+
'row_total_incl_tax' => '21.66',
137+
'qty' => '2',
138+
'tax_amount' => '1.66',
139+
'order_item' => new DataObject(
140+
[
141+
'parent_item' => $parentItem
142+
]
143+
)
144+
]
145+
),
146+
new DataObject(
147+
[
148+
'name' => 'Simple2',
149+
'sku' => 'simple2',
150+
'price' => '5.00',
151+
'price_incl_tax' => '5.41',
152+
'row_total' => '10.00',
153+
'row_total_incl_tax' => '10.83',
154+
'qty' => '2',
155+
'tax_amount' => '0.83',
156+
'order_item' => new DataObject(
157+
[
158+
'parent_item' => $parentItem
159+
]
160+
)
161+
]
162+
)
163+
];
164+
165+
$parentItem['order_item']['children_items'] = $items;
166+
167+
$orderMock = $this->createMock(Order::class);
168+
169+
$this->model->expects($this->any())->method('getChildren')->willReturn($items);
170+
$this->model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);
171+
$this->model->expects($this->any())->method('isChildCalculated')->willReturn(true);
172+
$this->model
173+
->method('getSelectionAttributes')
174+
->willReturnOnConsecutiveCalls(
175+
['option_id' => 1, 'option_label' => 'test option'],
176+
['option_id' => 1, 'option_label' => 'second option']
177+
);
178+
$this->model
179+
->method('getValueHtml')
180+
->willReturnOnConsecutiveCalls(
181+
$items[0]->getName(),
182+
$items[1]->getName()
183+
);
184+
185+
$orderMock->expects($this->any())->method('formatPriceTxt')->willReturnArgument(0);
186+
$this->model->setOrder($orderMock);
187+
$this->model->setItem($parentItem);
188+
}
189+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Test\Unit\Model\Sales\Order\Pdf\Items;
9+
10+
/**
11+
* Data provider class for ShipmentTest class
12+
*/
13+
class ShipmentTestProvider
14+
{
15+
/**
16+
* Returns shipment test variations data
17+
*
18+
* @return array[]
19+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
20+
*/
21+
public function getData(): array
22+
{
23+
return
24+
[
25+
[
26+
[
27+
1 =>
28+
[
29+
'lines' =>
30+
[
31+
0 =>
32+
[
33+
0 =>
34+
[
35+
'text' => 0,
36+
'feed' => 35,
37+
],
38+
1 =>
39+
[
40+
'text' =>
41+
[
42+
0 => 'Bundle',
43+
],
44+
'feed' => 100,
45+
],
46+
2 =>
47+
[
48+
'text' =>
49+
[
50+
0 => 'bundle-simple',
51+
],
52+
'feed' => 565,
53+
'align' => 'right',
54+
],
55+
],
56+
1 =>
57+
[
58+
0 =>
59+
[
60+
'text' => 0,
61+
'feed' => 35,
62+
],
63+
1 =>
64+
[
65+
'text' =>
66+
[
67+
0 => 'Simple1',
68+
],
69+
'feed' => 100,
70+
],
71+
2 =>
72+
[
73+
'text' =>
74+
[
75+
0 => 'simple1',
76+
],
77+
'feed' => 565,
78+
'align' => 'right',
79+
],
80+
],
81+
],
82+
'height' => 15,
83+
],
84+
0 =>
85+
[
86+
'lines' =>
87+
[
88+
0 =>
89+
[
90+
0 =>
91+
[
92+
'text' => 0,
93+
'feed' => 35,
94+
],
95+
1 =>
96+
[
97+
'text' =>
98+
[
99+
0 => 'Simple2',
100+
],
101+
'feed' => 100,
102+
],
103+
2 =>
104+
[
105+
'text' =>
106+
[
107+
0 => 'simple2',
108+
],
109+
'feed' => 565,
110+
'align' => 'right',
111+
],
112+
],
113+
],
114+
'height' => 15,
115+
],
116+
]
117+
]
118+
];
119+
}
120+
}

0 commit comments

Comments
 (0)