Skip to content

Commit 11056c2

Browse files
OlisaevAGOlisaevAG
authored andcommitted
feat: Support for padding in a table cell. More test file
1 parent 29e979a commit 11056c2

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

tests/PhpWordTests/Shared/HtmlTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
use PhpOffice\PhpWord\Element\Section;
2222
use PhpOffice\PhpWord\Element\Table;
2323
use PhpOffice\PhpWord\PhpWord;
24+
use PhpOffice\PhpWord\Shared\Converter;
2425
use PhpOffice\PhpWord\Shared\Html;
2526
use PhpOffice\PhpWord\SimpleType\Jc;
2627
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
28+
use PhpOffice\PhpWord\SimpleType\TblWidth;
2729
use PhpOffice\PhpWord\Style\Paragraph;
2830
use PhpOffice\PhpWordTests\AbstractWebServerEmbeddedTest;
2931
use PhpOffice\PhpWordTests\TestHelperDOCX;
@@ -249,6 +251,66 @@ public function testParseLineHeight(): void
249251
self::assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule'));
250252
}
251253

254+
public function testParseCellPaddingStyle(): void
255+
{
256+
$phpWord = new PhpWord();
257+
$section = $phpWord->addSection();
258+
259+
$top = 10;
260+
$right = 11;
261+
$bottom = 12;
262+
$left = 13;
263+
264+
$testValTop = Converter::pixelToTwip($top);
265+
$testValRight = Converter::pixelToTwip($right);
266+
$testValBottom = Converter::pixelToTwip($bottom);
267+
$testValLeft = Converter::pixelToTwip($left);
268+
269+
$html = '<table>
270+
<tbody>
271+
<tr>
272+
<td style="padding:' . $top . 'px ' . $right . 'px ' . $bottom . 'px ' . $left . 'px;">full</td>
273+
<td style="padding:' . $top . 'px 0px ' . $bottom . 'px ' . $left . 'px;padding-right:' . $right . 'px;">mix</td>
274+
<td style="padding-top:' . $top . 'px;">top</td>
275+
<td style="padding-bottom:' . $bottom . 'px;">bottom</td>
276+
<td style="padding-left:' . $left . 'px;">left</td>
277+
</tr>
278+
</tbody>
279+
</table>';
280+
Html::addHtml($section, $html);
281+
282+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
283+
284+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:top';
285+
self::assertTrue($doc->elementExists($path));
286+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:bottom';
287+
self::assertTrue($doc->elementExists($path));
288+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:end';
289+
self::assertTrue($doc->elementExists($path));
290+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:start';
291+
self::assertTrue($doc->elementExists($path));
292+
293+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:tcPr/w:tcMar/w:end';
294+
self::assertTrue($doc->elementExists($path));
295+
self::assertEquals($testValRight, $doc->getElementAttribute($path, 'w:w'));
296+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
297+
298+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[3]/w:tcPr/w:tcMar/w:top';
299+
self::assertTrue($doc->elementExists($path));
300+
self::assertEquals($testValTop, $doc->getElementAttribute($path, 'w:w'));
301+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
302+
303+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[4]/w:tcPr/w:tcMar/w:bottom';
304+
self::assertTrue($doc->elementExists($path));
305+
self::assertEquals($testValBottom, $doc->getElementAttribute($path, 'w:w'));
306+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
307+
308+
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[5]/w:tcPr/w:tcMar/w:start';
309+
self::assertTrue($doc->elementExists($path));
310+
self::assertEquals($testValLeft, $doc->getElementAttribute($path, 'w:w'));
311+
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
312+
}
313+
252314
/**
253315
* Test text-indent style.
254316
*/

tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function tearDown(): void
4141
/**
4242
* Test write styles.
4343
*/
44-
public function testCellSpacing(): void
44+
public function testCellPadding(): void
4545
{
4646
$phpWord = new \PhpOffice\PhpWord\PhpWord();
4747
$section = $phpWord->addSection();

0 commit comments

Comments
 (0)