Skip to content

Commit 8a9a478

Browse files
committed
add (failing) test and correct documentation sample to valid HTML
1 parent 9a91d54 commit 8a9a478

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

samples/Sample_26_Html.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
<ol>
3030
<li>List 2 item 1</li>
3131
<li>List 2 item 2</li>
32-
<ol>
33-
<li>sub list 1</li>
34-
<li>sub list 2</li>
35-
</ol>
32+
<li>
33+
<ol>
34+
<li>sub list 1</li>
35+
<li>sub list 2</li>
36+
</ol>
37+
</li>
38+
3639
<li>List 2 item 3</li>
3740
<ol>
3841
<li>sub list 1, restarts with a</li>

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,43 @@ public function tesOrderedListNumbering()
272272
$this->assertNotEquals($firstListnumId, $secondListnumId);
273273
}
274274

275+
/**
276+
* Tests parsing of nested ul/li
277+
*/
278+
public function testOrderedNestedListNumbering()
279+
{
280+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
281+
$section = $phpWord->addSection();
282+
$html = '<ol>
283+
<li>List 1 item 1</li>
284+
<li>List 1 item 2</li>
285+
</ol>
286+
<p>Some Text</p>
287+
<ol>
288+
<li>List 2 item 1</li>
289+
<li>
290+
<ol>
291+
<li>sub list 1</li>
292+
<li>sub list 2</li>
293+
</ol>
294+
</li>
295+
</ol>';
296+
Html::addHtml($section, $html, false, false);
297+
298+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
299+
echo $doc->printXml();
300+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:numPr/w:numId'));
301+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
302+
303+
$this->assertEquals('List 1 item 1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
304+
$this->assertEquals('List 2 item 1', $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:t')->nodeValue);
305+
306+
$firstListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId', 'w:val');
307+
$secondListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:numPr/w:numId', 'w:val');
308+
309+
$this->assertNotEquals($firstListnumId, $secondListnumId);
310+
}
311+
275312
/**
276313
* Tests parsing of ul/li
277314
*/

0 commit comments

Comments
 (0)