diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e39ed3f..f9679faf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -v0.14.0 (?? ???? 2017) +v0.14.0 (?? Dec 2017) ---------------------- This release fixes several bugs and adds some new features. This is the last version to support PHP 5.3 @@ -18,13 +18,15 @@ This is the last version to support PHP 5.3 - Support for Comments - @troosan #1067 - Support for paragraph textAlignment - @troosan #1165 - Add support for HTML underline tag in addHtml - @zNightFalLz #1186 -- Allow to change cell width unit - guillaume-ro-fr #986 +- Allow to change cell width unit - @guillaume-ro-fr #986 - Allow to change the line height rule @troosan +- Implement PageBreak for odt writer @cookiekiller #863 #824 +- Allow to force an update of all fields on opening a document - @troosan #951 ### Fixed - Loosen dependency to Zend - Images are not being printed when generating PDF - @hubertinio #1074 #431 -- Fixed some PHP 7 warnings - @ likeuntomurphy #927 +- Fixed some PHP 7 warnings - @likeuntomurphy #927 - Fixed Word 97 reader - @alsofronie @Benpxpx @mario-rivera #912 #920 #892 - Fixed image loading over https - @troosan #988 - Impossibility to set different even and odd page headers - @troosan #981 @@ -39,6 +41,9 @@ This is the last version to support PHP 5.3 - Fix incorrect image size between windows and mac - @bskrtich #874 - Fix adding HTML table to document - @mogilvie @arivanbastos #324 +###Deprecated +- PhpWord->getProtection(), get it from the settings instead PhpWord->getSettings()->getDocumentProtection(); + v0.13.0 (31 July 2016) ------------------- This release brings several improvements in `TemplateProcessor`, automatic output escaping feature for OOXML, ODF, HTML, and RTF (turned off, by default). diff --git a/README.md b/README.md index f712c6c6..85808888 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,18 @@ PHPWord requires the following: ## Installation PHPWord is installed via [Composer](https://getcomposer.org/). -You just need to [add dependency](https://getcomposer.org/doc/04-schema.md#package-links>) on PHPWord into your package. +To [add a dependency](https://getcomposer.org/doc/04-schema.md#package-links>) to PHPWord in your project, either -Example: +Run the following to use the latest stable version +```sh + composer require phpoffice/phpword +``` +or if you want the latest master version +```sh + composer require phpoffice/phpword:dev-master +``` +You can of course also manually edit your composer.json file ```json { "require": { diff --git a/composer.json b/composer.json index ee4f9bd5..70b60b46 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "php": ">=5.3.3", "ext-xml": "*", "zendframework/zend-escaper": "^2.2", - "zendframework/zend-stdlib": "^2.2", + "zendframework/zend-stdlib": "^2.2 || ^3.0", "phpoffice/common": "^0.2" }, "require-dev": { diff --git a/docs/ISSUE_TEMPLATE.md b/docs/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..58981f8e --- /dev/null +++ b/docs/ISSUE_TEMPLATE.md @@ -0,0 +1,28 @@ +Issue tracker is **ONLY** used for reporting bugs. NO NEW FEATURE ACCEPTED! Use [stackoverflow](https://stackoverflow.com/questions/tagged/phpword) for supporting issues. + +# Expected Behavior + +Please describe the behavior you are expecting. + +# Current Behavior + +What is the current behavior? + +# Failure Information + +Please help provide information about the failure. + +## How to Reproduce + +Please provide a code sample that reproduces the issue. + +```php +$phpWord = new \PhpOffice\PhpWord\PhpWord(); +$section = $phpWord->addSection(); +$section->... +``` + +## Context + +* PHP version: +* PHPWord version: 0.14 diff --git a/docs/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..ad9788c4 --- /dev/null +++ b/docs/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +# Description + +Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. + +Fixes # (issue) + +# Checklist: + +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have run phpunit, phpcs, php-cs-fixer, phpmd +- [ ] The new code is covered by unit tests +- [ ] I have update the documentation to describe the changes diff --git a/docs/elements.rst b/docs/elements.rst index a2e41566..bf3eb5ac 100644 --- a/docs/elements.rst +++ b/docs/elements.rst @@ -297,7 +297,7 @@ Your TOC can only be generated if you have add at least one title (See "Titles") Options for ``$tocStyle``: -- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in PHPWord\\Style\\TOC. +- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in ``\PhpOffice\PhpWord\Style\TOC``. - ``tabPos``. The position of the tab where the page number appears in twips. - ``indent``. The indent factor of the titles in twips. diff --git a/docs/general.rst b/docs/general.rst index f6c8df1c..ae090f2d 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -282,3 +282,12 @@ The document (or parts of it) can be password protected. $documentProtection = $phpWord->getSettings()->getDocumentProtection(); $documentProtection->setEditing(DocProtect::READ_ONLY); $documentProtection->setPassword('myPassword'); + +Automatically Recalculate Fields on Open +---------------------------------------- + +To force an update of the fields present in the document, set updateFields to true + +.. code-block:: php + + $phpWord->getSettings()->setUpdateFields(true); diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..5ae6d0f2 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +includes: + - vendor/phpstan/phpstan/conf/config.level1.neon +parameters: + memory-limit: 200000 + autoload_directories: + - tests + autoload_files: + - tests/bootstrap.php + excludes_analyse: + - */pclzip.lib.php + - src/PhpWord/Shared/OLERead.php + - src/PhpWord/Reader/MsDoc.php + - src/PhpWord/Writer/PDF/MPDF.php \ No newline at end of file diff --git a/run_tests.sh b/run_tests.sh index 6b81d69c..a5d94259 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,14 +1,20 @@ #!/bin/bash +echo "Running composer update" +composer update ## PHP_CodeSniffer +echo "Running CodeSniffer" ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip ## PHP-CS-Fixer +echo "Running CS Fixer" ./vendor/bin/php-cs-fixer fix --diff --verbose --dry-run ## PHP Mess Detector +echo "Running Mess Detector" ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php ## PHPUnit -./vendor/bin/phpunit -c ./ --no-coverage +echo "Running PHPUnit" +./vendor/bin/phpunit -c ./ diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php index 306595eb..f99b73ea 100644 --- a/samples/Sample_17_TitleTOC.php +++ b/samples/Sample_17_TitleTOC.php @@ -4,6 +4,7 @@ include_once 'Sample_Header.php'; // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +$phpWord->getSettings()->setUpdateFields(true); // New section $section = $phpWord->addSection(); diff --git a/src/PhpWord/Element/Endnote.php b/src/PhpWord/Element/Endnote.php index 6565c039..b6e94fba 100644 --- a/src/PhpWord/Element/Endnote.php +++ b/src/PhpWord/Element/Endnote.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Style\Paragraph; - /** * Endnote element * @@ -38,6 +36,6 @@ class Endnote extends Footnote */ public function __construct($paragraphStyle = null) { - $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); + parent::__construct($paragraphStyle); } } diff --git a/src/PhpWord/Element/Field.php b/src/PhpWord/Element/Field.php index d51cba8d..6ea63c6b 100644 --- a/src/PhpWord/Element/Field.php +++ b/src/PhpWord/Element/Field.php @@ -74,7 +74,7 @@ class Field extends AbstractElement /** * Field text * - * @var TextRun | string + * @var TextRun|string */ protected $text; @@ -98,7 +98,7 @@ class Field extends AbstractElement * @param string $type * @param array $properties * @param array $options - * @param TextRun | string $text + * @param TextRun|string|null $text */ public function __construct($type = null, $properties = array(), $options = array(), $text = null) { @@ -209,7 +209,7 @@ class Field extends AbstractElement * @param string|TextRun $text * * @throws \InvalidArgumentException - * @return string|TextRun + * @return null|string|TextRun */ public function setText($text) { diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php index a5bd7283..f1f6bab5 100644 --- a/src/PhpWord/Element/Image.php +++ b/src/PhpWord/Element/Image.php @@ -137,7 +137,7 @@ class Image extends AbstractElement $this->setIsWatermark($watermark); $this->style = $this->setNewStyle(new ImageStyle(), $style, true); - $this->checkImage($source); + $this->checkImage(); } /** diff --git a/src/PhpWord/Element/ListItemRun.php b/src/PhpWord/Element/ListItemRun.php index 5286f662..e311dc24 100644 --- a/src/PhpWord/Element/ListItemRun.php +++ b/src/PhpWord/Element/ListItemRun.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; -use PhpOffice\PhpWord\Style\Paragraph; /** * List item element @@ -61,7 +60,7 @@ class ListItemRun extends TextRun } else { $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true); } - $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); + parent::__construct($paragraphStyle); } /** diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index 8238277e..06acf1f9 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -142,7 +142,7 @@ class Section extends AbstractContainer /** * Get the footnote properties * - * @return \PhpOffice\PhpWord\Element\FooterProperties + * @return FootnoteProperties */ public function getFootnotePropoperties() { diff --git a/src/PhpWord/Element/TrackChange.php b/src/PhpWord/Element/TrackChange.php index d900b053..9ed623f9 100644 --- a/src/PhpWord/Element/TrackChange.php +++ b/src/PhpWord/Element/TrackChange.php @@ -37,7 +37,7 @@ class TrackChange extends AbstractContainer /** * Date * - * @var DateTime + * @var \DateTime */ private $date; diff --git a/src/PhpWord/Metadata/DocInfo.php b/src/PhpWord/Metadata/DocInfo.php index e5dee659..09714f9e 100644 --- a/src/PhpWord/Metadata/DocInfo.php +++ b/src/PhpWord/Metadata/DocInfo.php @@ -410,7 +410,7 @@ class DocInfo * Get a Custom Property Value * * @param string $propertyName - * @return string + * @return mixed */ public function getCustomPropertyValue($propertyName) { diff --git a/src/PhpWord/Metadata/Settings.php b/src/PhpWord/Metadata/Settings.php index 33f72cca..728cc823 100644 --- a/src/PhpWord/Metadata/Settings.php +++ b/src/PhpWord/Metadata/Settings.php @@ -116,6 +116,13 @@ class Settings */ private $themeFontLang; + /** + * Automatically Recalculate Fields on Open + * + * @var bool + */ + private $updateFields = false; + /** * Radix Point for Field Code Evaluation * @@ -345,6 +352,22 @@ class Settings $this->themeFontLang = $themeFontLang; } + /** + * @return bool + */ + public function hasUpdateFields() + { + return $this->updateFields; + } + + /** + * @param bool $updateFields + */ + public function setUpdateFields($updateFields) + { + $this->updateFields = $updateFields === null ? false : $updateFields; + } + /** * Returns the Radix Point for Field Code Evaluation * diff --git a/src/PhpWord/Reader/Word2007/Settings.php b/src/PhpWord/Reader/Word2007/Settings.php index 2580209e..c116425e 100644 --- a/src/PhpWord/Reader/Word2007/Settings.php +++ b/src/PhpWord/Reader/Word2007/Settings.php @@ -150,11 +150,11 @@ class Settings extends AbstractPart protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $node) { $revisionView = new TrackChangesView(); - $revisionView->setMarkup($xmlReader->getAttribute('w:markup', $node)); + $revisionView->setMarkup(filter_var($xmlReader->getAttribute('w:markup', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setComments($xmlReader->getAttribute('w:comments', $node)); $revisionView->setInsDel($xmlReader->getAttribute('w:insDel', $node)); - $revisionView->setFormatting($xmlReader->getAttribute('w:formatting', $node)); - $revisionView->setInkAnnotations($xmlReader->getAttribute('w:inkAnnotations', $node)); + $revisionView->setFormatting(filter_var($xmlReader->getAttribute('w:formatting', $node), FILTER_VALIDATE_BOOLEAN)); + $revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN)); $phpWord->getSettings()->setRevisionView($revisionView); } } diff --git a/src/PhpWord/Shared/AbstractEnum.php b/src/PhpWord/Shared/AbstractEnum.php index 58601a14..442d8251 100644 --- a/src/PhpWord/Shared/AbstractEnum.php +++ b/src/PhpWord/Shared/AbstractEnum.php @@ -48,7 +48,7 @@ abstract class AbstractEnum /** * Returns true the value is valid for this enum * - * @param strign $value + * @param string $value * @return bool true if value is valid */ public static function isValid($value) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 027d5798..3f94e2ba 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -182,7 +182,7 @@ class Html { if ('li' != $node->nodeName) { $cNodes = $node->childNodes; - if (count($cNodes) > 0) { + if (!empty($cNodes)) { foreach ($cNodes as $cNode) { if ($element instanceof AbstractContainer || $element instanceof Table || $element instanceof Row) { self::parseNode($cNode, $element, $styles, $data); @@ -389,7 +389,7 @@ class Html private static function parseListItem($node, $element, &$styles, $data) { $cNodes = $node->childNodes; - if (count($cNodes) > 0) { + if (!empty($cNodes)) { $text = ''; foreach ($cNodes as $cNode) { if ($cNode->nodeName == '#text') { diff --git a/src/PhpWord/Shared/PCLZip/pclzip.lib.php b/src/PhpWord/Shared/PCLZip/pclzip.lib.php index 0a69f687..5620c754 100644 --- a/src/PhpWord/Shared/PCLZip/pclzip.lib.php +++ b/src/PhpWord/Shared/PCLZip/pclzip.lib.php @@ -3790,7 +3790,7 @@ class PclZip } // ----- Write gz file format header - $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); + $v_binary_data = pack('va1a1Va1a1', 0x8b1f, chr($p_entry['compression']), chr(0x00), time(), chr(0x00), chr(3)); @fwrite($v_dest_file, $v_binary_data, 10); // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks @@ -4383,7 +4383,7 @@ class PclZip //$v_bytes = ($v_bytes << 8) | Ord($v_byte); // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. - $v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); + $v_bytes = (($v_bytes & 0xFFFFFF) << 8) | ord($v_byte); // ----- Compare the bytes if ($v_bytes == 0x504b0506) { diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php index d73f6c33..bb42a92a 100644 --- a/src/PhpWord/Shared/ZipArchive.php +++ b/src/PhpWord/Shared/ZipArchive.php @@ -140,7 +140,8 @@ class ZipArchive } else { $zip = new \PclZip($this->filename); $this->tempDir = Settings::getTempDir(); - $this->numFiles = count($zip->listContent()); + $zipContent = $zip->listContent(); + $this->numFiles = is_array($zipContent) ? count($zipContent) : 0; } $this->zip = $zip; @@ -351,7 +352,7 @@ class ZipArchive * Returns the name of an entry using its index (emulate \ZipArchive) * * @param int $index - * @return string + * @return string|bool * @since 0.10.0 */ public function pclzipGetNameIndex($index) diff --git a/src/PhpWord/Writer/ODText/Element/Link.php b/src/PhpWord/Writer/ODText/Element/Link.php index c996ab59..34d72c1a 100644 --- a/src/PhpWord/Writer/ODText/Element/Link.php +++ b/src/PhpWord/Writer/ODText/Element/Link.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element; -use PhpOffice\PhpWord\Settings; - /** * Text element writer * @@ -44,11 +42,7 @@ class Link extends AbstractElement $xmlWriter->startElement('text:a'); $xmlWriter->writeAttribute('xlink:type', 'simple'); $xmlWriter->writeAttribute('xlink:href', $element->getSource()); - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); $xmlWriter->endElement(); // text:a if (!$this->withoutP) { diff --git a/src/PhpWord/Writer/ODText/Element/PageBreak.php b/src/PhpWord/Writer/ODText/Element/PageBreak.php new file mode 100644 index 00000000..6eee6cfc --- /dev/null +++ b/src/PhpWord/Writer/ODText/Element/PageBreak.php @@ -0,0 +1,36 @@ +getXmlWriter(); + + $xmlWriter->startElement('text:p'); + $xmlWriter->writeAttribute('text:style-name', 'P1'); + $xmlWriter->endElement(); + } +} diff --git a/src/PhpWord/Writer/ODText/Element/Text.php b/src/PhpWord/Writer/ODText/Element/Text.php index 3b06217d..1fc0b800 100644 --- a/src/PhpWord/Writer/ODText/Element/Text.php +++ b/src/PhpWord/Writer/ODText/Element/Text.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\Settings; /** * Text element writer @@ -58,11 +57,7 @@ class Text extends AbstractElement } elseif (is_string($paragraphStyle)) { $xmlWriter->writeAttribute('text:style-name', $paragraphStyle); } - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); } else { if (empty($paragraphStyle)) { $xmlWriter->writeAttribute('text:style-name', 'Standard'); @@ -74,11 +69,7 @@ class Text extends AbstractElement if (is_string($fontStyle)) { $xmlWriter->writeAttribute('text:style-name', $fontStyle); } - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); $xmlWriter->endElement(); } if (!$this->withoutP) { diff --git a/src/PhpWord/Writer/ODText/Element/Title.php b/src/PhpWord/Writer/ODText/Element/Title.php index bf9bf9d6..769d293f 100644 --- a/src/PhpWord/Writer/ODText/Element/Title.php +++ b/src/PhpWord/Writer/ODText/Element/Title.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element; -use PhpOffice\PhpWord\Settings; - /** * Title element writer * @@ -39,11 +37,7 @@ class Title extends AbstractElement $xmlWriter->startElement('text:h'); $xmlWriter->writeAttribute('text:outline-level', $element->getDepth()); - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($element->getText()); - } else { - $xmlWriter->writeRaw($element->getText()); - } + $this->writeText($element->getText()); $xmlWriter->endElement(); // text:h } } diff --git a/src/PhpWord/Writer/ODText/Part/Meta.php b/src/PhpWord/Writer/ODText/Part/Meta.php index 72d03ae6..f592c5f0 100644 --- a/src/PhpWord/Writer/ODText/Part/Meta.php +++ b/src/PhpWord/Writer/ODText/Part/Meta.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\Common\XMLWriter; -use PhpOffice\PhpWord\Settings; /** * ODText meta part writer: meta.xml @@ -100,11 +99,7 @@ class Meta extends AbstractPart // if ($type !== null) { // $xmlWriter->writeAttribute('meta:value-type', $type); // } - if (Settings::isOutputEscapingEnabled()) { - $xmlWriter->text($value); - } else { - $xmlWriter->writeRaw($value); - } + $this->writeText($value); $xmlWriter->endElement(); // meta:user-defined } } diff --git a/src/PhpWord/Writer/PDF/TCPDF.php b/src/PhpWord/Writer/PDF/TCPDF.php index 3b82511a..85e3614c 100644 --- a/src/PhpWord/Writer/PDF/TCPDF.php +++ b/src/PhpWord/Writer/PDF/TCPDF.php @@ -40,7 +40,6 @@ class TCPDF extends AbstractRenderer implements WriterInterface * Save PhpWord to file. * * @param string $filename Name of the file to save as - * @return vois */ public function save($filename = null) { @@ -55,21 +54,21 @@ class TCPDF extends AbstractRenderer implements WriterInterface $pdf->setFontSubsetting(false); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); - $pdf->addPage(); - $pdf->setFont($this->getFont()); + $pdf->AddPage(); + $pdf->SetFont($this->getFont()); $pdf->writeHTML($this->getContent()); // Write document properties $phpWord = $this->getPhpWord(); $docProps = $phpWord->getDocInfo(); - $pdf->setTitle($docProps->getTitle()); - $pdf->setAuthor($docProps->getCreator()); - $pdf->setSubject($docProps->getSubject()); - $pdf->setKeywords($docProps->getKeywords()); - $pdf->setCreator($docProps->getCreator()); + $pdf->SetTitle($docProps->getTitle()); + $pdf->SetAuthor($docProps->getCreator()); + $pdf->SetSubject($docProps->getSubject()); + $pdf->SetKeywords($docProps->getKeywords()); + $pdf->SetCreator($docProps->getCreator()); // Write to file - fwrite($fileHandle, $pdf->output($filename, 'S')); + fwrite($fileHandle, $pdf->Output($filename, 'S')); parent::restoreStateAfterSave($fileHandle); } diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index e63d767f..0ba9f602 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -48,7 +48,7 @@ class Border extends AbstractStyle $content = ''; $sides = array('top', 'left', 'right', 'bottom'); - $sizeCount = count($this->sizes) - 1; + $sizeCount = count($this->sizes); // Page border measure // 8 = from text, infront off; 32 = from edge, infront on; 40 = from edge, infront off diff --git a/src/PhpWord/Writer/Word2007/Element/SDT.php b/src/PhpWord/Writer/Word2007/Element/SDT.php index 8899a1d8..6a202564 100644 --- a/src/PhpWord/Writer/Word2007/Element/SDT.php +++ b/src/PhpWord/Writer/Word2007/Element/SDT.php @@ -101,7 +101,7 @@ class SDT extends Text */ private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element) { - $this->writecomboBox($xmlWriter, $element); + $this->writeComboBox($xmlWriter, $element); } /** diff --git a/src/PhpWord/Writer/Word2007/Part/Settings.php b/src/PhpWord/Writer/Word2007/Part/Settings.php index 565aab2c..2e00330a 100644 --- a/src/PhpWord/Writer/Word2007/Part/Settings.php +++ b/src/PhpWord/Writer/Word2007/Part/Settings.php @@ -77,7 +77,7 @@ class Settings extends AbstractPart { if ($settingValue == '') { $xmlWriter->writeElement($settingKey); - } else { + } elseif (is_array($settingValue) && !empty($settingValue)) { $xmlWriter->startElement($settingKey); /** @var array $settingValue Type hint */ @@ -148,13 +148,14 @@ class Settings extends AbstractPart $this->setOnOffValue('w:doNotTrackMoves', $documentSettings->hasDoNotTrackMoves()); $this->setOnOffValue('w:doNotTrackFormatting', $documentSettings->hasDoNotTrackFormatting()); $this->setOnOffValue('w:evenAndOddHeaders', $documentSettings->hasEvenAndOddHeaders()); + $this->setOnOffValue('w:updateFields', $documentSettings->hasUpdateFields()); $this->setThemeFontLang($documentSettings->getThemeFontLang()); $this->setRevisionView($documentSettings->getRevisionView()); $this->setDocumentProtection($documentSettings->getDocumentProtection()); $this->setProofState($documentSettings->getProofState()); $this->setZoom($documentSettings->getZoom()); - $this->getCompatibility(); + $this->setCompatibility(); } /** @@ -236,6 +237,7 @@ class Settings extends AbstractPart private function setRevisionView(TrackChangesView $trackChangesView = null) { if ($trackChangesView != null) { + $revisionView = array(); $revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true' : 'false'; $revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true' : 'false'; $revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true' : 'false'; @@ -279,7 +281,7 @@ class Settings extends AbstractPart /** * Get compatibility setting. */ - private function getCompatibility() + private function setCompatibility() { $compatibility = $this->getParentWriter()->getPhpWord()->getCompatibility(); if ($compatibility->getOoxmlVersion() !== null) { diff --git a/src/PhpWord/Writer/Word2007/Style/Font.php b/src/PhpWord/Writer/Word2007/Style/Font.php index 3fbff63d..9c2714dc 100644 --- a/src/PhpWord/Writer/Word2007/Style/Font.php +++ b/src/PhpWord/Writer/Word2007/Style/Font.php @@ -104,6 +104,7 @@ class Font extends AbstractStyle // Bold, italic $xmlWriter->writeElementIf($style->isBold(), 'w:b'); + $xmlWriter->writeElementIf($style->isBold(), 'w:bCs'); $xmlWriter->writeElementIf($style->isItalic(), 'w:i'); $xmlWriter->writeElementIf($style->isItalic(), 'w:iCs'); diff --git a/tests/PhpWord/Metadata/SettingsTest.php b/tests/PhpWord/Metadata/SettingsTest.php index 9830fd28..50863561 100644 --- a/tests/PhpWord/Metadata/SettingsTest.php +++ b/tests/PhpWord/Metadata/SettingsTest.php @@ -162,4 +162,14 @@ class SettingsTest extends \PHPUnit\Framework\TestCase $oSettings->setZoom(Zoom::FULL_PAGE); $this->assertEquals('fullPage', $oSettings->getZoom()); } + + /** + * Test Update Fields on update + */ + public function testUpdateFields() + { + $oSettings = new Settings(); + $oSettings->setUpdateFields(true); + $this->assertTrue($oSettings->hasUpdateFields()); + } } diff --git a/tests/PhpWord/Shared/ConverterTest.php b/tests/PhpWord/Shared/ConverterTest.php index c7e0483d..752b9a8a 100644 --- a/tests/PhpWord/Shared/ConverterTest.php +++ b/tests/PhpWord/Shared/ConverterTest.php @@ -73,7 +73,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); - $result = Converter::pixelToEMU($value); + $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); $result = Converter::pointToTwip($value); @@ -82,7 +82,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase $result = Converter::pointToPixel($value); $this->assertEquals($value / 72 * 96, $result); - $result = Converter::pointToEMU($value); + $result = Converter::pointToEmu($value); $this->assertEquals(round($value / 72 * 96 * 9525), $result); $result = Converter::emuToPixel($value); @@ -111,7 +111,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase $values[] = array('0F9D', false); // 4 characters // Conduct test foreach ($values as $value) { - $result = Converter::htmlToRGB($value[0]); + $result = Converter::htmlToRgb($value[0]); $this->assertEquals($value[1], $result); } } diff --git a/tests/PhpWord/Style/NumberingTest.php b/tests/PhpWord/Style/NumberingTest.php index 0103c503..4ec12366 100644 --- a/tests/PhpWord/Style/NumberingTest.php +++ b/tests/PhpWord/Style/NumberingTest.php @@ -29,21 +29,21 @@ class NumberingTest extends \PHPUnit\Framework\TestCase */ public function testGetSetProperties() { - $this->object = new Numbering(); - $this->properties = array( + $object = new Numbering(); + $properties = array( 'numId' => array(null, 1), 'type' => array(null, 'singleLevel'), ); - foreach ($this->properties as $property => $value) { + foreach ($properties as $property => $value) { list($default, $expected) = $value; $get = "get{$property}"; $set = "set{$property}"; - $this->assertEquals($default, $this->object->$get()); // Default value + $this->assertEquals($default, $object->$get()); // Default value - $this->object->$set($expected); + $object->$set($expected); - $this->assertEquals($expected, $this->object->$get()); // New value + $this->assertEquals($expected, $object->$get()); // New value } } @@ -52,8 +52,8 @@ class NumberingTest extends \PHPUnit\Framework\TestCase */ public function testGetLevels() { - $this->object = new Numbering(); + $object = new Numbering(); - $this->assertEmpty($this->object->getLevels()); + $this->assertEmpty($object->getLevels()); } } diff --git a/tests/PhpWord/Style/TableTest.php b/tests/PhpWord/Style/TableTest.php index ff813927..2d57b1b8 100644 --- a/tests/PhpWord/Style/TableTest.php +++ b/tests/PhpWord/Style/TableTest.php @@ -99,6 +99,7 @@ class TableTest extends \PHPUnit\Framework\TestCase $value = 'FF0000'; $object->setBorderColor($value); + $values = array(); foreach ($parts as $part) { $get = "getBorder{$part}Color"; $values[] = $value; @@ -121,6 +122,7 @@ class TableTest extends \PHPUnit\Framework\TestCase $value = 4; $object->setBorderSize($value); + $values = array(); foreach ($parts as $part) { $get = "getBorder{$part}Size"; $values[] = $value; @@ -143,6 +145,7 @@ class TableTest extends \PHPUnit\Framework\TestCase $value = 240; $object->setCellMargin($value); + $values = array(); foreach ($parts as $part) { $get = "getCellMargin{$part}"; $values[] = $value; diff --git a/tests/PhpWord/Writer/ODText/ElementTest.php b/tests/PhpWord/Writer/ODText/ElementTest.php index 253c8e11..f56114ea 100644 --- a/tests/PhpWord/Writer/ODText/ElementTest.php +++ b/tests/PhpWord/Writer/ODText/ElementTest.php @@ -18,6 +18,8 @@ namespace PhpOffice\PhpWord\Writer\ODText; use PhpOffice\Common\XMLWriter; +use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\ODText\Element subnamespace @@ -40,4 +42,21 @@ class ElementTest extends \PHPUnit\Framework\TestCase $this->assertEquals('', $xmlWriter->getData()); } } + + /** + * Test PageBreak + */ + public function testPageBreak() + { + $phpWord = new PhpWord(); + $section = $phpWord->addSection(); + $section->addText('test'); + $section->addPageBreak(); + + $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); + + $element = '/office:document-content/office:body/office:text/text:section/text:p[2]'; + $this->assertTrue($doc->elementExists($element, 'content.xml')); + $this->assertEquals('P1', $doc->getElementAttribute($element, 'text:style-name', 'content.xml')); + } } diff --git a/tests/PhpWord/Writer/RTF/StyleTest.php b/tests/PhpWord/Writer/RTF/StyleTest.php index b9dc7b45..42f76430 100644 --- a/tests/PhpWord/Writer/RTF/StyleTest.php +++ b/tests/PhpWord/Writer/RTF/StyleTest.php @@ -17,6 +17,8 @@ namespace PhpOffice\PhpWord\Writer\RTF; +use PhpOffice\PhpWord\Writer\RTF\Style\Border; + /** * Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace */ @@ -35,4 +37,22 @@ class StyleTest extends \PHPUnit\Framework\TestCase $this->assertEquals('', $object->write()); } } + + public function testBorderWithNonRegisteredColors() + { + $border = new Border(); + $border->setSizes(array(1, 2, 3, 4)); + $border->setColors(array('#FF0000', '#FF0000', '#FF0000', '#FF0000')); + $border->setSizes(array(20, 20, 20, 20)); + + $content = $border->write(); + + $expected = '\pgbrdropt32'; + $expected .= '\pgbrdrt\brdrs\brdrw20\brdrcf0\brsp480 '; + $expected .= '\pgbrdrl\brdrs\brdrw20\brdrcf0\brsp480 '; + $expected .= '\pgbrdrr\brdrs\brdrw20\brdrcf0\brsp480 '; + $expected .= '\pgbrdrb\brdrs\brdrw20\brdrcf0\brsp480 '; + + $this->assertEquals($expected, $content); + } }