From 1dc3dc6ce5ee3dca89fc0d9c99a6052b94a77b03 Mon Sep 17 00:00:00 2001 From: Erik Hazington <83652897+hazington@users.noreply.github.com> Date: Fri, 30 Dec 2022 21:32:48 +0100 Subject: [PATCH 01/10] Add background color support for textboxes --- src/PhpWord/Style/TextBox.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php index e43e6fa2..447c6c91 100644 --- a/src/PhpWord/Style/TextBox.php +++ b/src/PhpWord/Style/TextBox.php @@ -65,6 +65,33 @@ class TextBox extends Image * @var string */ private $borderColor; + + /** + * background color + * + * @var string + */ + private $bgColor; + + /** + * Set background color + * + * @param string $value + */ + public function setBgColor($value = null) + { + $this->bgColor = $value; + } + + /** + * Get background color + * + * @return string + */ + public function getBgColor() + { + return $this->bgColor; + } /** * Set margin top. From 25575c80ca1ec1a496eba09882a9cada56626190 Mon Sep 17 00:00:00 2001 From: Erik Hazington <83652897+hazington@users.noreply.github.com> Date: Fri, 30 Dec 2022 21:34:47 +0100 Subject: [PATCH 02/10] Add background color support for text boxes for Word writer --- src/PhpWord/Writer/Word2007/Element/TextBox.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php index d264f084..54db9285 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php @@ -50,6 +50,9 @@ class TextBox extends Image $xmlWriter->startElement('v:shape'); $xmlWriter->writeAttribute('type', '#_x0000_t0202'); + if ($style->getBgColor()) { + $xmlWriter->writeAttribute('fillcolor', $style->getBgColor()); + } $styleWriter->write(); $styleWriter->writeBorder(); From 143e01b29b3595eae2ce032deca313e49480c848 Mon Sep 17 00:00:00 2001 From: Erik Hazington <83652897+hazington@users.noreply.github.com> Date: Fri, 30 Dec 2022 21:46:44 +0100 Subject: [PATCH 03/10] Added period to the comments to match the cs-fixer configuration --- src/PhpWord/Style/TextBox.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php index 447c6c91..a43b76fe 100644 --- a/src/PhpWord/Style/TextBox.php +++ b/src/PhpWord/Style/TextBox.php @@ -67,14 +67,14 @@ class TextBox extends Image private $borderColor; /** - * background color + * background color. * * @var string */ private $bgColor; /** - * Set background color + * Set background color. * * @param string $value */ @@ -84,7 +84,7 @@ class TextBox extends Image } /** - * Get background color + * Get background color. * * @return string */ From 40d57706515da9821006163f3d3463484b2ee067 Mon Sep 17 00:00:00 2001 From: Erik Hazington <83652897+hazington@users.noreply.github.com> Date: Fri, 30 Dec 2022 21:50:28 +0100 Subject: [PATCH 04/10] Fixed cs-fixer issues. --- src/PhpWord/Style/TextBox.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php index a43b76fe..846c89b5 100644 --- a/src/PhpWord/Style/TextBox.php +++ b/src/PhpWord/Style/TextBox.php @@ -65,7 +65,7 @@ class TextBox extends Image * @var string */ private $borderColor; - + /** * background color. * @@ -78,7 +78,7 @@ class TextBox extends Image * * @param string $value */ - public function setBgColor($value = null) + public function setBgColor($value = null): void { $this->bgColor = $value; } From 1a80aacb4fb361e00b9ab89cea45245bffd0212a Mon Sep 17 00:00:00 2001 From: hazington Date: Tue, 3 Jan 2023 23:26:02 +0100 Subject: [PATCH 05/10] Added type hints and matching PHPDoc. Also added @return void. --- src/PhpWord/Style/TextBox.php | 87 ++++++++++--------- .../Writer/Word2007/Element/TextBox.php | 10 +-- src/PhpWord/Writer/Word2007/Style/TextBox.php | 2 + 3 files changed, 53 insertions(+), 46 deletions(-) diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php index 846c89b5..68b516b1 100644 --- a/src/PhpWord/Style/TextBox.php +++ b/src/PhpWord/Style/TextBox.php @@ -2,16 +2,13 @@ /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. - * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. - * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord - * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -27,58 +24,59 @@ class TextBox extends Image /** * margin top. * - * @var int + * @var null|int */ private $innerMarginTop; /** * margin left. * - * @var int + * @var null|int */ private $innerMarginLeft; /** * margin right. * - * @var int + * @var null|int */ private $innerMarginRight; /** * Cell margin bottom. * - * @var int + * @var null|int */ private $innerMarginBottom; /** * border size. * - * @var int + * @var null|int */ private $borderSize; /** * border color. * - * @var string + * @var null|string */ private $borderColor; /** * background color. * - * @var string + * @var null|string */ private $bgColor; /** * Set background color. * - * @param string $value + * @param null|string $value + * @return void */ - public function setBgColor($value = null): void + public function setBgColor(string $value = null): void { $this->bgColor = $value; } @@ -86,9 +84,9 @@ class TextBox extends Image /** * Get background color. * - * @return string + * @return null|string */ - public function getBgColor() + public function getBgColor(): ?string { return $this->bgColor; } @@ -96,9 +94,10 @@ class TextBox extends Image /** * Set margin top. * - * @param int $value + * @param null|int $value + * @return void */ - public function setInnerMarginTop($value = null): void + public function setInnerMarginTop(int $value = null): void { $this->innerMarginTop = $value; } @@ -106,9 +105,9 @@ class TextBox extends Image /** * Get margin top. * - * @return int + * @return null|int */ - public function getInnerMarginTop() + public function getInnerMarginTop(): ?int { return $this->innerMarginTop; } @@ -116,9 +115,10 @@ class TextBox extends Image /** * Set margin left. * - * @param int $value + * @param null|int $value + * @return void */ - public function setInnerMarginLeft($value = null): void + public function setInnerMarginLeft(int $value = null): void { $this->innerMarginLeft = $value; } @@ -126,9 +126,9 @@ class TextBox extends Image /** * Get margin left. * - * @return int + * @return null|int */ - public function getInnerMarginLeft() + public function getInnerMarginLeft(): ?int { return $this->innerMarginLeft; } @@ -136,9 +136,10 @@ class TextBox extends Image /** * Set margin right. * - * @param int $value + * @param null|int $value + * @return void */ - public function setInnerMarginRight($value = null): void + public function setInnerMarginRight(int $value = null): void { $this->innerMarginRight = $value; } @@ -146,9 +147,9 @@ class TextBox extends Image /** * Get margin right. * - * @return int + * @return null|int */ - public function getInnerMarginRight() + public function getInnerMarginRight(): ?int { return $this->innerMarginRight; } @@ -156,9 +157,10 @@ class TextBox extends Image /** * Set margin bottom. * - * @param int $value + * @param null|int $value + * @return void */ - public function setInnerMarginBottom($value = null): void + public function setInnerMarginBottom(int $value = null): void { $this->innerMarginBottom = $value; } @@ -166,9 +168,9 @@ class TextBox extends Image /** * Get margin bottom. * - * @return int + * @return null|int */ - public function getInnerMarginBottom() + public function getInnerMarginBottom(): ?int { return $this->innerMarginBottom; } @@ -176,9 +178,10 @@ class TextBox extends Image /** * Set TLRB cell margin. * - * @param int $value Margin in twips + * @param null|int $value Margin in twips + * @return void */ - public function setInnerMargin($value = null): void + public function setInnerMargin(int $value = null): void { $this->setInnerMarginTop($value); $this->setInnerMarginLeft($value); @@ -191,7 +194,7 @@ class TextBox extends Image * * @return int[] */ - public function getInnerMargin() + public function getInnerMargin(): array { return [$this->innerMarginLeft, $this->innerMarginTop, $this->innerMarginRight, $this->innerMarginBottom]; } @@ -201,7 +204,7 @@ class TextBox extends Image * * @return bool */ - public function hasInnerMargins() + public function hasInnerMargins(): bool { $hasInnerMargins = false; $margins = $this->getInnerMargin(); @@ -218,9 +221,10 @@ class TextBox extends Image /** * Set border size. * - * @param int $value Size in points + * @param null|int $value Size in points + * @return void */ - public function setBorderSize($value = null): void + public function setBorderSize(int $value = null): void { $this->borderSize = $value; } @@ -230,7 +234,7 @@ class TextBox extends Image * * @return int */ - public function getBorderSize() + public function getBorderSize(): int { return $this->borderSize; } @@ -238,9 +242,10 @@ class TextBox extends Image /** * Set border color. * - * @param string $value + * @param null|string $value + * @return void */ - public function setBorderColor($value = null): void + public function setBorderColor(string $value = null): void { $this->borderColor = $value; } @@ -248,9 +253,9 @@ class TextBox extends Image /** * Get border color. * - * @return string + * @return null|string */ - public function getBorderColor() + public function getBorderColor(): ?string { return $this->borderColor; } diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php index 54db9285..18fef7a6 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php @@ -2,16 +2,13 @@ /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. - * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. - * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord - * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -28,18 +25,20 @@ class TextBox extends Image { /** * Write element. + * + * @return void */ public function write(): void { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); - if (!$element instanceof \PhpOffice\PhpWord\Element\TextBox) { + if (! $element instanceof \PhpOffice\PhpWord\Element\TextBox) { return; } $style = $element->getStyle(); $styleWriter = new TextBoxStyleWriter($xmlWriter, $style); - if (!$this->withoutP) { + if (! $this->withoutP) { $xmlWriter->startElement('w:p'); $styleWriter->writeAlignment(); } @@ -53,6 +52,7 @@ class TextBox extends Image if ($style->getBgColor()) { $xmlWriter->writeAttribute('fillcolor', $style->getBgColor()); } + $styleWriter->write(); $styleWriter->writeBorder(); diff --git a/src/PhpWord/Writer/Word2007/Style/TextBox.php b/src/PhpWord/Writer/Word2007/Style/TextBox.php index 6aa6b019..89dc4a39 100644 --- a/src/PhpWord/Writer/Word2007/Style/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Style/TextBox.php @@ -28,6 +28,7 @@ class TextBox extends Frame { /** * Writer inner margin. + * @return void */ public function writeInnerMargin(): void { @@ -44,6 +45,7 @@ class TextBox extends Frame /** * Writer border. + * @return void */ public function writeBorder(): void { From a215501cc992e638edf390f087198a696d694684 Mon Sep 17 00:00:00 2001 From: hazington Date: Tue, 3 Jan 2023 23:35:37 +0100 Subject: [PATCH 06/10] Added bgcolor unit test coverage --- tests/PhpWordTests/Style/TextBoxTest.php | 84 +++++++++++++----------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/tests/PhpWordTests/Style/TextBoxTest.php b/tests/PhpWordTests/Style/TextBoxTest.php index 3c1c2436..76688377 100644 --- a/tests/PhpWordTests/Style/TextBoxTest.php +++ b/tests/PhpWordTests/Style/TextBoxTest.php @@ -2,16 +2,13 @@ /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. - * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. - * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord - * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -20,15 +17,15 @@ namespace PhpOffice\PhpWordTests\Style; use InvalidArgumentException; use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\Style\TextBox; +use PHPUnit\Framework\TestCase; /** * Test class for PhpOffice\PhpWord\Style\Image. * * @coversDefaultClass \PhpOffice\PhpWord\Style\Image - * * @runTestsInSeparateProcesses */ -class TextBoxTest extends \PHPUnit\Framework\TestCase +class TextBoxTest extends TestCase { /** * Test setting style with normal value. @@ -38,23 +35,24 @@ class TextBoxTest extends \PHPUnit\Framework\TestCase $object = new TextBox(); $properties = [ - 'width' => 200, - 'height' => 200, - 'alignment' => Jc::START, - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red', + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', + 'bgColor' => 'blue', ]; foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -72,23 +70,24 @@ class TextBoxTest extends \PHPUnit\Framework\TestCase $object = new TextBox(); $properties = [ - 'width' => 200, - 'height' => 200, - 'alignment' => Jc::START, - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red', + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', + 'bgColor' => 'blue', ]; foreach ($properties as $key => $value) { $get = "get{$key}"; @@ -305,4 +304,15 @@ class TextBoxTest extends \PHPUnit\Framework\TestCase $object->setBorderColor($expected); self::assertEquals($expected, $object->getBorderColor()); } + + /** + * Test set/get bgColor. + */ + public function testSetGetBgColor(): void + { + $expected = 'blue'; + $object = new TextBox(); + $object->setBgColor($expected); + self::assertEquals($expected, $object->getBgColor()); + } } From 050802bdb5a60980d65a50614c0fed0afb73a401 Mon Sep 17 00:00:00 2001 From: hazington Date: Tue, 3 Jan 2023 23:38:08 +0100 Subject: [PATCH 07/10] Removed @return void as not compatible with projects coding standard. --- src/PhpWord/Writer/Word2007/Element/TextBox.php | 2 -- src/PhpWord/Writer/Word2007/Style/TextBox.php | 9 ++------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php index 18fef7a6..0efc50f9 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php @@ -25,8 +25,6 @@ class TextBox extends Image { /** * Write element. - * - * @return void */ public function write(): void { diff --git a/src/PhpWord/Writer/Word2007/Style/TextBox.php b/src/PhpWord/Writer/Word2007/Style/TextBox.php index 89dc4a39..91361c9f 100644 --- a/src/PhpWord/Writer/Word2007/Style/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Style/TextBox.php @@ -2,16 +2,13 @@ /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. - * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. - * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord - * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -28,12 +25,11 @@ class TextBox extends Frame { /** * Writer inner margin. - * @return void */ public function writeInnerMargin(): void { $style = $this->getStyle(); - if (!$style instanceof TextBoxStyle || !$style->hasInnerMargins()) { + if (! $style instanceof TextBoxStyle || ! $style->hasInnerMargins()) { return; } @@ -45,12 +41,11 @@ class TextBox extends Frame /** * Writer border. - * @return void */ public function writeBorder(): void { $style = $this->getStyle(); - if (!$style instanceof TextBoxStyle) { + if (! $style instanceof TextBoxStyle) { return; } $xmlWriter = $this->getXmlWriter(); From 0f6fbf2b11c13988d9feaefe51050e9d4136b862 Mon Sep 17 00:00:00 2001 From: hazington Date: Tue, 3 Jan 2023 23:44:51 +0100 Subject: [PATCH 08/10] Fixed several CS-Fixer issues --- src/PhpWord/Style/TextBox.php | 55 +++------------ .../Writer/Word2007/Element/TextBox.php | 5 +- src/PhpWord/Writer/Word2007/Style/TextBox.php | 5 +- tests/PhpWordTests/Style/TextBoxTest.php | 69 ++++++++++--------- 4 files changed, 51 insertions(+), 83 deletions(-) diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php index 68b516b1..341d9306 100644 --- a/src/PhpWord/Style/TextBox.php +++ b/src/PhpWord/Style/TextBox.php @@ -9,6 +9,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord + * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -72,19 +73,14 @@ class TextBox extends Image /** * Set background color. - * - * @param null|string $value - * @return void */ - public function setBgColor(string $value = null): void + public function setBgColor(?string $value = null): void { $this->bgColor = $value; } /** * Get background color. - * - * @return null|string */ public function getBgColor(): ?string { @@ -93,19 +89,14 @@ class TextBox extends Image /** * Set margin top. - * - * @param null|int $value - * @return void */ - public function setInnerMarginTop(int $value = null): void + public function setInnerMarginTop(?int $value = null): void { $this->innerMarginTop = $value; } /** * Get margin top. - * - * @return null|int */ public function getInnerMarginTop(): ?int { @@ -114,19 +105,14 @@ class TextBox extends Image /** * Set margin left. - * - * @param null|int $value - * @return void */ - public function setInnerMarginLeft(int $value = null): void + public function setInnerMarginLeft(?int $value = null): void { $this->innerMarginLeft = $value; } /** * Get margin left. - * - * @return null|int */ public function getInnerMarginLeft(): ?int { @@ -135,19 +121,14 @@ class TextBox extends Image /** * Set margin right. - * - * @param null|int $value - * @return void */ - public function setInnerMarginRight(int $value = null): void + public function setInnerMarginRight(?int $value = null): void { $this->innerMarginRight = $value; } /** * Get margin right. - * - * @return null|int */ public function getInnerMarginRight(): ?int { @@ -156,19 +137,14 @@ class TextBox extends Image /** * Set margin bottom. - * - * @param null|int $value - * @return void */ - public function setInnerMarginBottom(int $value = null): void + public function setInnerMarginBottom(?int $value = null): void { $this->innerMarginBottom = $value; } /** * Get margin bottom. - * - * @return null|int */ public function getInnerMarginBottom(): ?int { @@ -179,9 +155,8 @@ class TextBox extends Image * Set TLRB cell margin. * * @param null|int $value Margin in twips - * @return void */ - public function setInnerMargin(int $value = null): void + public function setInnerMargin(?int $value = null): void { $this->setInnerMarginTop($value); $this->setInnerMarginLeft($value); @@ -201,8 +176,6 @@ class TextBox extends Image /** * Has inner margin? - * - * @return bool */ public function hasInnerMargins(): bool { @@ -222,38 +195,30 @@ class TextBox extends Image * Set border size. * * @param null|int $value Size in points - * @return void */ - public function setBorderSize(int $value = null): void + public function setBorderSize(?int $value = null): void { $this->borderSize = $value; } /** * Get border size. - * - * @return int */ - public function getBorderSize(): int + public function getBorderSize(): ?int { return $this->borderSize; } /** * Set border color. - * - * @param null|string $value - * @return void */ - public function setBorderColor(string $value = null): void + public function setBorderColor(?string $value = null): void { $this->borderColor = $value; } /** * Get border color. - * - * @return null|string */ public function getBorderColor(): ?string { diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php index 0efc50f9..ff94094d 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php @@ -9,6 +9,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord + * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -30,13 +31,13 @@ class TextBox extends Image { $xmlWriter = $this->getXmlWriter(); $element = $this->getElement(); - if (! $element instanceof \PhpOffice\PhpWord\Element\TextBox) { + if (!$element instanceof \PhpOffice\PhpWord\Element\TextBox) { return; } $style = $element->getStyle(); $styleWriter = new TextBoxStyleWriter($xmlWriter, $style); - if (! $this->withoutP) { + if (!$this->withoutP) { $xmlWriter->startElement('w:p'); $styleWriter->writeAlignment(); } diff --git a/src/PhpWord/Writer/Word2007/Style/TextBox.php b/src/PhpWord/Writer/Word2007/Style/TextBox.php index 91361c9f..d5ccf7a8 100644 --- a/src/PhpWord/Writer/Word2007/Style/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Style/TextBox.php @@ -9,6 +9,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord + * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -29,7 +30,7 @@ class TextBox extends Frame public function writeInnerMargin(): void { $style = $this->getStyle(); - if (! $style instanceof TextBoxStyle || ! $style->hasInnerMargins()) { + if (!$style instanceof TextBoxStyle || !$style->hasInnerMargins()) { return; } @@ -45,7 +46,7 @@ class TextBox extends Frame public function writeBorder(): void { $style = $this->getStyle(); - if (! $style instanceof TextBoxStyle) { + if (!$style instanceof TextBoxStyle) { return; } $xmlWriter = $this->getXmlWriter(); diff --git a/tests/PhpWordTests/Style/TextBoxTest.php b/tests/PhpWordTests/Style/TextBoxTest.php index 76688377..284829aa 100644 --- a/tests/PhpWordTests/Style/TextBoxTest.php +++ b/tests/PhpWordTests/Style/TextBoxTest.php @@ -9,6 +9,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @see https://github.com/PHPOffice/PHPWord + * * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -35,24 +36,24 @@ class TextBoxTest extends TestCase $object = new TextBox(); $properties = [ - 'width' => 200, - 'height' => 200, - 'alignment' => Jc::START, - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red', - 'bgColor' => 'blue', + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', + 'bgColor' => 'blue', ]; foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -70,24 +71,24 @@ class TextBoxTest extends TestCase $object = new TextBox(); $properties = [ - 'width' => 200, - 'height' => 200, - 'alignment' => Jc::START, - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red', - 'bgColor' => 'blue', + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', + 'bgColor' => 'blue', ]; foreach ($properties as $key => $value) { $get = "get{$key}"; From 679a738c426ff498bd1b4319c23ad1ef438d5e10 Mon Sep 17 00:00:00 2001 From: hazington Date: Tue, 3 Jan 2023 23:56:04 +0100 Subject: [PATCH 09/10] Replaced deprecated "assertRegExp" test method by assertMatchesRegularExpression. --- tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php index 98449f3b..00582e12 100644 --- a/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php @@ -408,7 +408,7 @@ class DocumentTest extends \PHPUnit\Framework\TestCase // behind $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape'); $style = $element->getAttribute('style'); - self::assertRegExp('/z\-index:\-[0-9]*/', $style); + self::assertMatchesRegularExpression('/z\-index:\-[0-9]*/', $style); // square $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap'); From 53d34fd049026752a13183891250bd3d91c482c0 Mon Sep 17 00:00:00 2001 From: hazington Date: Wed, 4 Jan 2023 00:07:39 +0100 Subject: [PATCH 10/10] Address the CI coverage issue for the regex match assertion. --- .../Writer/Word2007/Part/DocumentTest.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php index 00582e12..be8f8cc4 100644 --- a/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWordTests/Writer/Word2007/Part/DocumentTest.php @@ -2,10 +2,8 @@ /** * This file is part of PHPWord - A pure PHP library for reading and writing * word processing documents. - * * PHPWord is free software distributed under the terms of the GNU Lesser * General Public License version 3 as published by the Free Software Foundation. - * * For the full copyright and license information, please read the LICENSE * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. @@ -61,11 +59,11 @@ class DocumentTest extends \PHPUnit\Framework\TestCase $doc = TestHelperDOCX::getDocument($phpWord); self::assertNotNull($doc); -// $this->assertTrue($doc->elementExists('/Properties/property[name="key1"]/vt:lpwstr')); -// $this->assertTrue($doc->elementExists('/Properties/property[name="key2"]/vt:bool')); -// $this->assertTrue($doc->elementExists('/Properties/property[name="key3"]/vt:i4')); -// $this->assertTrue($doc->elementExists('/Properties/property[name="key4"]/vt:r8')); -// $this->assertTrue($doc->elementExists('/Properties/property[name="key5"]/vt:lpwstr')); + // $this->assertTrue($doc->elementExists('/Properties/property[name="key1"]/vt:lpwstr')); + // $this->assertTrue($doc->elementExists('/Properties/property[name="key2"]/vt:bool')); + // $this->assertTrue($doc->elementExists('/Properties/property[name="key3"]/vt:i4')); + // $this->assertTrue($doc->elementExists('/Properties/property[name="key4"]/vt:r8')); + // $this->assertTrue($doc->elementExists('/Properties/property[name="key5"]/vt:lpwstr')); } /** @@ -408,7 +406,13 @@ class DocumentTest extends \PHPUnit\Framework\TestCase // behind $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape'); $style = $element->getAttribute('style'); - self::assertMatchesRegularExpression('/z\-index:\-[0-9]*/', $style); + + // Try to address CI coverage issue for PHP 7.1 and 7.2 when using regex match assertions + if (method_exists(static::class, 'assertRegExp')) { + self::assertRegExp('/z\-index:\-[0-9]*/', $style); + } else { + self::assertMatchesRegularExpression('/z\-index:\-[0-9]*/', $style); + } // square $element = $doc->getElement('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap'); @@ -551,7 +555,13 @@ class DocumentTest extends \PHPUnit\Framework\TestCase $cell->addText('Test'); $doc = TestHelperDOCX::getDocument($phpWord); - self::assertEquals(Cell::DEFAULT_BORDER_COLOR, $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcBorders/w:top', 'w:color')); + self::assertEquals( + Cell::DEFAULT_BORDER_COLOR, + $doc->getElementAttribute( + '/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:tcBorders/w:top', + 'w:color' + ) + ); } /**