Skip to content

Commit 642fbd2

Browse files
committed
ACP2E-1216: Large area customizable option not able to render for print invoice PDF
1 parent c40c853 commit 642fbd2

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,96 @@ public function testInsertTotals()
114114

115115
$this->assertSame($page, $actual);
116116
}
117+
118+
/**
119+
* Test for the multiline text will be correctly wrapped between multiple pages
120+
*
121+
* @return void
122+
* @throws \ReflectionException
123+
*/
124+
public function testDrawLineBlocks()
125+
{
126+
// Setup constructor dependencies
127+
$paymentData = $this->createMock(Data::class);
128+
$string = $this->createMock(StringUtils::class);
129+
$scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
130+
$filesystem = $this->createMock(Filesystem::class);
131+
$pdfConfig = $this->createMock(Config::class);
132+
$pdfTotalFactory = $this->createMock(Factory::class);
133+
$pdfItemsFactory = $this->createMock(ItemsFactory::class);
134+
$localeMock = $this->getMockForAbstractClass(TimezoneInterface::class);
135+
$translate = $this->getMockForAbstractClass(StateInterface::class);
136+
$addressRenderer = $this->createMock(Renderer::class);
137+
138+
$abstractPdfMock = $this->getMockForAbstractClass(
139+
AbstractPdf::class,
140+
[
141+
$paymentData,
142+
$string,
143+
$scopeConfig,
144+
$filesystem,
145+
$pdfConfig,
146+
$pdfTotalFactory,
147+
$pdfItemsFactory,
148+
$localeMock,
149+
$translate,
150+
$addressRenderer
151+
],
152+
'',
153+
true,
154+
false,
155+
true,
156+
['_setFontRegular', '_getPdf']
157+
);
158+
159+
$page = $this->createMock(\Zend_Pdf_Page::class);
160+
$zendFont = $this->createMock(\Zend_Pdf_Font::class);
161+
$zendPdf = $this->createMock(\Zend_Pdf::class);
162+
163+
// Make sure that the newPage will be called 3 times to correctly break 200 lines into pages
164+
$zendPdf->expects($this->exactly(3))->method('newPage')->willReturn($page);
165+
166+
$abstractPdfMock->expects($this->once())->method('_setFontRegular')->willReturn($zendFont);
167+
$abstractPdfMock->expects($this->any())->method('_getPdf')->willReturn($zendPdf);
168+
169+
$reflectionMethod = new \ReflectionMethod(AbstractPdf::class, 'drawLineBlocks');
170+
171+
$drawBlockLineData = $this->generateMultilineDrawBlock(200);
172+
$pageSettings = [
173+
'table_header' => true
174+
];
175+
176+
$reflectionMethod->invoke($abstractPdfMock, $page, $drawBlockLineData, $pageSettings);
177+
}
178+
179+
/**
180+
* Generate the array for multiline block
181+
*
182+
* @param int $numberOfLines
183+
* @return array[]
184+
*/
185+
private function generateMultilineDrawBlock(int $numberOfLines): array
186+
{
187+
$lines = [];
188+
for ($x = 0; $x < $numberOfLines; $x++) {
189+
$lines [] = $x;
190+
}
191+
192+
$block = [
193+
[
194+
'lines' =>
195+
[
196+
[
197+
[
198+
'text' => $lines,
199+
'feed' => 40
200+
]
201+
]
202+
],
203+
'shift' => 5
204+
]
205+
];
206+
207+
return $block;
208+
}
117209
}

0 commit comments

Comments
 (0)