Merge pull request #1436 from begnini/fixing_title

HTML Title Writer loses text when Title contains a TextRun instead a string.
This commit is contained in:
troosan 2018-07-19 02:00:36 +02:00 committed by GitHub
commit 18c26f9218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -45,7 +45,7 @@ class Title extends AbstractElement
$text = $this->escaper->escapeHtml($text);
}
} elseif ($text instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
$writer = new Container($this->parentWriter, $this->element);
$writer = new Container($this->parentWriter, $text);
$text = $writer->write();
}

View File

@ -18,6 +18,7 @@
namespace PhpOffice\PhpWord\Writer\HTML;
use PhpOffice\PhpWord\Element\Text as TextElement;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Writer\HTML;
@ -138,4 +139,22 @@ class ElementTest extends \PHPUnit\Framework\TestCase
return $dom;
}
public function testWriteTitleTextRun()
{
$expected = 'Title with TextRun';
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$textRun = new TextRun();
$textRun->addText($expected);
$section->addTitle($textRun);
$htmlWriter = new HTML($phpWord);
$content = $htmlWriter->getContent();
$this->assertTrue(strpos($content, $expected) !== false);
}
}