assertCount(0, $section->getElements());
// Heading
$styles = array('strong', 'em', 'sup', 'sub');
for ($level = 1; $level <= 6; $level++) {
$content .= "
'; foreach ($styles as $style) { $content .= "<{$style}>{$style}{$style}>"; } $content .= '
'; // Add HTML Html::addHtml($section, $content); $this->assertCount(7, $section->getElements()); // Other parts $section = new Section(1); $content = ''; $content .= '| Header | Content |
|---|
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(Jc::START, $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:jc', 'w:val')); $this->assertEquals(Jc::END, $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:jc', 'w:val')); $this->assertEquals(Jc::CENTER, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:jc', 'w:val')); $this->assertEquals(Jc::BOTH, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:jc', 'w:val')); } /** * Test font-size style */ public function testParseFontSize() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); Html::addHtml($section, 'test'); Html::addHtml($section, 'test'); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:sz')); $this->assertEquals('20', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:r/w:rPr/w:sz', 'w:val')); $this->assertEquals('15', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:r/w:rPr/w:sz', 'w:val')); } /** * Test font-family style */ public function testParseFontFamily() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); Html::addHtml($section, 'test'); Html::addHtml($section, 'test'); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:rFonts')); $this->assertEquals('Arial', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:r/w:rPr/w:rFonts', 'w:ascii')); $this->assertEquals('Times New Roman', $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:r/w:rPr/w:rFonts', 'w:ascii')); } /** * 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(Jc::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 = '| header a | header b | header c |
|---|---|---|
| 1 | 2 | |
| 4 | 5 | 6 |
This is some text
with a linebreak.