addSection(); $section->addText('Doc without header or footer'); $contents = $parentWriter->getWriterPart('Document')->write(); self::assertEquals(0, preg_match('/\\\\header[rlf]?\\b/', $contents)); self::assertEquals(0, preg_match('/\\\\footer[rlf]?\\b/', $contents)); self::assertEquals(0, preg_match('/\\\\titlepg\\b/', $contents)); self::assertEquals(0, preg_match('/\\\\facingp\\b/', $contents)); } public function testNoHeaderYesFooter(): void { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $parentWriter = new RTF($phpWord); $section = $phpWord->addSection(); $footer = $section->addFooter(); $footer->addText('Auto footer'); $section->addText('Doc without header but with footer'); $contents = $parentWriter->getWriterPart('Document')->write(); self::assertEquals(0, preg_match('/\\\\header[rlf]?\\b/', $contents)); self::assertEquals(1, preg_match('/\\\\footer[rlf]?\\b/', $contents)); self::assertEquals(0, preg_match('/\\\\titlepg\\b/', $contents)); self::assertEquals(0, preg_match('/\\\\facingp\\b/', $contents)); } public function testEvenHeaderFirstFooter(): void { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->getSettings()->setEvenAndOddHeaders(true); $parentWriter = new RTF($phpWord); $section = $phpWord->addSection(); $footer = $section->addFooter(Footer::FIRST); $footer->addText('First footer'); $footer = $section->addHeader(Footer::EVEN); $footer->addText('Even footer'); $footer = $section->addHeader(Footer::AUTO); $footer->addText('Odd footer'); $section->addText('Doc with even/odd header and first footer'); $contents = $parentWriter->getWriterPart('Document')->write(); self::assertEquals(1, preg_match('/\\\\headerr\\b/', $contents)); self::assertEquals(1, preg_match('/\\\\headerl\\b/', $contents)); self::assertEquals(0, preg_match('/\\\\header[f]?\\b/', $contents)); self::assertEquals(1, preg_match('/\\\\footerf\\b/', $contents)); self::assertEquals(0, preg_match('/\\\\footer[rl]?\\b/', $contents)); self::assertEquals(1, preg_match('/\\\\titlepg\\b/', $contents)); self::assertEquals(1, preg_match('/\\\\facingp\\b/', $contents)); } }