Skip to content

Commit a44f185

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

File tree

4 files changed

+401
-87
lines changed

4 files changed

+401
-87
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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\Creditmemo;
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+
* Test for the vertical alignment of the printed elements of the creditmemo PDF
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30+
*/
31+
class CreditmemoTest extends TestCase
32+
{
33+
/**
34+
* @var Creditmemo|MockObject
35+
*/
36+
private $model;
37+
38+
/**
39+
* @var Data|MockObject
40+
*/
41+
private $taxDataMock;
42+
43+
/**
44+
* @inheritDoc
45+
*/
46+
protected function setUp(): void
47+
{
48+
$contextMock = $this->createMock(Context::class);
49+
$registryMock = $this->createMock(Registry::class);
50+
$this->taxDataMock = $this->createMock(Data::class);
51+
$directoryMock = $this->createMock(Filesystem\Directory\Read::class);
52+
$directoryMock->expects($this->any())->method('getAbsolutePath')->willReturn('');
53+
$filesystemMock = $this->createMock(Filesystem::class);
54+
$filesystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($directoryMock);
55+
$filterManagerMock = $this->createMock(FilterManager::class);
56+
$stringUtils = new StringUtils();
57+
$resourceMock = $this->createMock(AbstractResource::class);
58+
$collectionMock = $this->createMock(AbstractDb::class);
59+
$serializerMock = $this->createMock(Json::class);
60+
61+
$this->model = $this->getMockBuilder(Creditmemo::class)
62+
->setConstructorArgs(
63+
[
64+
$contextMock,
65+
$registryMock,
66+
$this->taxDataMock,
67+
$filesystemMock,
68+
$filterManagerMock,
69+
$serializerMock,
70+
$stringUtils,
71+
$resourceMock,
72+
$collectionMock,
73+
[]
74+
]
75+
)
76+
->onlyMethods(
77+
[
78+
'_setFontRegular',
79+
'getChildren',
80+
'isShipmentSeparately',
81+
'isChildCalculated',
82+
'getValueHtml',
83+
'getSelectionAttributes'
84+
]
85+
)
86+
->getMock();
87+
}
88+
89+
/**
90+
* @param array $expected
91+
* @param string $method
92+
*
93+
* @return void
94+
* @dataProvider \Magento\Bundle\Test\Unit\Model\Sales\Order\Pdf\Items\CreditmemoTestProvider::getData
95+
*/
96+
public function testDrawPrice(array $expected): void
97+
{
98+
$pageMock = $this->createMock(Zend_Pdf_Page::class);
99+
$this->model->setPage($pageMock);
100+
$pdfMock = $this->createMock(InvoicePdf::class);
101+
$pdfMock->expects($this->any())->method('drawLineBlocks')->with(
102+
$pageMock,
103+
$expected,
104+
['table_header' => true]
105+
)->willReturn($pageMock);
106+
$this->model->setPdf($pdfMock);
107+
108+
$this->prepareModel();
109+
$this->model->draw();
110+
}
111+
112+
/**
113+
* Prepare invoice draw model for test execution
114+
*
115+
* @return void
116+
*/
117+
private function prepareModel(): void
118+
{
119+
$parentItem = new DataObject(
120+
[
121+
'sku' => 'bundle-simple',
122+
'name' => 'Bundle',
123+
'order_item' => new DataObject(
124+
[
125+
'sku' => 'bundle-simple',
126+
'name' => 'Bundle',
127+
'product_options' => []
128+
]
129+
)
130+
]
131+
);
132+
133+
$items = [
134+
new DataObject(
135+
[
136+
'name' => 'Simple1',
137+
'sku' => 'simple1',
138+
'price' => '10.00',
139+
'price_incl_tax' => '10.83',
140+
'row_total' => '20.00',
141+
'row_total_incl_tax' => '21.66',
142+
'qty' => '2',
143+
'tax_amount' => '1.66',
144+
'order_item' => new DataObject(
145+
[
146+
'parent_item' => $parentItem
147+
]
148+
)
149+
]
150+
),
151+
new DataObject(
152+
[
153+
'name' => 'Simple2',
154+
'sku' => 'simple2',
155+
'price' => '5.00',
156+
'price_incl_tax' => '5.41',
157+
'row_total' => '10.00',
158+
'row_total_incl_tax' => '10.83',
159+
'qty' => '2',
160+
'tax_amount' => '0.83',
161+
'order_item' => new DataObject(
162+
[
163+
'parent_item' => $parentItem
164+
]
165+
)
166+
]
167+
)
168+
];
169+
170+
$parentItem['order_item']['children_items'] = $items;
171+
172+
$orderMock = $this->createMock(Order::class);
173+
174+
$this->model->expects($this->any())->method('getChildren')->willReturn($items);
175+
$this->model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);
176+
$this->model->expects($this->any())->method('isChildCalculated')->willReturn(true);
177+
$this->model
178+
->method('getSelectionAttributes')
179+
->willReturnOnConsecutiveCalls(
180+
['option_id' => 1, 'option_label' => 'test option'],
181+
['option_id' => 1, 'option_label' => 'second option']
182+
);
183+
$this->model
184+
->method('getValueHtml')
185+
->willReturnOnConsecutiveCalls(
186+
$items[0]->getName(),
187+
$items[1]->getName()
188+
);
189+
190+
$orderMock->expects($this->any())->method('formatPriceTxt')->willReturnArgument(0);
191+
$this->model->setOrder($orderMock);
192+
$this->model->setItem($parentItem);
193+
}
194+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 CresitmemoTest class
12+
*/
13+
class CreditmemoTestProvider
14+
{
15+
/**
16+
* Returns creditmemo test 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+
[
32+
[
33+
'font' => 'italic',
34+
'text' =>
35+
[
36+
'test option',
37+
],
38+
'feed' => 35,
39+
],
40+
],
41+
[
42+
[
43+
'text' =>
44+
[
45+
'Simple1',
46+
],
47+
'feed' => 40,
48+
],
49+
[
50+
'text' => '20.00',
51+
'feed' => 285,
52+
'font' => 'bold',
53+
'align' => 'right',
54+
'width' => 50,
55+
],
56+
[
57+
'text' => 0,
58+
'feed' => 335,
59+
'font' => 'bold',
60+
'align' => 'right',
61+
'width' => 50,
62+
],
63+
[
64+
'text' => 2,
65+
'feed' => 420,
66+
'font' => 'bold',
67+
'align' => 'right',
68+
'width' => 30,
69+
],
70+
[
71+
'text' => '1.66',
72+
'feed' => 455,
73+
'font' => 'bold',
74+
'align' => 'right',
75+
'width' => 45,
76+
],
77+
[
78+
'text' => 21.66,
79+
'feed' => 565,
80+
'font' => 'bold',
81+
'align' => 'right',
82+
],
83+
],
84+
[
85+
[
86+
'text' =>
87+
[
88+
'Simple2',
89+
],
90+
'feed' => 40,
91+
],
92+
[
93+
'text' => '10.00',
94+
'feed' => 285,
95+
'font' => 'bold',
96+
'align' => 'right',
97+
'width' => 50,
98+
],
99+
[
100+
'text' => 0,
101+
'feed' => 335,
102+
'font' => 'bold',
103+
'align' => 'right',
104+
'width' => 50,
105+
],
106+
[
107+
'text' => 2,
108+
'feed' => 420,
109+
'font' => 'bold',
110+
'align' => 'right',
111+
'width' => 30,
112+
],
113+
[
114+
'text' => '0.83',
115+
'feed' => 455,
116+
'font' => 'bold',
117+
'align' => 'right',
118+
'width' => 45,
119+
],
120+
[
121+
'text' => 10.83,
122+
'feed' => 565,
123+
'font' => 'bold',
124+
'align' => 'right',
125+
],
126+
],
127+
],
128+
'height' => 15,
129+
],
130+
],
131+
],
132+
];
133+
}
134+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use Zend_Pdf_Page;
2626

2727
/**
28-
* Covers bundle order item invoice print logic
28+
* Test for the vertical alignment of the printed elements of the shipment PDF
2929
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3030
*/
3131
class ShipmentTest extends TestCase

0 commit comments

Comments
 (0)