From 47fa1f0c3b27868e88c55fcb637ed2b361f0b834 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Mon, 17 Mar 2014 19:43:38 +0700 Subject: [PATCH] Bugfix: Preserve text doesn't render correctly when the text is not the first word, e.g. 'Page {PAGE}' --- Classes/PHPWord/Section/Footer/PreserveText.php | 2 +- Tests/PHPWord/Section/Footer/PreserveTextTest.php | 2 +- Tests/PHPWord/Section/FooterTest.php | 2 +- Tests/PHPWord/Section/HeaderTest.php | 2 +- Tests/PHPWord/Section/Table/CellTest.php | 2 +- changelog.txt | 1 + samples/Sample_12_HeaderFooter.php | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Classes/PHPWord/Section/Footer/PreserveText.php b/Classes/PHPWord/Section/Footer/PreserveText.php index d0305fbc..0cac9b04 100755 --- a/Classes/PHPWord/Section/Footer/PreserveText.php +++ b/Classes/PHPWord/Section/Footer/PreserveText.php @@ -93,7 +93,7 @@ class PHPWord_Section_Footer_PreserveText $matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if (isset($matches[0])) { - $this->_text = $matches[0]; + $this->_text = $matches; } return $this; diff --git a/Tests/PHPWord/Section/Footer/PreserveTextTest.php b/Tests/PHPWord/Section/Footer/PreserveTextTest.php index 61f84ee5..3f73c1cb 100644 --- a/Tests/PHPWord/Section/Footer/PreserveTextTest.php +++ b/Tests/PHPWord/Section/Footer/PreserveTextTest.php @@ -18,7 +18,7 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase public function testConstructWithString() { $oPreserveText = new PHPWord_Section_Footer_PreserveText('text', 'styleFont', 'styleParagraph'); - $this->assertEquals($oPreserveText->getText(), 'text'); + $this->assertEquals($oPreserveText->getText(), array('text')); $this->assertEquals($oPreserveText->getFontStyle(), 'styleFont'); $this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); } diff --git a/Tests/PHPWord/Section/FooterTest.php b/Tests/PHPWord/Section/FooterTest.php index 10751d0e..2f244911 100644 --- a/Tests/PHPWord/Section/FooterTest.php +++ b/Tests/PHPWord/Section/FooterTest.php @@ -110,7 +110,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals($element->getText(), array('ééé')); } public function testGetElements() diff --git a/Tests/PHPWord/Section/HeaderTest.php b/Tests/PHPWord/Section/HeaderTest.php index 527ad3ee..c08aec24 100644 --- a/Tests/PHPWord/Section/HeaderTest.php +++ b/Tests/PHPWord/Section/HeaderTest.php @@ -106,7 +106,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals($element->getText(), array('ééé')); } public function testAddWatermark() diff --git a/Tests/PHPWord/Section/Table/CellTest.php b/Tests/PHPWord/Section/Table/CellTest.php index 30a7fcdb..3071e5f3 100644 --- a/Tests/PHPWord/Section/Table/CellTest.php +++ b/Tests/PHPWord/Section/Table/CellTest.php @@ -188,7 +188,7 @@ class CellTest extends \PHPUnit_Framework_TestCase $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals($element->getText(), array('ééé')); } public function testCreateTextRun() diff --git a/changelog.txt b/changelog.txt index 46b64423..ef1f2227 100755 --- a/changelog.txt +++ b/changelog.txt @@ -23,6 +23,7 @@ ************************************************************************************** Changes in branch for release 0.9.0 : +- Bugfix: (ivanlanin) - Preserve text doesn't render correctly when the text is not the first word, e.g. 'Page {PAGE}' - QA: (Progi1984) - Documentation Changes in branch for release 0.8.1 : diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php index 367076c6..5d1cdfe2 100644 --- a/samples/Sample_12_HeaderFooter.php +++ b/samples/Sample_12_HeaderFooter.php @@ -25,7 +25,7 @@ $subsequent->addText("Subsequent pages in Section 1 will Have this!"); // Add footer $footer = $section->createFooter(); -$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center')); +$footer->addPreserveText('Page {PAGE} of {NUMPAGES}', array('color' => 'FF0000'), array('align' => 'center')); // Write some text $section->addTextBreak();