Skip to content

Commit 47c837a

Browse files
committed
add unit tests
1 parent 46a5f96 commit 47c837a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/PhpWord/Shared/Html.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,6 @@ private static function parseCell($node, $element, &$styles)
366366
*/
367367
private static function shouldAddTextRun(\DOMNode $node)
368368
{
369-
if (!$node->hasChildNodes()) {
370-
return false;
371-
}
372-
373369
$containsBlockElement = self::$xpath->query('.//table|./p', $node)->length > 0;
374370
if ($containsBlockElement) {
375371
return false;

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,33 @@ public function testParseFontSize()
150150
$this->assertEquals('15', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:r/w:rPr/w:sz', 'w:val'));
151151
}
152152

153+
/**
154+
* Test direction style
155+
*/
156+
public function testParseTextDirection()
157+
{
158+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
159+
$section = $phpWord->addSection();
160+
Html::addHtml($section, '<span style="direction: rtl">test</span>');
161+
162+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
163+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:rtl'));
164+
}
165+
166+
/**
167+
* Test html lang
168+
*/
169+
public function testParseLang()
170+
{
171+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
172+
$section = $phpWord->addSection();
173+
Html::addHtml($section, '<span lang="fr-BE">test</span>');
174+
175+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
176+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:lang'));
177+
$this->assertEquals('fr-BE', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:lang', 'w:val'));
178+
}
179+
153180
/**
154181
* Test font-family style
155182
*/
@@ -199,7 +226,7 @@ public function testParseTable()
199226
</thead>
200227
<tbody>
201228
<tr><td style="border-style: dotted;">1</td><td colspan="2">2</td></tr>
202-
<tr><td>4</td><td>5</td><td>6</td></tr>
229+
<tr><td>This is <b>bold</b> text</td><td>5</td><td><p>6</p></td></tr>
203230
</tbody>
204231
</table>';
205232
Html::addHtml($section, $html);

0 commit comments

Comments
 (0)