Skip to content

Commit

Permalink
test: Add test case to check if unsetting vMerge works
Browse files Browse the repository at this point in the history
This should fix the reduction in test coverage because of the
new null checking code in the Setter
  • Loading branch information
SpraxDev committed Sep 13, 2024
1 parent 116be46 commit 2226a11
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/PhpWordTests/Writer/HTML/Element/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use DOMXPath;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\VerticalJc;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWordTests\Writer\HTML\Helper;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -199,4 +200,35 @@ public function testWriteTableCellVAlign(): void
$cell3Style = $cell3Query->item(0)->attributes->getNamedItem('style');
self::assertNull($cell3Style);
}

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

$table = $section->addTable();

$cell = $table->addRow()->addCell();
$cell->addText('text');
$cell->getStyle()->setVMerge(Style\Cell::VMERGE_RESTART);

$cell = $table->addRow()->addCell();
$cell->getStyle()->setVMerge(Style\Cell::VMERGE_CONTINUE);

$cell = $table->addRow()->addCell();
$cell->addText('no vMerge');
$cell->getStyle()->setVMerge(Style\Cell::VMERGE_CONTINUE);
$cell->getStyle()->setVMerge();

$dom = Helper::getAsHTML($phpWord);
$xpath = new DOMXPath($dom);

$cell1Style = Helper::getTextContent($xpath, '//table/tr[1]/td[1]', 'rowspan');
self::assertSame('2', $cell1Style);

$cell3Query = $xpath->query('//table/tr[3]/td[1]');
self::assertNotFalse($cell3Query);
self::assertCount(1, $cell3Query);
self::assertNull($cell3Query->item(0)->attributes->getNamedItem('rowspan'));
}
}

0 comments on commit 2226a11

Please sign in to comment.