assertCount(0, $section->getElements()); // Heading $styles = array('strong', 'em', 'sup', 'sub'); for ($level = 1; $level <= 6; $level++) { $content .= "Heading {$level}"; } // Styles $content .= '

'; foreach ($styles as $style) { $content .= "<{$style}>{$style}"; } $content .= '

'; // Add HTML Html::addHtml($section, $content); $this->assertCount(7, $section->getElements()); // Other parts $section = new Section(1); $content = ''; $content .= '
HeaderContent
'; $content .= ''; $content .= '
  1. Bullet
'; $content .= "'Single Quoted Text'"; $content .= '"Double Quoted Text"'; $content .= '& Ampersand'; $content .= '<>“‘’«»‹›'; $content .= '&•°…™©®—'; $content .= '–   ²³¼½¾'; Html::addHtml($section, $content); } /** * Test that html already in body element can be read * @ignore */ public function testParseFullHtml() { $section = new Section(1); Html::addHtml($section, '

test paragraph1

test paragraph2

', true); $this->assertCount(2, $section->getElements()); } /** * Test underline */ public function testParseUnderline() { $html = 'test'; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); Html::addHtml($section, $html); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:u')); $this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val')); } /** * Test text-decoration style */ public function testParseTextDecoration() { $html = 'test'; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); Html::addHtml($section, $html); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:u')); $this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val')); } /** * Test text-align style */ public function testParseTextAlign() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); Html::addHtml($section, '

test

'); Html::addHtml($section, '

test

'); Html::addHtml($section, '

test

'); Html::addHtml($section, '

test

'); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:jc')); $this->assertEquals('start', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:jc', 'w:val')); $this->assertEquals('end', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:jc', 'w:val')); $this->assertEquals('center', $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:jc', 'w:val')); $this->assertEquals('both', $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:jc', 'w:val')); } /** * Test parsing paragraph and span styles */ public function testParseParagraphAndSpanStyle() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); Html::addHtml($section, '

test

'); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:jc')); $this->assertEquals('center', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:jc', 'w:val')); $this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:r/w:rPr/w:u', 'w:val')); } /** * Test parsing table */ public function testParseTable() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $html = '
a b c
12
456
'; Html::addHtml($section, $html); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); // echo $doc->printXml(); // $this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr/w:tc')); } }