2014-05-11 19:41:48 +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-11 19:41:48 +07:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
|
|
|
|
*/
|
2017-11-04 22:44:12 +01:00
|
|
|
|
2015-11-15 13:33:05 +04:00
|
|
|
namespace PhpOffice\PhpWord\Writer\ODText;
|
2014-05-11 19:41:48 +07:00
|
|
|
|
2020-04-23 17:25:56 -07:00
|
|
|
use PhpOffice\PhpWord\Element\TrackChange;
|
2017-11-25 23:44:22 +01:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
2021-01-02 08:26:46 +01:00
|
|
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
2017-11-25 23:44:22 +01:00
|
|
|
use PhpOffice\PhpWord\TestHelperDOCX;
|
2014-05-11 19:41:48 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test class for PhpOffice\PhpWord\Writer\ODText\Element subnamespace
|
|
|
|
|
*/
|
2017-11-09 06:36:47 -02:00
|
|
|
class ElementTest extends \PHPUnit\Framework\TestCase
|
2014-05-11 19:41:48 +07:00
|
|
|
{
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
/**
|
|
|
|
|
* Executed after each method of the class
|
|
|
|
|
*/
|
2022-09-16 11:27:29 +02:00
|
|
|
public function tearDown(): void
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
{
|
|
|
|
|
TestHelperDOCX::clear();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-11 19:41:48 +07:00
|
|
|
/**
|
|
|
|
|
* Test unmatched elements
|
|
|
|
|
*/
|
|
|
|
|
public function testUnmatchedElements()
|
|
|
|
|
{
|
2020-02-06 19:20:13 -08:00
|
|
|
$elements = array('Image', 'Link', 'Table', 'Text', 'Title', 'Field');
|
2014-05-14 19:41:44 +07:00
|
|
|
foreach ($elements as $element) {
|
|
|
|
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $element;
|
2014-05-11 19:41:48 +07:00
|
|
|
$xmlWriter = new XMLWriter();
|
2014-05-14 19:41:44 +07:00
|
|
|
$newElement = new \PhpOffice\PhpWord\Element\PageBreak();
|
|
|
|
|
$object = new $objectClass($xmlWriter, $newElement);
|
2014-05-11 19:41:48 +07:00
|
|
|
$object->write();
|
|
|
|
|
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
self::assertEquals('', $xmlWriter->getData());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ODT Line Element not yet implemented
|
|
|
|
|
// ODT Bookmark not yet implemented
|
|
|
|
|
// ODT Table with style name not yet implemented (Word test defective)
|
|
|
|
|
// ODT Shape Elements not yet implemented
|
|
|
|
|
// ODT Chart Elements not yet implemented
|
|
|
|
|
// ODT adding Field to Section not yet implemented
|
|
|
|
|
// ODT List not yet implemented
|
|
|
|
|
// ODT Macro Button not yet implemented
|
|
|
|
|
// ODT Form Field not yet implemented
|
|
|
|
|
// ODT SDT not yet implemented
|
|
|
|
|
// ODT Comment not yet implemented
|
|
|
|
|
// ODT Track Changes implemented, possibly not correctly
|
|
|
|
|
// ODT List Item not yet implemented
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test link element
|
|
|
|
|
*/
|
|
|
|
|
public function testLinkElement()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
|
|
|
|
|
$extlink = 'https://github.com/PHPOffice/PHPWord';
|
|
|
|
|
$section->addLink($extlink);
|
|
|
|
|
$intlink = 'internal_link';
|
|
|
|
|
$section->addLink($intlink, null, null, null, true);
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
|
|
|
|
|
$p2t = '/office:document-content/office:body/office:text/text:section';
|
|
|
|
|
$element = "$p2t/text:p[2]/text:a";
|
|
|
|
|
self::assertTrue($doc->elementExists($element));
|
|
|
|
|
self::assertEquals($extlink, $doc->getElementAttribute($element, 'xlink:href'));
|
|
|
|
|
|
|
|
|
|
$element = "$p2t/text:p[3]/text:a";
|
|
|
|
|
self::assertTrue($doc->elementExists($element));
|
|
|
|
|
self::assertEquals("#$intlink", $doc->getElementAttribute($element, 'xlink:href'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Basic test for table element
|
|
|
|
|
*/
|
|
|
|
|
public function testTableElements()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
|
|
|
|
|
$table = $section->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER));
|
|
|
|
|
$table->addRow(900);
|
|
|
|
|
$table->addCell(2000)->addText('Row 1');
|
|
|
|
|
$table->addCell(2000)->addText('Row 2');
|
|
|
|
|
$table->addCell(2000)->addText('Row 3');
|
|
|
|
|
$table->addCell(2000)->addText('Row 4');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
|
|
|
|
|
$p2s = '/office:document-content/office:automatic-styles';
|
|
|
|
|
$tableStyleNum = 1;
|
|
|
|
|
$tableStyleName = '';
|
|
|
|
|
while ($tableStyleName === '') {
|
|
|
|
|
$element = "$p2s/style:style[$tableStyleNum]";
|
|
|
|
|
if (!$doc->elementExists($element)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ($doc->getElementAttribute($element, 'style:family') === 'table') {
|
|
|
|
|
$tableStyleName = $doc->getElementAttribute($element, 'style:name');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++$tableStyleNum;
|
2014-05-11 19:41:48 +07:00
|
|
|
}
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
self::AssertNotEquals('', $tableStyleName);
|
|
|
|
|
$element = "$element/style:table-properties";
|
|
|
|
|
self::assertTrue($doc->elementExists($element));
|
|
|
|
|
self::assertEquals(\PhpOffice\PhpWord\SimpleType\JcTable::CENTER, $doc->getElementAttribute($element, 'table:align'));
|
|
|
|
|
$p2t = '/office:document-content/office:body/office:text/text:section';
|
|
|
|
|
$tableRootElement = "$p2t/table:table";
|
|
|
|
|
self::assertTrue($doc->elementExists($tableRootElement));
|
|
|
|
|
self::assertEquals($tableStyleName, $doc->getElementAttribute($tableRootElement, 'table:style'));
|
|
|
|
|
self::assertTrue($doc->elementExists($tableRootElement . '/table:table-column[4]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test Title and Headings
|
|
|
|
|
*/
|
|
|
|
|
public function testTitleAndHeading()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new PhpWord();
|
|
|
|
|
$phpWord->addTitleStyle(0, array('size' => 14, 'italic' => true));
|
|
|
|
|
$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
|
|
|
|
|
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$section->addTitle('This is a title', 0);
|
|
|
|
|
$section->addTitle('Heading 1', 1);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
|
|
|
|
|
$p2t = '/office:document-content/office:body/office:text/text:section';
|
|
|
|
|
$element = "$p2t/text:h[1]";
|
|
|
|
|
$this->assertTrue($doc->elementExists($element));
|
|
|
|
|
$this->assertEquals('HE0', $doc->getElementAttribute($element, 'text:style-name'));
|
|
|
|
|
$this->assertEquals('0', $doc->getElementAttribute($element, 'text:outline-level'));
|
|
|
|
|
$span = "$element/text:span";
|
|
|
|
|
$this->assertTrue($doc->elementExists($span));
|
|
|
|
|
$this->assertEquals('This is a title', $doc->getElement($span)->textContent);
|
|
|
|
|
$this->assertEquals('Title', $doc->getElementAttribute($span, 'text:style-name'));
|
|
|
|
|
|
|
|
|
|
$element = "$p2t/text:h[2]";
|
|
|
|
|
$this->assertTrue($doc->elementExists($element));
|
|
|
|
|
$this->assertEquals('HD1', $doc->getElementAttribute($element, 'text:style-name'));
|
|
|
|
|
$this->assertEquals('1', $doc->getElementAttribute($element, 'text:outline-level'));
|
|
|
|
|
$span = "$element/text:span";
|
|
|
|
|
$this->assertTrue($doc->elementExists($span));
|
|
|
|
|
$this->assertEquals('Heading 1', $doc->getElement($span)->textContent);
|
|
|
|
|
$this->assertEquals('Heading_1', $doc->getElementAttribute($span, 'text:style-name'));
|
|
|
|
|
|
|
|
|
|
$doc->setDefaultFile('styles.xml');
|
|
|
|
|
$element = '/office:document-styles/office:styles/style:style[1]';
|
|
|
|
|
$this->assertTrue($doc->elementExists($element));
|
|
|
|
|
$this->assertEquals('Title', $doc->getElementAttribute($element, 'style:name'));
|
|
|
|
|
$element .= '/style:text-properties';
|
|
|
|
|
$this->assertTrue($doc->elementExists($element));
|
|
|
|
|
$this->assertEquals('14pt', $doc->getElementAttribute($element, 'fo:font-size'));
|
|
|
|
|
$this->assertEquals('italic', $doc->getElementAttribute($element, 'fo:font-style'));
|
|
|
|
|
$this->assertEquals('', $doc->getElementAttribute($element, 'fo:font-weight'));
|
|
|
|
|
$this->assertEquals('', $doc->getElementAttribute($element, 'fo:color'));
|
|
|
|
|
|
|
|
|
|
$element = '/office:document-styles/office:styles/style:style[2]';
|
|
|
|
|
$this->assertTrue($doc->elementExists($element));
|
|
|
|
|
$this->assertEquals('Heading_1', $doc->getElementAttribute($element, 'style:name'));
|
|
|
|
|
$element .= '/style:text-properties';
|
|
|
|
|
$this->assertTrue($doc->elementExists($element));
|
|
|
|
|
$this->assertEquals('20pt', $doc->getElementAttribute($element, 'fo:font-size'));
|
|
|
|
|
$this->assertEquals('', $doc->getElementAttribute($element, 'fo:font-style'));
|
|
|
|
|
$this->assertEquals('bold', $doc->getElementAttribute($element, 'fo:font-weight'));
|
|
|
|
|
$this->assertEquals('#333333', $doc->getElementAttribute($element, 'fo:color'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 17:25:56 -07:00
|
|
|
/**
|
|
|
|
|
* Test title specified as text run rather than text
|
|
|
|
|
*/
|
|
|
|
|
public function testTextRunTitle()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
$phpWord->addTitleStyle(1, array('name' => 'Times New Roman', 'size' => 18, 'bold' => true));
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$section->addTitle('Text Title', 1);
|
|
|
|
|
$section->addText('Text following Text Title');
|
|
|
|
|
$textRun = new \PhpOffice\PhpWord\Element\TextRun();
|
|
|
|
|
$textRun->addText('Text Run');
|
|
|
|
|
$textRun->addText(' Title');
|
|
|
|
|
$section->addTitle($textRun, 1);
|
|
|
|
|
$section->addText('Text following Text Run Title');
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
|
|
|
|
|
$p2t = '/office:document-content/office:body/office:text/text:section';
|
|
|
|
|
|
|
|
|
|
$element = "$p2t/text:h[1]";
|
|
|
|
|
$this->assertEquals('HE1', $doc->getElementAttribute($element, 'text:style-name'));
|
|
|
|
|
$this->assertEquals('1', $doc->getElementAttribute($element, 'text:outline-level'));
|
|
|
|
|
$span = "$element/text:span";
|
|
|
|
|
$this->assertEquals('Text Title', $doc->getElement($span)->textContent);
|
|
|
|
|
$this->assertEquals('Heading_1', $doc->getElementAttribute($span, 'text:style-name'));
|
|
|
|
|
$element = "$p2t/text:p[2]/text:span";
|
|
|
|
|
$this->assertEquals('Text following Text Title', $doc->getElement($element)->nodeValue);
|
|
|
|
|
|
|
|
|
|
$element = "$p2t/text:h[2]";
|
|
|
|
|
$this->assertEquals('HD1', $doc->getElementAttribute($element, 'text:style-name'));
|
|
|
|
|
$this->assertEquals('1', $doc->getElementAttribute($element, 'text:outline-level'));
|
|
|
|
|
$span = "$element/text:span";
|
|
|
|
|
$this->assertEquals('Text Run', $doc->getElement("$span/text:span[1]")->textContent);
|
|
|
|
|
$this->assertTrue($doc->elementExists("$span/text:span[2]/text:s"));
|
|
|
|
|
$this->assertEquals('Title', $doc->getElement("$span/text:span[2]")->textContent);
|
|
|
|
|
$this->assertEquals('Heading_1', $doc->getElementAttribute($span, 'text:style-name'));
|
|
|
|
|
$element = "$p2t/text:p[3]/text:span";
|
|
|
|
|
$this->assertEquals('Text following Text Run Title', $doc->getElement($element)->nodeValue);
|
|
|
|
|
}
|
|
|
|
|
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
/**
|
|
|
|
|
* Test correct writing of text with ampersand in it
|
|
|
|
|
*/
|
|
|
|
|
public function testTextWithAmpersand()
|
|
|
|
|
{
|
|
|
|
|
$esc = \PhpOffice\PhpWord\Settings::isOutputEscapingEnabled();
|
|
|
|
|
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
|
|
|
|
|
$phpWord = new PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$txt = 'this text contains an & (ampersand)';
|
|
|
|
|
$section->addText($txt);
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled($esc);
|
|
|
|
|
$p2t = '/office:document-content/office:body/office:text/text:section';
|
|
|
|
|
$element = "$p2t/text:p[2]";
|
|
|
|
|
$this->assertTrue($doc->elementExists($element));
|
|
|
|
|
$span = "$element/text:span";
|
|
|
|
|
$this->assertTrue($doc->elementExists($span));
|
|
|
|
|
$this->assertEquals($txt, $doc->getElement($span)->nodeValue);
|
2014-05-11 19:41:48 +07:00
|
|
|
}
|
2017-11-25 23:44:22 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test PageBreak
|
|
|
|
|
*/
|
|
|
|
|
public function testPageBreak()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new PhpWord();
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$section->addText('test');
|
|
|
|
|
$section->addPageBreak();
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$element = '/office:document-content/office:body/office:text/text:section/text:p[3]';
|
|
|
|
|
self::assertTrue($doc->elementExists($element, 'content.xml'));
|
|
|
|
|
self::assertEquals('PB', $doc->getElementAttribute($element, 'text:style-name', 'content.xml'));
|
2017-11-25 23:44:22 +01:00
|
|
|
}
|
2020-04-23 17:25:56 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test tracked changes
|
|
|
|
|
*/
|
|
|
|
|
public function testTrackedChanges()
|
|
|
|
|
{
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|
|
|
|
|
|
|
|
|
// New portrait section
|
|
|
|
|
$section = $phpWord->addSection();
|
|
|
|
|
$textRun = $section->addTextRun();
|
|
|
|
|
|
|
|
|
|
$text = $textRun->addText('Hello World! Time to ');
|
|
|
|
|
|
|
|
|
|
$text = $textRun->addText('wake ', array('bold' => true));
|
|
|
|
|
$text->setChangeInfo(TrackChange::INSERTED, 'Fred', time() - 1800);
|
|
|
|
|
|
|
|
|
|
$text = $textRun->addText('up');
|
|
|
|
|
$text->setTrackChange(new TrackChange(TrackChange::INSERTED, 'Fred'));
|
|
|
|
|
|
|
|
|
|
$text = $textRun->addText('go to sleep');
|
|
|
|
|
$text->setChangeInfo(TrackChange::DELETED, 'Barney', new \DateTime('@' . (time() - 3600)));
|
|
|
|
|
|
|
|
|
|
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
|
|
|
|
|
|
|
|
|
$tcs = '/office:document-content/office:body/office:text/text:tracked-changes';
|
|
|
|
|
$tc1 = "$tcs/text:changed-region[1]";
|
|
|
|
|
$tc1id = $doc->getElementAttribute($tc1, 'text:id');
|
|
|
|
|
$element = "$tc1/text:insertion";
|
|
|
|
|
self::assertTrue($doc->elementExists($element));
|
|
|
|
|
$element .= '/office:change-info';
|
|
|
|
|
self::AssertEquals('Fred', $doc->getElement("$element/dc:creator")->nodeValue);
|
|
|
|
|
self::assertTrue($doc->elementExists("$element/dc:date"));
|
|
|
|
|
|
|
|
|
|
$tc2 = "$tcs/text:changed-region[2]";
|
|
|
|
|
$tc2id = $doc->getElementAttribute($tc2, 'text:id');
|
|
|
|
|
$element = "$tc2/text:insertion";
|
|
|
|
|
self::assertTrue($doc->elementExists($element));
|
|
|
|
|
$element .= '/office:change-info';
|
|
|
|
|
self::AssertEquals('Fred', $doc->getElement("$element/dc:creator")->nodeValue);
|
|
|
|
|
//self::assertTrue($doc->elementExists("$element/dc:date"));
|
|
|
|
|
|
|
|
|
|
$tc3 = "$tcs/text:changed-region[3]";
|
|
|
|
|
$tc3id = $doc->getElementAttribute($tc3, 'text:id');
|
|
|
|
|
$element = "$tc3/text:deletion";
|
|
|
|
|
self::assertTrue($doc->elementExists($element));
|
|
|
|
|
$element .= '/office:change-info';
|
|
|
|
|
self::AssertEquals('Barney', $doc->getElement("$element/dc:creator")->nodeValue);
|
|
|
|
|
self::assertTrue($doc->elementExists("$element/dc:date"));
|
|
|
|
|
|
|
|
|
|
$p2t = '/office:document-content/office:body/office:text/text:section/text:p[2]';
|
|
|
|
|
$element = "$p2t/text:span[2]/text:change-start";
|
|
|
|
|
self::AssertEquals($tc1id, $doc->getElementAttribute($element, 'text:change-id'));
|
|
|
|
|
$element = "$p2t/text:span[3]/text:change-start";
|
|
|
|
|
self::AssertEquals($tc2id, $doc->getElementAttribute($element, 'text:change-id'));
|
|
|
|
|
$element = "$p2t/text:change";
|
|
|
|
|
self::AssertEquals($tc3id, $doc->getElementAttribute($element, 'text:change-id'));
|
|
|
|
|
}
|
2014-05-11 19:41:48 +07:00
|
|
|
}
|