2014-05-10 23:40:34 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
|
|
|
|
*
|
2017-11-04 22:44:12 +01:00
|
|
|
* @see https://github.com/PHPOffice/PHPWord
|
2018-03-08 23:52:25 +01:00
|
|
|
* @copyright 2010-2018 PHPWord contributors
|
2014-05-10 23:40:34 +07:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-15 13:33:05 +04:00
|
|
|
namespace PhpOffice\PhpWord\Shared;
|
2014-05-10 23:40:34 +07:00
|
|
|
|
2018-12-30 14:14:27 +01:00
|
|
|
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
|
2014-05-10 23:40:34 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Section;
|
2017-11-09 00:41:56 +01:00
|
|
|
use PhpOffice\PhpWord\SimpleType\Jc;
|
2018-03-19 22:49:00 +01:00
|
|
|
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
|
2018-03-19 23:06:00 +01:00
|
|
|
use PhpOffice\PhpWord\Style\Paragraph;
|
|
|
|
|
use PhpOffice\PhpWord\TestHelperDOCX;
|
2014-05-10 23:40:34 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test class for PhpOffice\PhpWord\Shared\Html
|
2017-11-09 00:41:56 +01:00
|
|
|
* @coversDefaultClass \PhpOffice\PhpWord\Shared\Html
|
2014-05-10 23:40:34 +07:00
|
|
|
*/
|
2018-12-30 14:14:27 +01:00
|
|
|
class HtmlTest extends AbstractWebServerEmbeddedTest
|
2014-05-10 23:40:34 +07:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Test unit conversion functions with various numbers
|
|
|
|
|
*/
|
|
|
|
|
public function testAddHtml()
|
|
|
|
|
{
|
|
|
|
|
$content = '';
|
|
|
|
|
|
|
|
|
|
// Default
|
2018-01-13 10:03:53 +01:00
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
2014-06-20 09:34:49 +04:00
|
|
|
$this->assertCount(0, $section->getElements());
|
2014-05-10 23:40:34 +07:00
|
|
|
|
|
|
|
|
// Heading
|
|
|
|
|
$styles = array('strong', 'em', 'sup', 'sub');
|
|
|
|
|
for ($level = 1; $level <= 6; $level++) {
|
|
|
|
|
$content .= "<h{$level}>Heading {$level}</h{$level}>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Styles
|
2015-02-06 22:28:31 +04:00
|
|
|
$content .= '<p style="text-decoration: underline; text-decoration: line-through; '
|
2017-11-09 00:41:56 +01:00
|
|
|
. 'text-align: center; color: #999; background-color: #000; font-weight: bold; font-style: italic;">';
|
2014-05-10 23:40:34 +07:00
|
|
|
foreach ($styles as $style) {
|
|
|
|
|
$content .= "<{$style}>{$style}</{$style}>";
|
|
|
|
|
}
|
|
|
|
|
$content .= '</p>';
|
|
|
|
|
|
|
|
|
|
// Add HTML
|
|
|
|
|
Html::addHtml($section, $content);
|
2014-06-20 09:34:49 +04:00
|
|
|
$this->assertCount(7, $section->getElements());
|
2014-05-10 23:40:34 +07:00
|
|
|
|
|
|
|
|
// Other parts
|
2018-01-13 10:03:53 +01:00
|
|
|
$section = $phpWord->addSection();
|
2014-05-10 23:40:34 +07:00
|
|
|
$content = '';
|
|
|
|
|
$content .= '<table><tr><th>Header</th><td>Content</td></tr></table>';
|
2014-05-31 03:28:58 +07:00
|
|
|
$content .= '<ul><li>Bullet</li><ul><li>Bullet</li></ul></ul>';
|
2014-05-10 23:40:34 +07:00
|
|
|
$content .= '<ol><li>Bullet</li></ol>';
|
2014-06-09 15:17:40 -06:00
|
|
|
$content .= "'Single Quoted Text'";
|
|
|
|
|
$content .= '"Double Quoted Text"';
|
|
|
|
|
$content .= '& Ampersand';
|
|
|
|
|
$content .= '<>“‘’«»‹›';
|
|
|
|
|
$content .= '&•°…™©®—';
|
|
|
|
|
$content .= '–   ²³¼½¾';
|
2014-05-31 03:28:58 +07:00
|
|
|
Html::addHtml($section, $content);
|
2014-05-10 23:40:34 +07:00
|
|
|
}
|
2017-11-09 00:41:56 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test that html already in body element can be read
|
|
|
|
|
* @ignore
|
|
|
|
|
*/
|
|
|
|
|
public function testParseFullHtml()
|
|
|
|
|
{
|
|
|
|
|
$section = new Section(1);
|
|
|
|
|
Html::addHtml($section, '<body><p>test paragraph1</p><p>test paragraph2</p></body>', true);
|
|
|
|
|
|
|
|
|
|
$this->assertCount(2, $section->getElements());
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-28 22:02:39 +01:00
|
|
|
/**
|
|
|
|
|
* Test HTML entities
|
|
|
|
|
*/
|
|
|
|
|
public function testParseHtmlEntities()
|
|
|
|
|
{
|
|
|
|
|
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, 'text with entities <my text>');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:r/w:t'));
|
|
|
|
|
$this->assertEquals('text with entities <my text>', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 00:41:56 +01:00
|
|
|
/**
|
|
|
|
|
* Test underline
|
|
|
|
|
*/
|
|
|
|
|
public function testParseUnderline()
|
|
|
|
|
{
|
|
|
|
|
$html = '<u>test</u>';
|
|
|
|
|
$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 = '<span style="text-decoration: underline;">test</span>';
|
|
|
|
|
$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'));
|
|
|
|
|
}
|
2018-05-23 18:48:28 +02:00
|
|
|
|
2018-05-23 18:22:54 +02:00
|
|
|
/**
|
|
|
|
|
* Test font
|
|
|
|
|
*/
|
|
|
|
|
public function testParseFont()
|
|
|
|
|
{
|
|
|
|
|
$html = '<font style="font-family: Arial;">test</font>';
|
|
|
|
|
$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'));
|
|
|
|
|
//TODO check style
|
|
|
|
|
}
|
2017-11-09 00:41:56 +01:00
|
|
|
|
2018-03-18 22:26:45 +01:00
|
|
|
/**
|
|
|
|
|
* Test line-height style
|
|
|
|
|
*/
|
|
|
|
|
public function testParseLineHeight()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, '<p style="line-height: 1.5;">test</p>');
|
2018-03-19 22:49:00 +01:00
|
|
|
Html::addHtml($section, '<p style="line-height: 15pt;">test</p>');
|
2018-04-14 22:42:58 +02:00
|
|
|
Html::addHtml($section, '<p style="line-height: 120%;">test</p>');
|
2018-06-13 17:41:17 +02:00
|
|
|
Html::addHtml($section, '<p style="line-height: 0.17in;">test</p>');
|
2021-04-15 21:04:45 +02:00
|
|
|
Html::addHtml($section, '<p style="line-height: normal;">test</p>');
|
2018-03-18 22:26:45 +01:00
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
2018-03-19 22:49:00 +01:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
|
|
|
|
|
$this->assertEquals(Paragraph::LINE_HEIGHT * 1.5, $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:spacing', 'w:line'));
|
|
|
|
|
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:spacing', 'w:lineRule'));
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[2]/w:pPr/w:spacing'));
|
|
|
|
|
$this->assertEquals(300, $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:spacing', 'w:line'));
|
|
|
|
|
$this->assertEquals(LineSpacingRule::EXACT, $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:spacing', 'w:lineRule'));
|
2018-04-14 22:42:58 +02:00
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:pPr/w:spacing'));
|
|
|
|
|
$this->assertEquals(Paragraph::LINE_HEIGHT * 1.2, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:line'));
|
|
|
|
|
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:lineRule'));
|
2018-06-13 17:41:17 +02:00
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[4]/w:pPr/w:spacing'));
|
|
|
|
|
$this->assertEquals(244.8, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:line'));
|
|
|
|
|
$this->assertEquals(LineSpacingRule::EXACT, $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:spacing', 'w:lineRule'));
|
2021-04-15 21:04:45 +02:00
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[5]/w:pPr/w:spacing'));
|
|
|
|
|
$this->assertEquals(Paragraph::LINE_HEIGHT, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:line'));
|
|
|
|
|
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[5]/w:pPr/w:spacing', 'w:lineRule'));
|
2018-03-18 22:26:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test text-indent style
|
|
|
|
|
*/
|
|
|
|
|
public function testParseTextIndent()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, '<p style="text-indent: 50px;">test</p>');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:ind'));
|
|
|
|
|
$this->assertEquals(750, $doc->getElementAttribute('/w:document/w:body/w:p/w:pPr/w:ind', 'w:firstLine'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 00:41:56 +01:00
|
|
|
/**
|
|
|
|
|
* Test text-align style
|
|
|
|
|
*/
|
|
|
|
|
public function testParseTextAlign()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, '<p style="text-align: left;">test</p>');
|
|
|
|
|
Html::addHtml($section, '<p style="text-align: right;">test</p>');
|
|
|
|
|
Html::addHtml($section, '<p style="text-align: center;">test</p>');
|
|
|
|
|
Html::addHtml($section, '<p style="text-align: justify;">test</p>');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:jc'));
|
2017-11-11 23:49:23 +01:00
|
|
|
$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, '<span style="font-size: 10pt;">test</span>');
|
|
|
|
|
Html::addHtml($section, '<span style="font-size: 10px;">test</span>');
|
|
|
|
|
|
|
|
|
|
$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'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 23:31:56 +01:00
|
|
|
/**
|
|
|
|
|
* Test direction style
|
|
|
|
|
*/
|
|
|
|
|
public function testParseTextDirection()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, '<span style="direction: rtl">test</span>');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:rtl'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test html lang
|
|
|
|
|
*/
|
|
|
|
|
public function testParseLang()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, '<span lang="fr-BE">test</span>');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:lang'));
|
|
|
|
|
$this->assertEquals('fr-BE', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:lang', 'w:val'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-11 23:49:23 +01:00
|
|
|
/**
|
|
|
|
|
* Test font-family style
|
|
|
|
|
*/
|
|
|
|
|
public function testParseFontFamily()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, '<span style="font-family: Arial">test</span>');
|
|
|
|
|
Html::addHtml($section, '<span style="font-family: Times New Roman;">test</span>');
|
|
|
|
|
|
|
|
|
|
$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'));
|
2017-11-09 00:41:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test parsing paragraph and span styles
|
|
|
|
|
*/
|
|
|
|
|
public function testParseParagraphAndSpanStyle()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
2018-01-13 10:03:53 +01:00
|
|
|
Html::addHtml($section, '<p style="text-align: center; margin-top: 15px; margin-bottom: 15px;"><span style="text-decoration: underline;">test</span></p>');
|
2017-11-09 00:41:56 +01:00
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:jc'));
|
2018-01-13 10:03:53 +01:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:spacing'));
|
2017-11-11 23:49:23 +01:00
|
|
|
$this->assertEquals(Jc::CENTER, $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:jc', 'w:val'));
|
2017-11-09 00:41:56 +01:00
|
|
|
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:r/w:rPr/w:u', 'w:val'));
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-06 21:58:16 +02:00
|
|
|
/**
|
|
|
|
|
* Test parsing paragraph with `page-break-after` style
|
|
|
|
|
*/
|
|
|
|
|
public function testParseParagraphWithPageBreak()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
Html::addHtml($section, '<p style="page-break-after:always;"></p>');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:br'));
|
|
|
|
|
$this->assertEquals('page', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:br', 'w:type'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 00:41:56 +01:00
|
|
|
/**
|
|
|
|
|
* Test parsing table
|
|
|
|
|
*/
|
|
|
|
|
public function testParseTable()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
2020-11-08 20:58:06 +01:00
|
|
|
$html = '<table align="left" style="width: 50%; border: 12px #0000FF double">
|
2017-11-09 00:41:56 +01:00
|
|
|
<thead>
|
2020-11-08 20:58:06 +01:00
|
|
|
<tr style="background-color: #FF0000; text-align: center; color: #FFFFFF; font-weight: bold">
|
|
|
|
|
<th style="width: 50pt"><p>header a</p></th>
|
|
|
|
|
<th style="width: 50; border-color: #00EE00; border-width: 3px"><span>header b</span></th>
|
2019-02-06 18:19:01 +01:00
|
|
|
<th style="border-color: #00AA00 #00BB00 #00CC00 #00DD00; border-width: 3px">header c</th>
|
2017-11-09 00:41:56 +01:00
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
2017-11-15 22:49:13 +01:00
|
|
|
<tr><td style="border-style: dotted;">1</td><td colspan="2">2</td></tr>
|
2018-02-06 23:31:56 +01:00
|
|
|
<tr><td>This is <b>bold</b> text</td><td>5</td><td><p>6</p></td></tr>
|
2017-11-09 00:41:56 +01:00
|
|
|
</tbody>
|
|
|
|
|
</table>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
2017-11-15 22:49:13 +01:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl'));
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr/w:tc'));
|
2017-12-29 14:36:07 +01:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tblPr/w:jc'));
|
|
|
|
|
$this->assertEquals(Jc::START, $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tblPr/w:jc', 'w:val'));
|
2019-02-06 22:07:42 +01:00
|
|
|
|
2019-02-06 18:19:01 +01:00
|
|
|
//check border colors
|
2019-02-06 22:07:42 +01:00
|
|
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:top', 'w:color'));
|
|
|
|
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:right', 'w:color'));
|
|
|
|
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:bottom', 'w:color'));
|
|
|
|
|
$this->assertEquals('00EE00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/w:left', 'w:color'));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('00AA00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:top', 'w:color'));
|
|
|
|
|
$this->assertEquals('00BB00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:right', 'w:color'));
|
|
|
|
|
$this->assertEquals('00CC00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:bottom', 'w:color'));
|
|
|
|
|
$this->assertEquals('00DD00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:left', 'w:color'));
|
2020-11-08 20:58:06 +01:00
|
|
|
|
|
|
|
|
//check borders are not propagated inside cells
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p'));
|
|
|
|
|
$this->assertFalse($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p/w:pPr/w:pBdr'));
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:p'));
|
|
|
|
|
$this->assertFalse($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:p/w:pPr/w:pBdr'));
|
2017-11-09 00:41:56 +01:00
|
|
|
}
|
2017-11-18 15:55:05 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests parsing of ul/li
|
|
|
|
|
*/
|
|
|
|
|
public function testParseList()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<ul>
|
|
|
|
|
<li>
|
|
|
|
|
<span style="font-family: arial,helvetica,sans-serif;">
|
|
|
|
|
<span style="font-size: 12px;">list item1</span>
|
|
|
|
|
</span>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<span style="font-family: arial,helvetica,sans-serif;">
|
2018-01-13 10:03:53 +01:00
|
|
|
<span style="font-size: 10px; font-weight: bold;">list item2</span>
|
2017-11-18 15:55:05 +01:00
|
|
|
</span>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>';
|
|
|
|
|
Html::addHtml($section, $html, false, false);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:numPr/w:numId'));
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
|
|
|
|
|
$this->assertEquals('list item1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
|
|
|
|
|
$this->assertEquals('list item2', $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:t')->nodeValue);
|
2018-01-13 10:03:53 +01:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:b'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests parsing of ul/li
|
|
|
|
|
*/
|
2018-02-01 14:12:56 +01:00
|
|
|
public function testOrderedListNumbering()
|
2018-01-13 10:03:53 +01:00
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<ol>
|
|
|
|
|
<li>List 1 item 1</li>
|
|
|
|
|
<li>List 1 item 2</li>
|
|
|
|
|
</ol>
|
|
|
|
|
<p>Some Text</p>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>List 2 item 1</li>
|
|
|
|
|
<li>List 2 item 2</li>
|
|
|
|
|
</ol>';
|
|
|
|
|
Html::addHtml($section, $html, false, false);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
2018-02-06 23:16:32 +01:00
|
|
|
|
2018-01-13 10:03:53 +01:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:numPr/w:numId'));
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('List 1 item 1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
|
|
|
|
|
$this->assertEquals('List 2 item 1', $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:t')->nodeValue);
|
|
|
|
|
|
|
|
|
|
$firstListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId', 'w:val');
|
|
|
|
|
$secondListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:numPr/w:numId', 'w:val');
|
2018-02-01 13:58:08 +01:00
|
|
|
|
|
|
|
|
$this->assertNotEquals($firstListnumId, $secondListnumId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests parsing of nested ul/li
|
|
|
|
|
*/
|
|
|
|
|
public function testOrderedNestedListNumbering()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<ol>
|
|
|
|
|
<li>List 1 item 1</li>
|
|
|
|
|
<li>List 1 item 2</li>
|
|
|
|
|
</ol>
|
|
|
|
|
<p>Some Text</p>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>List 2 item 1</li>
|
|
|
|
|
<li>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>sub list 1</li>
|
|
|
|
|
<li>sub list 2</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
</ol>';
|
|
|
|
|
Html::addHtml($section, $html, false, false);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
2018-02-08 07:18:02 +01:00
|
|
|
|
2018-02-01 13:58:08 +01:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:numPr/w:numId'));
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('List 1 item 1', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
|
|
|
|
|
$this->assertEquals('List 2 item 1', $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:t')->nodeValue);
|
|
|
|
|
|
|
|
|
|
$firstListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId', 'w:val');
|
|
|
|
|
$secondListnumId = $doc->getElementAttribute('/w:document/w:body/w:p[4]/w:pPr/w:numPr/w:numId', 'w:val');
|
2018-01-13 10:03:53 +01:00
|
|
|
|
|
|
|
|
$this->assertNotEquals($firstListnumId, $secondListnumId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests parsing of ul/li
|
|
|
|
|
*/
|
|
|
|
|
public function testParseListWithFormat()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = preg_replace('/\s+/', ' ', '<ul>
|
|
|
|
|
<li>Some text before
|
|
|
|
|
<span style="font-family: arial,helvetica,sans-serif;">
|
|
|
|
|
<span style="font-size: 12px;">list item1 <b>bold</b> with text after bold</span>
|
|
|
|
|
</span>
|
|
|
|
|
and some after
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<span style="font-family: arial,helvetica,sans-serif;">
|
|
|
|
|
<span style="font-size: 12px;">list item2</span>
|
|
|
|
|
</span>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>');
|
|
|
|
|
Html::addHtml($section, $html, false, false);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:pPr/w:numPr/w:numId'));
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
|
|
|
|
|
$this->assertEquals('list item2', $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:t')->nodeValue);
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:r[3]/w:rPr/w:b'));
|
|
|
|
|
$this->assertEquals('bold', $doc->getElement('/w:document/w:body/w:p[1]/w:r[3]/w:t')->nodeValue);
|
2017-11-18 15:55:05 +01:00
|
|
|
}
|
2017-12-05 17:33:51 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests parsing of br
|
|
|
|
|
*/
|
|
|
|
|
public function testParseLineBreak()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p>This is some text<br/>with a linebreak.</p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:br'));
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:t'));
|
|
|
|
|
$this->assertEquals('This is some text', $doc->getElement('/w:document/w:body/w:p/w:r[1]/w:t')->nodeValue);
|
|
|
|
|
$this->assertEquals('with a linebreak.', $doc->getElement('/w:document/w:body/w:p/w:r[2]/w:t')->nodeValue);
|
|
|
|
|
}
|
2017-12-21 00:03:52 +01:00
|
|
|
|
2018-01-13 10:03:53 +01:00
|
|
|
/**
|
|
|
|
|
* Test parsing of img
|
|
|
|
|
*/
|
2017-12-21 00:03:52 +01:00
|
|
|
public function testParseImage()
|
|
|
|
|
{
|
|
|
|
|
$src = __DIR__ . '/../_files/images/firefox.png';
|
|
|
|
|
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p><img src="' . $src . '" width="150" height="200" style="float: right;"/><img src="' . $src . '" style="float: left;"/></p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$baseXpath = '/w:document/w:body/w:p/w:r';
|
|
|
|
|
$this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
|
2018-02-06 23:16:32 +01:00
|
|
|
$this->assertStringMatchesFormat('%Swidth:150px%S', $doc->getElementAttribute($baseXpath . '[1]/w:pict/v:shape', 'style'));
|
|
|
|
|
$this->assertStringMatchesFormat('%Sheight:200px%S', $doc->getElementAttribute($baseXpath . '[1]/w:pict/v:shape', 'style'));
|
2017-12-21 00:03:52 +01:00
|
|
|
$this->assertStringMatchesFormat('%Smso-position-horizontal:right%S', $doc->getElementAttribute($baseXpath . '[1]/w:pict/v:shape', 'style'));
|
|
|
|
|
$this->assertStringMatchesFormat('%Smso-position-horizontal:left%S', $doc->getElementAttribute($baseXpath . '[2]/w:pict/v:shape', 'style'));
|
|
|
|
|
}
|
2018-01-25 23:24:21 +01:00
|
|
|
|
2018-05-23 18:22:54 +02:00
|
|
|
/**
|
|
|
|
|
* Test parsing of remote img
|
|
|
|
|
*/
|
|
|
|
|
public function testParseRemoteImage()
|
|
|
|
|
{
|
2018-12-30 14:14:27 +01:00
|
|
|
$src = self::getRemoteImageUrl();
|
2018-05-23 18:22:54 +02:00
|
|
|
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p><img src="' . $src . '" width="150" height="200" style="float: right;"/><img src="' . $src . '" style="float: left;"/></p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$baseXpath = '/w:document/w:body/w:p/w:r';
|
|
|
|
|
$this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
|
|
|
|
|
}
|
2018-05-23 18:48:28 +02:00
|
|
|
|
2018-05-24 07:19:45 +02:00
|
|
|
/**
|
|
|
|
|
* Test parsing embedded image
|
|
|
|
|
*/
|
|
|
|
|
public function testParseEmbeddedImage()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p><img src="data:image/jpeg;base64,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
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$baseXpath = '/w:document/w:body/w:p/w:r';
|
|
|
|
|
$this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 18:22:54 +02:00
|
|
|
/**
|
|
|
|
|
* Test parsing of remote img that can be found locally
|
|
|
|
|
*/
|
|
|
|
|
public function testParseRemoteLocalImage()
|
|
|
|
|
{
|
|
|
|
|
$src = 'https://fakedomain.io/images/firefox.png';
|
|
|
|
|
$localPath = __DIR__ . '/../_files/images/';
|
2018-05-23 18:48:28 +02:00
|
|
|
$options = array(
|
|
|
|
|
'IMG_SRC_SEARCH' => 'https://fakedomain.io/images/',
|
|
|
|
|
'IMG_SRC_REPLACE' => $localPath,
|
2018-05-23 18:35:12 +02:00
|
|
|
);
|
2018-05-23 18:22:54 +02:00
|
|
|
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p><img src="' . $src . '" width="150" height="200" style="float: right;"/></p>';
|
|
|
|
|
Html::addHtml($section, $html, false, true, $options);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$baseXpath = '/w:document/w:body/w:p/w:r';
|
|
|
|
|
$this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-25 08:01:17 +02:00
|
|
|
/**
|
|
|
|
|
* Test parsing of remote img that can be found locally
|
2018-05-27 20:53:42 +02:00
|
|
|
*
|
|
|
|
|
* @expectedException \Exception
|
2018-05-25 08:01:17 +02:00
|
|
|
*/
|
|
|
|
|
public function testCouldNotLoadImage()
|
|
|
|
|
{
|
|
|
|
|
$src = 'https://fakedomain.io/images/firefox.png';
|
|
|
|
|
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p><img src="' . $src . '" width="150" height="200" style="float: right;"/></p>';
|
|
|
|
|
Html::addHtml($section, $html, false, true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-25 23:24:21 +01:00
|
|
|
public function testParseLink()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p><a href="http://phpword.readthedocs.io/" style="text-decoration: underline">link text</a></p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
|
|
|
|
|
$this->assertEquals('link text', $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t')->nodeValue);
|
2018-04-25 23:57:07 +02:00
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink/w:r/w:rPr/w:u'));
|
|
|
|
|
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:hyperlink/w:r/w:rPr/w:u', 'w:val'));
|
2018-04-14 21:15:36 +02:00
|
|
|
|
2018-04-07 11:24:52 +02:00
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$section->addBookmark('bookmark');
|
|
|
|
|
$html = '<p><a href="#bookmark">internal link text</a></p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
|
|
|
|
|
$this->assertTrue($doc->getElement('/w:document/w:body/w:p/w:hyperlink')->hasAttribute('w:anchor'));
|
|
|
|
|
$this->assertEquals('bookmark', $doc->getElement('/w:document/w:body/w:p/w:hyperlink')->getAttribute('w:anchor'));
|
2018-01-25 23:24:21 +01:00
|
|
|
}
|
2018-02-27 23:24:01 +01:00
|
|
|
|
|
|
|
|
public function testParseMalformedStyleIsIgnored()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p style="">text</p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
$this->assertFalse($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:jc'));
|
|
|
|
|
}
|
2019-02-06 22:07:42 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests parsing hidden text
|
|
|
|
|
*/
|
|
|
|
|
public function testParseHiddenText()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p style="display: hidden">This is some hidden text.</p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:vanish'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests parsing letter spacing
|
|
|
|
|
*/
|
|
|
|
|
public function testParseLetterSpacing()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<p style="letter-spacing: 150px">This is some text with letter spacing.</p>';
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:spacing'));
|
|
|
|
|
$this->assertEquals(150 * 15, $doc->getElement('/w:document/w:body/w:p/w:r/w:rPr/w:spacing')->getAttribute('w:val'));
|
|
|
|
|
}
|
2020-03-01 18:15:27 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests checkbox input field
|
|
|
|
|
*/
|
2021-02-08 00:59:44 +01:00
|
|
|
public function testInputCheckbox()
|
2020-03-01 18:15:27 +00:00
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$html = '<input type="checkbox" checked="true" /><input type="checkbox" />';
|
2021-02-08 00:59:44 +01:00
|
|
|
Html::addHtml($section, $html);
|
2020-03-01 18:15:27 +00:00
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:r/w:fldChar/w:ffData/w:checkBox'));
|
|
|
|
|
$this->assertEquals(1, $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:fldChar/w:ffData/w:checkBox/w:checked')->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[2]/w:r/w:fldChar/w:ffData/w:checkBox'));
|
|
|
|
|
$this->assertEquals(0, $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:fldChar/w:ffData/w:checkBox/w:checked')->getAttribute('w:val'));
|
|
|
|
|
}
|
2021-02-07 23:30:28 +01:00
|
|
|
|
2021-02-10 21:10:06 +01:00
|
|
|
/**
|
2021-02-08 22:58:14 +01:00
|
|
|
* Parse widths in tables and cells, which also allows for controlling column width
|
|
|
|
|
*/
|
2020-07-10 12:43:19 +02:00
|
|
|
public function testParseTableAndCellWidth()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2021-02-08 22:40:46 +01:00
|
|
|
$section = $phpWord->addSection(array(
|
2020-07-10 12:43:19 +02:00
|
|
|
'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
|
2021-02-08 22:40:46 +01:00
|
|
|
));
|
2020-07-10 12:43:19 +02:00
|
|
|
|
|
|
|
|
// borders & backgrounds are here just for better visual comparison
|
|
|
|
|
$html = <<<HTML
|
|
|
|
|
<table style="border: 1px #000000 solid; width: 100%;">
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="width: 25%; border: 1px #000000 solid; text-align: center;">25%</td>
|
|
|
|
|
<td>
|
|
|
|
|
<table width="400" style="border: 1px #000000 solid; background-color: #EEEEEE;">
|
|
|
|
|
<tr>
|
|
|
|
|
<th colspan="3" style="border: 1px #000000 solid;">400px</th>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>T2.R2.C1</th>
|
|
|
|
|
<th style="width: 50pt; border: 1px #FF0000 dashed; background-color: #FFFFFF">50pt</th>
|
|
|
|
|
<th>T2.R2.C3</th>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<th width="300" colspan="2" style="border: 1px #000000 solid;">300px</th>
|
|
|
|
|
<th style="border: 1px #000000 solid;">T2.R3.C3</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
// outer table grid
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tblGrid/w:gridCol';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals(25 * 50, $doc->getElement($xpath)->getAttribute('w:w'));
|
|
|
|
|
$this->assertEquals('dxa', $doc->getElement($xpath)->getAttribute('w:type'));
|
|
|
|
|
|
|
|
|
|
// <td style="width: 25%; ...
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcW';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals(25 * 50, $doc->getElement($xpath)->getAttribute('w:w'));
|
|
|
|
|
$this->assertEquals('pct', $doc->getElement($xpath)->getAttribute('w:type'));
|
|
|
|
|
|
|
|
|
|
// <table width="400" .. 400px = 6000 twips (400 / 96 * 1440)
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tbl/w:tr/w:tc/w:tcPr/w:tcW';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals(6000, $doc->getElement($xpath)->getAttribute('w:w'));
|
|
|
|
|
$this->assertEquals('dxa', $doc->getElement($xpath)->getAttribute('w:type'));
|
|
|
|
|
|
|
|
|
|
// <th style="width: 50pt; .. 50pt = 750 twips (50 / 72 * 1440)
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tbl/w:tr[2]/w:tc[2]/w:tcPr/w:tcW';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals(1000, $doc->getElement($xpath)->getAttribute('w:w'));
|
|
|
|
|
$this->assertEquals('dxa', $doc->getElement($xpath)->getAttribute('w:type'));
|
|
|
|
|
|
|
|
|
|
// <th width="300" .. 300px = 4500 twips (300 / 96 * 1440)
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc/w:tbl/w:tr[3]/w:tc/w:tcPr/w:tcW';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals(4500, $doc->getElement($xpath)->getAttribute('w:w'));
|
|
|
|
|
$this->assertEquals('dxa', $doc->getElement($xpath)->getAttribute('w:type'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 15:42:28 +02:00
|
|
|
/**
|
2021-02-08 22:58:14 +01:00
|
|
|
* Test parsing background color for table rows and table cellspacing
|
|
|
|
|
*/
|
2020-07-11 00:24:08 +02:00
|
|
|
public function testParseCellspacingRowBgColor()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2021-02-08 22:58:14 +01:00
|
|
|
$section = $phpWord->addSection(array(
|
2020-07-11 00:24:08 +02:00
|
|
|
'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
|
2021-02-08 22:58:14 +01:00
|
|
|
));
|
2020-07-11 00:24:08 +02:00
|
|
|
|
|
|
|
|
// borders & backgrounds are here just for better visual comparison
|
|
|
|
|
$html = <<<HTML
|
|
|
|
|
<table cellspacing="3" bgColor="lightgreen" width="50%" align="center">
|
|
|
|
|
<tr>
|
|
|
|
|
<td>A</td>
|
|
|
|
|
<td>B</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr bgcolor="#FF0000">
|
|
|
|
|
<td>C</td>
|
|
|
|
|
<td>D</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellSpacing';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals(3 * 15, $doc->getElement($xpath)->getAttribute('w:w'));
|
|
|
|
|
$this->assertEquals('dxa', $doc->getElement($xpath)->getAttribute('w:type'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:shd';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals('lightgreen', $doc->getElement($xpath)->getAttribute('w:fill'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:shd';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals('FF0000', $doc->getElement($xpath)->getAttribute('w:fill'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 15:42:28 +02:00
|
|
|
/**
|
2021-02-08 22:58:14 +01:00
|
|
|
* Parse horizontal rule
|
|
|
|
|
*/
|
2022-09-06 21:58:16 +02:00
|
|
|
public function testParseHorizontalRule()
|
2020-07-11 15:42:28 +02:00
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
|
|
|
|
|
// borders & backgrounds are here just for better visual comparison
|
|
|
|
|
$html = <<<HTML
|
|
|
|
|
<p>Simple default rule:</p>
|
|
|
|
|
<hr/>
|
|
|
|
|
<p>Custom style rule:</p>
|
|
|
|
|
<hr style="margin-top: 30px; margin-bottom: 0; border-bottom: 5px lightblue solid;" />
|
|
|
|
|
<p>END</p>
|
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
// default rule
|
|
|
|
|
$xpath = '/w:document/w:body/w:p[2]/w:pPr/w:pBdr/w:bottom';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals('single', $doc->getElement($xpath)->getAttribute('w:val')); // solid
|
|
|
|
|
$this->assertEquals('1', $doc->getElement($xpath)->getAttribute('w:sz')); // 1 twip
|
|
|
|
|
$this->assertEquals('000000', $doc->getElement($xpath)->getAttribute('w:color')); // black
|
|
|
|
|
|
|
|
|
|
// custom style rule
|
|
|
|
|
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:pBdr/w:bottom';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals('single', $doc->getElement($xpath)->getAttribute('w:val'));
|
2021-02-08 22:58:14 +01:00
|
|
|
$this->assertEquals((int) (5 * 15 / 2), $doc->getElement($xpath)->getAttribute('w:sz'));
|
2020-07-11 15:42:28 +02:00
|
|
|
$this->assertEquals('lightblue', $doc->getElement($xpath)->getAttribute('w:color'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:spacing';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
2020-07-11 23:03:51 +02:00
|
|
|
$this->assertEquals(450, $doc->getElement($xpath)->getAttribute('w:before'));
|
2020-07-11 15:42:28 +02:00
|
|
|
$this->assertEquals(0, $doc->getElement($xpath)->getAttribute('w:after'));
|
|
|
|
|
$this->assertEquals(240, $doc->getElement($xpath)->getAttribute('w:line'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 17:20:36 +02:00
|
|
|
/**
|
2021-02-08 22:58:14 +01:00
|
|
|
* Parse ordered list start & numbering style
|
|
|
|
|
*/
|
2020-07-11 17:20:36 +02:00
|
|
|
public function testParseOrderedList()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
|
|
|
|
|
// borders & backgrounds are here just for better visual comparison
|
|
|
|
|
$html = <<<HTML
|
|
|
|
|
<ol>
|
|
|
|
|
<li>standard ordered list line 1</li>
|
|
|
|
|
<li>standard ordered list line 2</li>
|
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
<ol start="5" type="A">
|
|
|
|
|
<li>ordered list alphabetical, <span style="background-color: #EEEEEE; color: #FF0000;">line 5 => E</span></li>
|
|
|
|
|
<li>ordered list alphabetical, <span style="background-color: #EEEEEE; color: #FF0000;">line 6 => F</span></li>
|
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
<ol start="3" type="i">
|
|
|
|
|
<li>ordered list roman lower, line <b>3 => iii</b></li>
|
|
|
|
|
<li>ordered list roman lower, line <b>4 => iv</b></li>
|
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
// compare numbering file
|
|
|
|
|
$xmlFile = 'word/numbering.xml';
|
|
|
|
|
|
|
|
|
|
// default - decimal start = 1
|
|
|
|
|
$xpath = '/w:numbering/w:abstractNum[1]/w:lvl[1]/w:start';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath, $xmlFile));
|
|
|
|
|
$this->assertEquals('1', $doc->getElement($xpath, $xmlFile)->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:numbering/w:abstractNum[1]/w:lvl[1]/w:numFmt';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath, $xmlFile));
|
|
|
|
|
$this->assertEquals('decimal', $doc->getElement($xpath, $xmlFile)->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
// second list - start = 5, type A = upperLetter
|
|
|
|
|
$xpath = '/w:numbering/w:abstractNum[2]/w:lvl[1]/w:start';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath, $xmlFile));
|
|
|
|
|
$this->assertEquals('5', $doc->getElement($xpath, $xmlFile)->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:numbering/w:abstractNum[2]/w:lvl[1]/w:numFmt';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath, $xmlFile));
|
|
|
|
|
$this->assertEquals('upperLetter', $doc->getElement($xpath, $xmlFile)->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
// third list - start = 3, type i = lowerRoman
|
|
|
|
|
$xpath = '/w:numbering/w:abstractNum[3]/w:lvl[1]/w:start';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath, $xmlFile));
|
|
|
|
|
$this->assertEquals('3', $doc->getElement($xpath, $xmlFile)->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:numbering/w:abstractNum[3]/w:lvl[1]/w:numFmt';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath, $xmlFile));
|
|
|
|
|
$this->assertEquals('lowerRoman', $doc->getElement($xpath, $xmlFile)->getAttribute('w:val'));
|
|
|
|
|
}
|
2020-07-11 22:47:40 +02:00
|
|
|
|
|
|
|
|
/**
|
2021-02-08 22:58:14 +01:00
|
|
|
* Parse ordered list start & numbering style
|
|
|
|
|
*/
|
2020-07-11 22:47:40 +02:00
|
|
|
public function testParseVerticalAlign()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
|
|
|
|
|
// borders & backgrounds are here just for better visual comparison
|
|
|
|
|
$html = <<<HTML
|
|
|
|
|
<table width="100%">
|
|
|
|
|
<tr>
|
|
|
|
|
<td width="20%" style="border: 1px #666666 solid;">default</td>
|
|
|
|
|
<td width="20%" style="vertical-align: top; border: 1px #666666 solid;">top</td>
|
|
|
|
|
<td width="20%" style="vertical-align: middle; border: 1px #666666 solid;">middle</td>
|
|
|
|
|
<td width="20%" valign="bottom" style="border: 1px #666666 solid;">bottom</td>
|
|
|
|
|
<td bgcolor="#DDDDDD"><br/><br/><br/><br/><br/><br/><br/></td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc[1]/w:tcPr/w:vAlign';
|
|
|
|
|
$this->assertFalse($doc->elementExists($xpath));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc[2]/w:tcPr/w:vAlign';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals('top', $doc->getElement($xpath)->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc[3]/w:tcPr/w:vAlign';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals('center', $doc->getElement($xpath)->getAttribute('w:val'));
|
|
|
|
|
|
|
|
|
|
$xpath = '/w:document/w:body/w:tbl/w:tr/w:tc[4]/w:tcPr/w:vAlign';
|
|
|
|
|
$this->assertTrue($doc->elementExists($xpath));
|
|
|
|
|
$this->assertEquals('bottom', $doc->getElement($xpath)->getAttribute('w:val'));
|
|
|
|
|
}
|
2020-07-22 10:04:12 +02:00
|
|
|
|
|
|
|
|
/**
|
2021-02-08 22:58:14 +01:00
|
|
|
* Fix bug - don't decode double quotes inside double quoted string
|
|
|
|
|
*/
|
2020-07-22 10:04:12 +02:00
|
|
|
public function testDontDecodeAlreadyEncodedDoubleQuotes()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
|
|
|
|
|
// borders & backgrounds are here just for better visual comparison
|
|
|
|
|
$html = <<<HTML
|
|
|
|
|
<div style="font-family: Arial, "Helvetice Neue"">This would crash if inline quotes also decoded at loading XML into DOMDocument!</div>
|
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
|
|
Html::addHtml($section, $html);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
2021-02-08 22:58:14 +01:00
|
|
|
$this->assertInternalType('object', $doc);
|
2020-07-22 10:04:12 +02:00
|
|
|
}
|
2014-05-10 23:40:34 +07:00
|
|
|
}
|