diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index d7171798..cb42cf3d 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -23,7 +23,7 @@ namespace PhpOffice\PhpWord\Element; * @method Text addText(string $text, mixed $fStyle = null, mixed $pStyle = null) * @method TextRun addTextRun(mixed $pStyle = null) * @method Bookmark addBookmark(string $name) - * @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null) + * @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null, boolean $internal = false) * @method PreserveText addPreserveText(string $text, mixed $fStyle = null, mixed $pStyle = null) * @method void addTextBreak(int $count = 1, mixed $fStyle = null, mixed $pStyle = null) * @method ListItem addListItem(string $txt, int $depth = 0, mixed $font = null, mixed $list = null, mixed $para = null) diff --git a/tests/PhpWord/Writer/ODText/Part/ContentTest.php b/tests/PhpWord/Writer/ODText/Part/ContentTest.php index 28542379..d5681143 100644 --- a/tests/PhpWord/Writer/ODText/Part/ContentTest.php +++ b/tests/PhpWord/Writer/ODText/Part/ContentTest.php @@ -83,6 +83,7 @@ class ContentTest extends \PHPUnit\Framework\TestCase $cell->addObject($objectSrc); $textrun = $cell->addTextRun(); $textrun->addText('Test text run'); + $section->addPageBreak(); $footer = $section->addFooter(); $footer->addPreserveText('{PAGE}'); diff --git a/tests/PhpWord/Writer/Word2007/ElementTest.php b/tests/PhpWord/Writer/Word2007/ElementTest.php index 85a9bb38..a81a617b 100644 --- a/tests/PhpWord/Writer/Word2007/ElementTest.php +++ b/tests/PhpWord/Writer/Word2007/ElementTest.php @@ -71,6 +71,68 @@ class ElementTest extends \PHPUnit\Framework\TestCase $this->assertTrue($doc->elementExists($element)); } + /** + * Test bookmark element + */ + public function testBookmark() + { + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + + $section->addBookmark('test_bookmark'); + $doc = TestHelperDOCX::getDocument($phpWord); + + $element = '/w:document/w:body/w:bookmarkStart'; + $this->assertTrue($doc->elementExists($element)); + $this->assertEquals('test_bookmark', $doc->getElementAttribute($element, 'w:name')); + + $element = '/w:document/w:body/w:bookmarkEnd'; + $this->assertTrue($doc->elementExists($element)); + } + + /** + * Test link element + */ + public function testLinkElement() + { + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + + $section->addLink('https://github.com/PHPOffice/PHPWord'); + $section->addLink('internal_link', null, null, null, true); + $doc = TestHelperDOCX::getDocument($phpWord); + + $element = '/w:document/w:body/w:p[1]/w:hyperlink/w:r/w:t'; + $this->assertTrue($doc->elementExists($element)); + + $element = '/w:document/w:body/w:p[2]/w:hyperlink/w:r/w:t'; + $this->assertTrue($doc->elementExists($element)); + $this->assertEquals('internal_link', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:hyperlink', 'w:anchor')); + } + + /** + * Basic test for table element + */ + public function testTableElements() + { + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + + $table = $section->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER)); + $table->addRow(900); + $table->addCell(2000)->addText('Row 1'); + $table->addCell(2000)->addText('Row 2'); + $table->addCell(2000)->addText('Row 3'); + $table->addCell(2000)->addText('Row 4'); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $tableRootElement = '/w:document/w:body/w:tbl'; + $this->assertTrue($doc->elementExists($tableRootElement . '/w:tblGrid/w:gridCol')); + $this->assertTrue($doc->elementExists($tableRootElement . '/w:tblPr/w:jc')); + $this->assertEquals('center', $doc->getElementAttribute($tableRootElement . '/w:tblPr/w:jc', 'w:val')); + } + /** * Test shape elements */ diff --git a/tests/PhpWord/Writer/Word2007/Style/FontTest.php b/tests/PhpWord/Writer/Word2007/Style/FontTest.php index 78b2c320..d36a3037 100644 --- a/tests/PhpWord/Writer/Word2007/Style/FontTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/FontTest.php @@ -50,4 +50,19 @@ class FontTest extends \PHPUnit\Framework\TestCase $path = '/w:document/w:body/w:p/w:r/w:rPr/w:rtl'; $this->assertTrue($doc->elementExists($path, $file)); } + + /** + * Test writing font with language + */ + public function testFontWithLang() + { + $phpWord = new \PhpOffice\PhpWord\PhpWord(); + $section = $phpWord->addSection(); + $section->addText('Ce texte-ci est en français.', array('lang' => \PhpOffice\PhpWord\Style\Language::FR_BE)); + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + + $file = 'word/document.xml'; + $path = '/w:document/w:body/w:p/w:r/w:rPr/w:lang'; + $this->assertTrue($doc->elementExists($path, $file)); + } } diff --git a/tests/PhpWord/Writer/Word2007/Style/ParagraphTest.php b/tests/PhpWord/Writer/Word2007/Style/ParagraphTest.php new file mode 100644 index 00000000..9bc2756b --- /dev/null +++ b/tests/PhpWord/Writer/Word2007/Style/ParagraphTest.php @@ -0,0 +1,52 @@ +addParagraphStyle('testStyle', array('indent' => '10')); + $section = $phpWord->addSection(); + $section->addText('test', null, array('numStyle' => 'testStyle', 'numLevel' => '1')); + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + + $path = '/w:document/w:body/w:p/w:pPr/w:numPr/w:ilvl'; + $this->assertTrue($doc->elementExists($path)); + } +}