Skip to content

Commit

Permalink
feat: Support for padding in a table cell. More test file
Browse files Browse the repository at this point in the history
  • Loading branch information
OlisaevAG authored and OlisaevAG committed Nov 20, 2024
1 parent 29e979a commit 11056c2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
62 changes: 62 additions & 0 deletions tests/PhpWordTests/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\Shared\Html;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
use PhpOffice\PhpWord\SimpleType\TblWidth;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWordTests\AbstractWebServerEmbeddedTest;
use PhpOffice\PhpWordTests\TestHelperDOCX;
Expand Down Expand Up @@ -249,6 +251,66 @@ public function testParseLineHeight(): void
self::assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule'));
}

public function testParseCellPaddingStyle(): void
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();

$top = 10;
$right = 11;
$bottom = 12;
$left = 13;

$testValTop = Converter::pixelToTwip($top);
$testValRight = Converter::pixelToTwip($right);
$testValBottom = Converter::pixelToTwip($bottom);
$testValLeft = Converter::pixelToTwip($left);

$html = '<table>
<tbody>
<tr>
<td style="padding:' . $top . 'px ' . $right . 'px ' . $bottom . 'px ' . $left . 'px;">full</td>
<td style="padding:' . $top . 'px 0px ' . $bottom . 'px ' . $left . 'px;padding-right:' . $right . 'px;">mix</td>
<td style="padding-top:' . $top . 'px;">top</td>
<td style="padding-bottom:' . $bottom . 'px;">bottom</td>
<td style="padding-left:' . $left . 'px;">left</td>
</tr>
</tbody>
</table>';
Html::addHtml($section, $html);

$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');

$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:top';
self::assertTrue($doc->elementExists($path));
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:bottom';
self::assertTrue($doc->elementExists($path));
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:end';
self::assertTrue($doc->elementExists($path));
$path = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:tcMar/w:start';
self::assertTrue($doc->elementExists($path));

$path = '/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:tcPr/w:tcMar/w:end';
self::assertTrue($doc->elementExists($path));
self::assertEquals($testValRight, $doc->getElementAttribute($path, 'w:w'));
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));

$path = '/w:document/w:body/w:tbl/w:tr/w:tc[3]/w:tcPr/w:tcMar/w:top';
self::assertTrue($doc->elementExists($path));
self::assertEquals($testValTop, $doc->getElementAttribute($path, 'w:w'));
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));

$path = '/w:document/w:body/w:tbl/w:tr/w:tc[4]/w:tcPr/w:tcMar/w:bottom';
self::assertTrue($doc->elementExists($path));
self::assertEquals($testValBottom, $doc->getElementAttribute($path, 'w:w'));
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));

$path = '/w:document/w:body/w:tbl/w:tr/w:tc[5]/w:tcPr/w:tcMar/w:start';
self::assertTrue($doc->elementExists($path));
self::assertEquals($testValLeft, $doc->getElementAttribute($path, 'w:w'));
self::assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
}

/**
* Test text-indent style.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpWordTests/Writer/Word2007/Style/TableCellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function tearDown(): void
/**
* Test write styles.
*/
public function testCellSpacing(): void
public function testCellPadding(): void
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
Expand Down

0 comments on commit 11056c2

Please sign in to comment.