Bugfix: Preserve text doesn't render correctly when the text is not the first word, e.g. 'Page {PAGE}'

This commit is contained in:
Ivan Lanin 2014-03-17 19:43:38 +07:00
parent e89f24f7a7
commit 47fa1f0c3b
7 changed files with 7 additions and 6 deletions

View File

@ -93,7 +93,7 @@ class PHPWord_Section_Footer_PreserveText
$matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) { if (isset($matches[0])) {
$this->_text = $matches[0]; $this->_text = $matches;
} }
return $this; return $this;

View File

@ -18,7 +18,7 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
public function testConstructWithString() public function testConstructWithString()
{ {
$oPreserveText = new PHPWord_Section_Footer_PreserveText('text', 'styleFont', 'styleParagraph'); $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->getFontStyle(), 'styleFont');
$this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); $this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph');
} }

View File

@ -110,7 +110,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), array('ééé'));
} }
public function testGetElements() public function testGetElements()

View File

@ -106,7 +106,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), array('ééé'));
} }
public function testAddWatermark() public function testAddWatermark()

View File

@ -188,7 +188,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé'); $this->assertEquals($element->getText(), array('ééé'));
} }
public function testCreateTextRun() public function testCreateTextRun()

View File

@ -23,6 +23,7 @@
************************************************************************************** **************************************************************************************
Changes in branch for release 0.9.0 : 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 - QA: (Progi1984) - Documentation
Changes in branch for release 0.8.1 : Changes in branch for release 0.8.1 :

View File

@ -25,7 +25,7 @@ $subsequent->addText("Subsequent pages in Section 1 will Have this!");
// Add footer // Add footer
$footer = $section->createFooter(); $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 // Write some text
$section->addTextBreak(); $section->addTextBreak();