diff --git a/Tests/PHPWord/StyleTest.php b/Tests/PHPWord/StyleTest.php index 36e961ac..9e442cb1 100644 --- a/Tests/PHPWord/StyleTest.php +++ b/Tests/PHPWord/StyleTest.php @@ -1,7 +1,6 @@ createSection(); + $header = $section->createHeader(); + $header->addWatermark($imageSrc); + $doc = TestHelperDOCX::getDocument($PHPWord); + + $element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference"); + $this->assertStringStartsWith("rId", $element->getAttribute('r:id')); + } + + /** + * covers ::_writeTitle */ public function testWriteTitle() { diff --git a/Tests/PHPWord/Writer/Word2007/DocumentTest.php b/Tests/PHPWord/Writer/Word2007/DocumentTest.php index 7d06085a..fe854fee 100644 --- a/Tests/PHPWord/Writer/Word2007/DocumentTest.php +++ b/Tests/PHPWord/Writer/Word2007/DocumentTest.php @@ -32,4 +32,56 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $this->assertEquals(2, $element->getAttribute('w:start')); } + + /** + * covers ::_writeTOC + * covers ::_writePageBreak + * covers ::_writeListItem + * covers ::_writeTitle + * covers ::_writeObject + */ + public function testElements() + { + $objectSrc = join( + DIRECTORY_SEPARATOR, + array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + ); + + $PHPWord = new PHPWord(); + $PHPWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); + $PHPWord->addTitleStyle(2, array('color'=>'666666')); + $section = $PHPWord->createSection(); + $section->addTOC(); + $section->addPageBreak(); + $section->addTitle('Title 1', 1); + $section->addListItem('List Item 1', 0); + $section->addListItem('List Item 2', 0); + $section->addListItem('List Item 3', 0); + $section = $PHPWord->createSection(); + $section->addTitle('Title 2', 2); + $section->addObject($objectSrc); + $doc = TestHelperDOCX::getDocument($PHPWord); + + // TOC + $element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:tabs/w:tab'); + $this->assertEquals('right', $element->getAttribute('w:val')); + $this->assertEquals('dot', $element->getAttribute('w:leader')); + $this->assertEquals(9062, $element->getAttribute('w:pos')); + + // Page break + $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:br'); + $this->assertEquals('page', $element->getAttribute('w:type')); + + // Title + $element = $doc->getElement('/w:document/w:body/w:p[5]/w:pPr/w:pStyle'); + $this->assertEquals('Heading1', $element->getAttribute('w:val')); + + // List item + $element = $doc->getElement('/w:document/w:body/w:p[6]/w:pPr/w:numPr/w:numId'); + $this->assertEquals(3, $element->getAttribute('w:val')); + + // Object + $element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject'); + $this->assertEquals('Embed', $element->getAttribute('Type')); + } } diff --git a/Tests/PHPWord/Writer/Word2007/StylesTest.php b/Tests/PHPWord/Writer/Word2007/StylesTest.php index fe129f11..bcdc4b81 100644 --- a/Tests/PHPWord/Writer/Word2007/StylesTest.php +++ b/Tests/PHPWord/Writer/Word2007/StylesTest.php @@ -26,13 +26,31 @@ class StylesTest extends \PHPUnit_Framework_TestCase { $PHPWord = new PHPWord(); - $defaultStyle = array('align' => 'both'); - $baseStyle = array('basedOn' => 'Normal'); - $newStyle = array('basedOn' => 'Base Style', 'next' => 'Normal'); - $PHPWord->setDefaultParagraphStyle($defaultStyle); - $PHPWord->addParagraphStyle('Base Style', $baseStyle); - $PHPWord->addParagraphStyle('New Style', $newStyle); + $pStyle = array('align' => 'both'); + $pBase = array('basedOn' => 'Normal'); + $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal'); + $rStyle = array('size' => 20); + $tStyle = array( + 'bgColor' => 'FF0000', + 'cellMarginTop' => 120, + 'cellMarginBottom' => 120, + 'cellMarginLeft' => 120, + 'cellMarginRight' => 120, + 'borderTopSize' => 120, + 'borderBottomSize' => 120, + 'borderLeftSize' => 120, + 'borderRightSize' => 120, + 'borderInsideHSize' => 120, + 'borderInsideVSize' => 120, + ); + $PHPWord->setDefaultParagraphStyle($pStyle); + $PHPWord->addParagraphStyle('Base Style', $pBase); + $PHPWord->addParagraphStyle('New Style', $pNew); + $PHPWord->addFontStyle('New Style', $rStyle, $pStyle); + $PHPWord->addTableStyle('Table Style', $tStyle, $tStyle); + $PHPWord->addTitleStyle(1, $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($PHPWord); + $file = 'word/styles.xml'; // Normal style generated? diff --git a/samples/Sample_00.php b/samples/Sample_00.php deleted file mode 100644 index db490cbd..00000000 --- a/samples/Sample_00.php +++ /dev/null @@ -1,33 +0,0 @@ -'); -require_once '../Classes/PHPWord.php'; - -// New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); - -// Begin code - - - -// End code - -// Save file -$name = basename(__FILE__, '.php'); -$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); -foreach ($writers as $writer => $extension) { - echo date('H:i:s'), " Write to {$writer} format", EOL; - $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); - $objWriter->save("{$name}.{$extension}"); - rename("{$name}.{$extension}", "results/{$name}.{$extension}"); -} - -// Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;