From e404c527f92b1221f023e1448512acf3d4a4cf39 Mon Sep 17 00:00:00 2001 From: Michael Chrisco Date: Fri, 20 Nov 2015 14:14:02 -0800 Subject: [PATCH 1/2] Bump to travis php version Small code coverage on section footers --- .travis.yml | 2 ++ composer.json | 2 +- tests/PhpWord/Element/SectionTest.php | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c39a05c460..0712f73461 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,12 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm matrix: allow_failures: + - php: 7.0 - php: hhvm env: diff --git a/composer.json b/composer.json index 9629e3067c..993bef894b 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "phpmd/phpmd": "2.*", "phploc/phploc": "2.*", "dompdf/dompdf":"0.6.*", - "tecnick.com/tcpdf": "6.*", + "tecnickcom/tcpdf": "6.*", "mpdf/mpdf": "5.*", "zendframework/zend-validator": "2.5.*" }, diff --git a/tests/PhpWord/Element/SectionTest.php b/tests/PhpWord/Element/SectionTest.php index adad9daa71..1a5c2f845e 100644 --- a/tests/PhpWord/Element/SectionTest.php +++ b/tests/PhpWord/Element/SectionTest.php @@ -164,6 +164,16 @@ public function testCreateHeaderFooter() $this->assertFalse($object->hasDifferentFirstPage()); } + /** + * Add footer has same first page + */ + public function testaddFooter(){ + $object = new Section(1); + $footer = $object->addFooter(); + $footer->addText('footer'); + $this->assertFalse($object->hasDifferentFirstPage()); + } + /** * Add header has different first page */ From 60cce62297c4fff06773e27aceec7cea2d651ff8 Mon Sep 17 00:00:00 2001 From: MichaelAChrisco Date: Sun, 22 Nov 2015 12:14:39 -0800 Subject: [PATCH 2/2] PHP 7.0 potected word String - Renamed PHP Word String to Common String --- src/PhpWord/Element/Bookmark.php | 4 +-- src/PhpWord/Element/CheckBox.php | 4 +-- src/PhpWord/Element/Link.php | 6 ++-- src/PhpWord/Element/ListItem.php | 4 +-- src/PhpWord/Element/PreserveText.php | 4 +-- src/PhpWord/Element/Text.php | 4 +-- src/PhpWord/Element/Title.php | 4 +-- .../Shared/{String.php => CommonString.php} | 2 +- src/PhpWord/Style/AbstractStyle.php | 4 +-- src/PhpWord/Style/Paragraph.php | 4 +-- src/PhpWord/TemplateProcessor.php | 4 +-- .../Writer/RTF/Element/AbstractElement.php | 4 +-- .../Word2007/Element/AbstractElement.php | 4 +-- .../{StringTest.php => CommonStringTest.php} | 28 +++++++++---------- 14 files changed, 40 insertions(+), 40 deletions(-) rename src/PhpWord/Shared/{String.php => CommonString.php} (99%) rename tests/PhpWord/Shared/{StringTest.php => CommonStringTest.php} (56%) diff --git a/src/PhpWord/Element/Bookmark.php b/src/PhpWord/Element/Bookmark.php index d5b8ff6fba..2353d01a73 100644 --- a/src/PhpWord/Element/Bookmark.php +++ b/src/PhpWord/Element/Bookmark.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Style; /** @@ -47,7 +47,7 @@ class Bookmark extends AbstractElement public function __construct($name) { - $this->name = String::toUTF8($name); + $this->name = CommonString::toUTF8($name); return $this; } diff --git a/src/PhpWord/Element/CheckBox.php b/src/PhpWord/Element/CheckBox.php index d3b2a3c6f4..4586d0dea4 100644 --- a/src/PhpWord/Element/CheckBox.php +++ b/src/PhpWord/Element/CheckBox.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; /** * Check box element @@ -56,7 +56,7 @@ public function __construct($name = null, $text = null, $fontStyle = null, $para */ public function setName($name) { - $this->name = String::toUTF8($name); + $this->name = CommonString::toUTF8($name); return $this; } diff --git a/src/PhpWord/Element/Link.php b/src/PhpWord/Element/Link.php index 0359f41516..df1130845c 100644 --- a/src/PhpWord/Element/Link.php +++ b/src/PhpWord/Element/Link.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -78,8 +78,8 @@ class Link extends AbstractElement */ public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false) { - $this->source = String::toUTF8($source); - $this->text = is_null($text) ? $this->source : String::toUTF8($text); + $this->source = CommonString::toUTF8($source); + $this->text = is_null($text) ? $this->source : CommonString::toUTF8($text); $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->internal = $internal; diff --git a/src/PhpWord/Element/ListItem.php b/src/PhpWord/Element/ListItem.php index 4cb8d33952..c1f8546907 100644 --- a/src/PhpWord/Element/ListItem.php +++ b/src/PhpWord/Element/ListItem.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; /** @@ -57,7 +57,7 @@ class ListItem extends AbstractElement */ public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null) { - $this->textObject = new Text(String::toUTF8($text), $fontStyle, $paragraphStyle); + $this->textObject = new Text(CommonString::toUTF8($text), $fontStyle, $paragraphStyle); $this->depth = $depth; // Version >= 0.10.0 will pass numbering style name. Older version will use old method diff --git a/src/PhpWord/Element/PreserveText.php b/src/PhpWord/Element/PreserveText.php index 44aef3b40e..846566c24e 100644 --- a/src/PhpWord/Element/PreserveText.php +++ b/src/PhpWord/Element/PreserveText.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -61,7 +61,7 @@ public function __construct($text = null, $fontStyle = null, $paragraphStyle = n $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); - $this->text = String::toUTF8($text); + $this->text = CommonString::toUTF8($text); $matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if (isset($matches[0])) { $this->text = $matches; diff --git a/src/PhpWord/Element/Text.php b/src/PhpWord/Element/Text.php index 52fccb3f28..339390772e 100644 --- a/src/PhpWord/Element/Text.php +++ b/src/PhpWord/Element/Text.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -136,7 +136,7 @@ public function getParagraphStyle() */ public function setText($text) { - $this->text = String::toUTF8($text); + $this->text = CommonString::toUTF8($text); return $this; } diff --git a/src/PhpWord/Element/Title.php b/src/PhpWord/Element/Title.php index cf1d49c81a..5739a8d544 100644 --- a/src/PhpWord/Element/Title.php +++ b/src/PhpWord/Element/Title.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Style; /** @@ -61,7 +61,7 @@ class Title extends AbstractElement */ public function __construct($text, $depth = 1) { - $this->text = String::toUTF8($text); + $this->text = CommonString::toUTF8($text); $this->depth = $depth; if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) { $this->style = "Heading{$this->depth}"; diff --git a/src/PhpWord/Shared/String.php b/src/PhpWord/Shared/CommonString.php similarity index 99% rename from src/PhpWord/Shared/String.php rename to src/PhpWord/Shared/CommonString.php index be04fd0ec7..85e22a7c91 100644 --- a/src/PhpWord/Shared/String.php +++ b/src/PhpWord/Shared/CommonString.php @@ -20,7 +20,7 @@ /** * Common string functions */ -class String +class CommonString { /** * Control characters array diff --git a/src/PhpWord/Style/AbstractStyle.php b/src/PhpWord/Style/AbstractStyle.php index 482712e39b..600fd90313 100644 --- a/src/PhpWord/Style/AbstractStyle.php +++ b/src/PhpWord/Style/AbstractStyle.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Style; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; /** * Abstract style class @@ -161,7 +161,7 @@ public function setStyleValue($key, $value) if (isset($this->aliases[$key])) { $key = $this->aliases[$key]; } - $method = 'set' . String::removeUnderscorePrefix($key); + $method = 'set' . CommonString::removeUnderscorePrefix($key); if (method_exists($this, $method)) { $this->$method($value); } diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index a98ca258cc..8e840fc6ec 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -18,7 +18,7 @@ namespace PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Exception\InvalidStyleException; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\SimpleType\Jc; /** @@ -167,7 +167,7 @@ class Paragraph extends Border */ public function setStyleValue($key, $value) { - $key = String::removeUnderscorePrefix($key); + $key = CommonString::removeUnderscorePrefix($key); if ('indent' == $key || 'hanging' == $key) { $value = $value * 720; } elseif ('spacing' == $key) { diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index ce92bacfbe..6da80a2267 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -20,7 +20,7 @@ use PhpOffice\PhpWord\Exception\CopyFileException; use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Shared\ZipArchive; class TemplateProcessor @@ -403,7 +403,7 @@ protected function setValueForPart($documentPartXML, $search, $replace, $limit) $search = '${' . $search . '}'; } - if (!String::isUTF8($replace)) { + if (!CommonString::isUTF8($replace)) { $replace = utf8_encode($replace); } diff --git a/src/PhpWord/Writer/RTF/Element/AbstractElement.php b/src/PhpWord/Writer/RTF/Element/AbstractElement.php index 73da5cbddb..9c8eabe5eb 100644 --- a/src/PhpWord/Writer/RTF/Element/AbstractElement.php +++ b/src/PhpWord/Writer/RTF/Element/AbstractElement.php @@ -17,7 +17,7 @@ namespace PhpOffice\PhpWord\Writer\RTF\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; @@ -112,7 +112,7 @@ protected function writeOpening() */ protected function writeText($text) { - return String::toUnicode($text); + return CommonString::toUnicode($text); } /** diff --git a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php index 3b6432ed6a..511653f90b 100644 --- a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php +++ b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php @@ -18,7 +18,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element; use PhpOffice\PhpWord\Element\AbstractElement as Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\Shared\CommonString; use PhpOffice\PhpWord\Shared\XMLWriter; /** @@ -167,6 +167,6 @@ private function writeTextStyle($styleType) */ protected function getText($text) { - return String::controlCharacterPHP2OOXML($text); + return CommonString::controlCharacterPHP2OOXML($text); } } diff --git a/tests/PhpWord/Shared/StringTest.php b/tests/PhpWord/Shared/CommonStringTest.php similarity index 56% rename from tests/PhpWord/Shared/StringTest.php rename to tests/PhpWord/Shared/CommonStringTest.php index c358833d69..68e080715c 100644 --- a/tests/PhpWord/Shared/StringTest.php +++ b/tests/PhpWord/Shared/CommonStringTest.php @@ -18,21 +18,21 @@ namespace PhpOffice\PhpWord\Shared; /** - * Test class for PhpOffice\PhpWord\Shared\String + * Test class for PhpOffice\PhpWord\Shared\CommonString * - * @coversDefaultClass \PhpOffice\PhpWord\Shared\String + * @coversDefaultClass \PhpOffice\PhpWord\Shared\CommonString * @runTestsInSeparateProcesses */ -class StringTest extends \PHPUnit_Framework_TestCase +class CommonStringTest extends \PHPUnit_Framework_TestCase { /** * Is UTF8 */ public function testIsUTF8() { - $this->assertTrue(String::isUTF8('')); - $this->assertTrue(String::isUTF8('éééé')); - $this->assertFalse(String::isUTF8(utf8_decode('éééé'))); + $this->assertTrue(CommonString::isUTF8('')); + $this->assertTrue(CommonString::isUTF8('éééé')); + $this->assertFalse(CommonString::isUTF8(utf8_decode('éééé'))); } /** @@ -40,8 +40,8 @@ public function testIsUTF8() */ public function testControlCharacterOOXML2PHP() { - $this->assertEquals('', String::controlCharacterOOXML2PHP('')); - $this->assertEquals(chr(0x08), String::controlCharacterOOXML2PHP('_x0008_')); + $this->assertEquals('', CommonString::controlCharacterOOXML2PHP('')); + $this->assertEquals(chr(0x08), CommonString::controlCharacterOOXML2PHP('_x0008_')); } /** @@ -49,8 +49,8 @@ public function testControlCharacterOOXML2PHP() */ public function testControlCharacterPHP2OOXML() { - $this->assertEquals('', String::controlCharacterPHP2OOXML('')); - $this->assertEquals('_x0008_', String::controlCharacterPHP2OOXML(chr(0x08))); + $this->assertEquals('', CommonString::controlCharacterPHP2OOXML('')); + $this->assertEquals('_x0008_', CommonString::controlCharacterPHP2OOXML(chr(0x08))); } /** @@ -58,9 +58,9 @@ public function testControlCharacterPHP2OOXML() */ public function testToUnicode() { - $this->assertEquals('a', String::toUnicode('a')); - $this->assertEquals('\uc0{\u8364}', String::toUnicode('€')); - $this->assertEquals('\uc0{\u233}', String::toUnicode('é')); + $this->assertEquals('a', CommonString::toUnicode('a')); + $this->assertEquals('\uc0{\u8364}', CommonString::toUnicode('€')); + $this->assertEquals('\uc0{\u233}', CommonString::toUnicode('é')); } /** @@ -68,6 +68,6 @@ public function testToUnicode() */ public function testRemoveUnderscorePrefix() { - $this->assertEquals('item', String::removeUnderscorePrefix('_item')); + $this->assertEquals('item', CommonString::removeUnderscorePrefix('_item')); } }