|
15 | 15 | *
|
16 | 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
17 | 17 | */
|
| 18 | + |
18 | 19 | declare(strict_types=1);
|
19 | 20 |
|
20 | 21 | namespace PhpOffice\PhpWordTests\Writer\Word2007\Element;
|
@@ -54,4 +55,30 @@ public function testWriteTitlePageNumber(): void
|
54 | 55 | self::assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:t'));
|
55 | 56 | self::assertEquals($expectedPageNum, $doc->getElement('/w:document/w:body/w:p[1]/w:hyperlink/w:r[6]/w:t')->textContent);
|
56 | 57 | }
|
| 58 | + |
| 59 | + public function testWriteTitleWithoutpageNumber(): void |
| 60 | + { |
| 61 | + $phpWord = new PhpWord(); |
| 62 | + |
| 63 | + $section = $phpWord->addSection(); |
| 64 | + $section->addTOC(); |
| 65 | + |
| 66 | + //more than one title and random text for create more than one page |
| 67 | + for ($i = 1; $i <= 10; ++$i) { |
| 68 | + $section->addTitle('Title ' . $i, 1); |
| 69 | + $content = file_get_contents('https://loripsum.net/api/10/long'); |
| 70 | + \PhpOffice\PhpWord\Shared\Html::addHtml($section, $content ? $content : '', false, false); |
| 71 | + $section->addPageBreak(); |
| 72 | + } |
| 73 | + |
| 74 | + $doc = TestHelperDOCX::getDocument($phpWord); |
| 75 | + |
| 76 | + for ($i = 1; $i <= 10; ++$i) { |
| 77 | + self::assertTrue($doc->elementExists('/w:document/w:body/w:p[' . $i . ']/w:hyperlink/w:r[1]/w:t')); |
| 78 | + self::assertEquals('Title ' . $i, $doc->getElement('/w:document/w:body/w:p[' . $i . ']/w:hyperlink/w:r[1]/w:t')->textContent); |
| 79 | + self::assertTrue($doc->elementExists('/w:document/w:body/w:p[' . $i . ']/w:hyperlink/w:r[4]/w:instrText')); |
| 80 | + self::assertEquals('preserve', $doc->getElementAttribute('/w:document/w:body/w:p[' . $i . ']/w:hyperlink/w:r[4]/w:instrText', 'xml:space')); |
| 81 | + self::assertEquals('PAGEREF ' . ($i - 1) . ' \\h', $doc->getElement('/w:document/w:body/w:p[' . $i . ']/w:hyperlink/w:r[4]/w:instrText')->nodeValue); |
| 82 | + } |
| 83 | + } |
57 | 84 | }
|
0 commit comments