Skip to content

Commit da7c0ad

Browse files
committed
Merge pull request #107 from gabrielbull/develop
Fixed bug with footer preserve text
2 parents 0b876a3 + 72fca30 commit da7c0ad

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

Classes/PHPWord/Writer/Word2007/Base.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null
285285
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
286286

287287
$arrText = $textrun->getText();
288+
if (!is_array($arrText)) {
289+
$arrText = array($arrText);
290+
}
288291

289292
$objWriter->startElement('w:p');
290293

Tests/PHPWord/Writer/Word2007/BaseTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,19 @@ public function testWriteParagraphStyle_Pagination()
108108
$this->assertEquals($expected, $element->getAttribute('w:val'));
109109
}
110110
}
111-
}
111+
112+
public function testWritePreserveText()
113+
{
114+
$PHPWord = new PHPWord();
115+
$section = $PHPWord->createSection();
116+
$footer = $section->createFooter();
117+
118+
$footer->addPreserveText('{PAGE}');
119+
120+
$doc = TestHelperDOCX::getDocument($PHPWord);
121+
$preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml');
122+
123+
$this->assertEquals('PAGE', $preserve->nodeValue);
124+
$this->assertEquals('preserve', $preserve->getAttribute('xml:space'));
125+
}
126+
}

Tests/_inc/TestHelperDOCX.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class TestHelperDOCX
1515
public static function getDocument(PHPWord $PHPWord)
1616
{
1717
self::$file = tempnam(sys_get_temp_dir(), 'PHPWord');
18-
if(!is_dir(sys_get_temp_dir().'/PHPWord_Unit_Test/')){
19-
mkdir(sys_get_temp_dir().'/PHPWord_Unit_Test/');
18+
if (!is_dir(sys_get_temp_dir() . '/PHPWord_Unit_Test/')) {
19+
mkdir(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
2020
}
2121

2222
$objWriter = \PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
@@ -29,16 +29,16 @@ public static function getDocument(PHPWord $PHPWord)
2929
$zip->close();
3030
}
3131

32-
return new Xml_Document(sys_get_temp_dir().'/PHPWord_Unit_Test/');
32+
return new Xml_Document(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
3333
}
3434

3535
public static function clear()
3636
{
37-
if(file_exists(self::$file)){
38-
unlink(self::$file);
37+
if (file_exists(self::$file)) {
38+
unlink(self::$file);
3939
}
40-
if(is_dir(sys_get_temp_dir().'/PHPWord_Unit_Test/')){
41-
self::deleteDir(sys_get_temp_dir().'/PHPWord_Unit_Test/');
40+
if (is_dir(sys_get_temp_dir() . '/PHPWord_Unit_Test/')) {
41+
self::deleteDir(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
4242
}
4343
}
4444

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"ext-xml": "*"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "3.7.28"
27+
"phpunit/phpunit": "3.7.*"
2828
},
2929
"recommend": {
3030
"ext-zip": "*",

0 commit comments

Comments
 (0)