Example #1
3
 /**
  * Test write styles
  */
 public function testWriteStyles()
 {
     $phpWord = new PhpWord();
     $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?
     $path = '/w:styles/w:style[@w:styleId="Normal"]/w:name';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Normal', $element->getAttribute('w:val'));
     // Parent style referenced?
     $path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Base Style', $element->getAttribute('w:val'));
     // Next paragraph style correct?
     $path = '/w:styles/w:style[@w:styleId="New Style"]/w:next';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('Normal', $element->getAttribute('w:val'));
 }
 /**
  * Write footnotes
  */
 public function testWriteNumbering()
 {
     $xmlFile = 'word/numbering.xml';
     $phpWord = new PhpWord();
     $phpWord->addNumberingStyle('numStyle', array('type' => 'multilevel', 'levels' => array(array('start' => 1, 'format' => 'decimal', 'restart' => 1, 'suffix' => 'space', 'text' => '%1.', 'align' => 'left', 'left' => 360, 'hanging' => 360, 'tabPos' => 360, 'font' => 'Arial', 'hint' => 'default'))));
     $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
     $this->assertTrue($doc->elementExists('/w:numbering/w:abstractNum', $xmlFile));
 }
Example #3
0
 /**
  * Test compatibility
  */
 public function testCompatibility()
 {
     $phpWord = new PhpWord();
     $phpWord->getCompatibility()->setOoxmlVersion(15);
     $doc = TestHelperDOCX::getDocument($phpWord);
     $file = 'word/settings.xml';
     $path = '/w:settings/w:compat/w:compatSetting';
     $this->assertTrue($doc->elementExists($path, $file));
 }
Example #4
0
 /**
  * Test write styles
  */
 public function testFontRTL()
 {
     $phpWord = new \PhpOffice\PhpWord\PhpWord();
     $section = $phpWord->addSection();
     $textrun = $section->addTextRun();
     $textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true));
     $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
     $file = 'word/document.xml';
     $path = '/w:document/w:body/w:p/w:r/w:rPr/w:rtl';
     $this->assertTrue($doc->elementExists($path, $file));
 }
Example #5
0
 /**
  * Test if the tabs has been created properly
  */
 public function testTabsStyle()
 {
     $phpWord = new PhpWord();
     $phpWord->addParagraphStyle('tabbed', array('tabs' => array(new Tab('left', 1440, 'dot'))));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $file = 'word/styles.xml';
     $path = '/w:styles/w:style[@w:styleId="tabbed"]/w:pPr/w:tabs/w:tab[1]';
     $element = $doc->getElement($path, $file);
     $this->assertEquals('left', $element->getAttribute('w:val'));
     $this->assertEquals(1440, $element->getAttribute('w:pos'));
     $this->assertEquals('dot', $element->getAttribute('w:leader'));
 }
 /**
  * Write footnotes
  */
 public function testWriteFootnotes()
 {
     $phpWord = new PhpWord();
     $phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
     $section = $phpWord->addSection();
     $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
     $footnote1 = $section->addFootnote('pStyle');
     $footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8'));
     $footnote1->addTextBreak();
     $footnote1->addLink('https://github.com/PHPOffice/PHPWord');
     $footnote2 = $section->addEndnote(array('align' => 'left'));
     $footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8'));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
     $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference'));
 }
 /**
  * Write footnotes
  */
 public function testWriteFootnotes()
 {
     $phpWord = new PhpWord();
     $phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
     $section = $phpWord->addSection();
     $section->addText('Text');
     $footnote1 = $section->addFootnote('pStyle');
     $footnote1->addText('Footnote');
     $footnote1->addTextBreak();
     $footnote1->addLink('http://google.com');
     $footnote2 = $section->addEndnote(array('align' => 'left'));
     $footnote2->addText('Endnote');
     $doc = TestHelperDOCX::getDocument($phpWord);
     $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference"));
     $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:endnoteReference"));
 }
Example #8
0
 /**
  * Test set line height
  */
 public function testLineHeight()
 {
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     // Test style array
     $text = $section->addText('This is a test', array('line-height' => 2.0));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
     $lineHeight = $element->getAttribute('w:line');
     $lineRule = $element->getAttribute('w:lineRule');
     $this->assertEquals(480, $lineHeight);
     $this->assertEquals('auto', $lineRule);
     // Test setter
     $text->getFontStyle()->setLineHeight(3.0);
     $doc = TestHelperDOCX::getDocument($phpWord);
     $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');
     $lineHeight = $element->getAttribute('w:line');
     $lineRule = $element->getAttribute('w:lineRule');
     $this->assertEquals(720, $lineHeight);
     $this->assertEquals('auto', $lineRule);
 }
 /**
  * Test SDT elements
  */
 public function testSDTElements()
 {
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addSDT('comboBox');
     $section->addSDT('dropDownList');
     $section->addSDT('date');
     $doc = TestHelperDOCX::getDocument($phpWord);
     $path = "/w:document/w:body/w:p/w:sdt/w:sdtPr";
     $this->assertTrue($doc->elementExists($path . '/w:comboBox'));
     $this->assertTrue($doc->elementExists($path . '/w:dropDownList'));
     $this->assertTrue($doc->elementExists($path . '/w:date'));
 }
 /**
  * Test write gutter and line numbering
  */
 public function testWriteGutterAndLineNumbering()
 {
     $pageMarginPath = '/w:document/w:body/w:sectPr/w:pgMar';
     $lineNumberingPath = '/w:document/w:body/w:sectPr/w:lnNumType';
     $phpWord = new PhpWord();
     $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array()));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $this->assertEquals(240, $doc->getElement($pageMarginPath)->getAttribute('w:gutter'));
     $this->assertTrue($doc->elementExists($lineNumberingPath));
 }
Example #11
0
 /**
  * Test no paragraph style
  */
 public function testWriteNoStyle()
 {
     $phpWord = new PhpWord();
     $phpWord->addFontStyle('Font', array('size' => 11));
     $doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
     $element = "/office:document-content/office:automatic-styles/style:style";
     $this->assertTrue($doc->elementExists($element, 'content.xml'));
 }
 /**
  * Check content types
  */
 public function testCheckContentTypes()
 {
     $images = array('mars_noext_jpg' => '1.jpg', 'mars.jpg' => '2.jpg', 'mario.gif' => '3.gif', 'firefox.png' => '4.png', 'duke_nukem.bmp' => '5.bmp', 'angela_merkel.tif' => '6.tif');
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     foreach ($images as $source => $target) {
         $section->addImage(__DIR__ . "/../_files/images/{$source}");
     }
     $doc = TestHelperDOCX::getDocument($phpWord);
     $mediaPath = $doc->getPath() . "/word/media";
     foreach ($images as $source => $target) {
         $this->assertFileEquals(__DIR__ . "/../_files/images/{$source}", $mediaPath . "/section_image{$target}");
     }
 }
Example #13
-1
 /**
  * Test line element
  */
 public function testLineElement()
 {
     $phpWord = new PhpWord();
     $section = $phpWord->addSection();
     $section->addLine(array('width' => 1000, 'height' => 1000, 'positioning' => 'absolute', 'flip' => true));
     $doc = TestHelperDOCX::getDocument($phpWord);
     $element = "/w:document/w:body/w:p/w:r/w:pict/v:shapetype";
     $this->assertTrue($doc->elementExists($element));
 }