Skip to content

Commit 2226a11

Browse files
committed
test: Add test case to check if unsetting vMerge works
This should fix the reduction in test coverage because of the new null checking code in the Setter
1 parent 116be46 commit 2226a11

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/PhpWordTests/Writer/HTML/Element/TableTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use DOMXPath;
2121
use PhpOffice\PhpWord\PhpWord;
2222
use PhpOffice\PhpWord\SimpleType\VerticalJc;
23+
use PhpOffice\PhpWord\Style;
2324
use PhpOffice\PhpWordTests\Writer\HTML\Helper;
2425
use PHPUnit\Framework\TestCase;
2526

@@ -199,4 +200,35 @@ public function testWriteTableCellVAlign(): void
199200
$cell3Style = $cell3Query->item(0)->attributes->getNamedItem('style');
200201
self::assertNull($cell3Style);
201202
}
203+
204+
public function testWriteTableCellVMerge(): void
205+
{
206+
$phpWord = new PhpWord();
207+
$section = $phpWord->addSection();
208+
209+
$table = $section->addTable();
210+
211+
$cell = $table->addRow()->addCell();
212+
$cell->addText('text');
213+
$cell->getStyle()->setVMerge(Style\Cell::VMERGE_RESTART);
214+
215+
$cell = $table->addRow()->addCell();
216+
$cell->getStyle()->setVMerge(Style\Cell::VMERGE_CONTINUE);
217+
218+
$cell = $table->addRow()->addCell();
219+
$cell->addText('no vMerge');
220+
$cell->getStyle()->setVMerge(Style\Cell::VMERGE_CONTINUE);
221+
$cell->getStyle()->setVMerge();
222+
223+
$dom = Helper::getAsHTML($phpWord);
224+
$xpath = new DOMXPath($dom);
225+
226+
$cell1Style = Helper::getTextContent($xpath, '//table/tr[1]/td[1]', 'rowspan');
227+
self::assertSame('2', $cell1Style);
228+
229+
$cell3Query = $xpath->query('//table/tr[3]/td[1]');
230+
self::assertNotFalse($cell3Query);
231+
self::assertCount(1, $cell3Query);
232+
self::assertNull($cell3Query->item(0)->attributes->getNamedItem('rowspan'));
233+
}
202234
}

0 commit comments

Comments
 (0)