From 5e93950bc3746846ab1ca45d8c9fca10f917989f Mon Sep 17 00:00:00 2001 From: Hugo Carvalho Date: Wed, 2 Oct 2019 22:15:14 -0300 Subject: [PATCH 1/6] Update templates processing docs Adding save() and saveAs() methods docs --- docs/templates-processing.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/templates-processing.rst b/docs/templates-processing.rst index 5b32aa18..2e8de3a4 100644 --- a/docs/templates-processing.rst +++ b/docs/templates-processing.rst @@ -244,3 +244,20 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples. $table->addCell(150)->addText('Cell B2'); $table->addCell(150)->addText('Cell B3'); $templateProcessor->setComplexBlock('table', $table); + +save +""""""""" +Saves the loaded template within the current directory. Returns the file path. + +.. code-block:: php + + $filepath = $templateProcessor->save(); + +saveAs +""""""""" +Saves a copy of the loaded template in the indicated path. + +.. code-block:: php + + $pathToSave = 'path/to/save/file.ext'; + $templateProcessor->saveAs($pathToSave); From b0de8e7d1d13ea4ee1f91bca70b4af021c858dd4 Mon Sep 17 00:00:00 2001 From: Manunchik <56105206+Manunchik@users.noreply.github.com> Date: Wed, 23 Oct 2019 13:41:35 +0500 Subject: [PATCH 2/6] Improve unit test --- tests/PhpWord/MediaTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/PhpWord/MediaTest.php b/tests/PhpWord/MediaTest.php index 3cf62b59..cca413f5 100644 --- a/tests/PhpWord/MediaTest.php +++ b/tests/PhpWord/MediaTest.php @@ -34,6 +34,22 @@ class MediaTest extends AbstractWebServerEmbeddedTest $this->assertEquals(array(), Media::getElements('section')); } + /** + * Get header media elements + */ + public function testGetHeaderMediaElementsWithNull() + { + $this->assertEquals(array(), Media::getElements('header')); + } + + /** + * Get footer media elements + */ + public function testGetFooterMediaElementsWithNull() + { + $this->assertEquals(array(), Media::getElements('footer')); + } + /** * Count section media elements */ From cb7ffd0ac2bc15b3c1900992d28427f7a67af081 Mon Sep 17 00:00:00 2001 From: Manunchik <56105206+Manunchik@users.noreply.github.com> Date: Wed, 23 Oct 2019 13:44:47 +0500 Subject: [PATCH 3/6] Improve unit test --- tests/PhpWord/PhpWordTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/PhpWord/PhpWordTest.php b/tests/PhpWord/PhpWordTest.php index d818e0f8..4acd0fe6 100644 --- a/tests/PhpWord/PhpWordTest.php +++ b/tests/PhpWord/PhpWordTest.php @@ -225,4 +225,13 @@ class PhpWordTest extends \PHPUnit\Framework\TestCase $this->assertEquals(2, $phpWord->getSection(0)->countElements()); $this->assertEquals(1, $phpWord->getSection(1)->countElements()); } + + /** + * @covers \PhpOffice\PhpWord\PhpWord::getSettings + */ + public function testGetSettings() + { + $phpWord = new PhpWord(); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Metadata\\Settings', $phpWord->getSettings()); + } } From 21db2d40a4fb292c7a4a5a6bd9fef928835ca0be Mon Sep 17 00:00:00 2001 From: Manunchik <56105206+Manunchik@users.noreply.github.com> Date: Wed, 23 Oct 2019 13:46:58 +0500 Subject: [PATCH 4/6] Improve unit test --- tests/PhpWord/StyleTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/PhpWord/StyleTest.php b/tests/PhpWord/StyleTest.php index cbc39c87..d45bb749 100644 --- a/tests/PhpWord/StyleTest.php +++ b/tests/PhpWord/StyleTest.php @@ -33,6 +33,7 @@ class StyleTest extends \PHPUnit\Framework\TestCase * @covers ::addParagraphStyle * @covers ::addFontStyle * @covers ::addLinkStyle + * @covers ::addNumberingStyle * @covers ::addTitleStyle * @covers ::addTableStyle * @covers ::setDefaultParagraphStyle @@ -47,6 +48,20 @@ class StyleTest extends \PHPUnit\Framework\TestCase $paragraph = array('alignment' => Jc::CENTER); $font = array('italic' => true, '_bold' => true); $table = array('bgColor' => 'CCCCCC'); + $numbering = array( + 'type' => 'multilevel', + 'levels' => array( + array( + 'start' => 1, + 'format' => 'decimal', + 'restart' => 1, + 'suffix' => 'space', + 'text' => '%1.', + 'alignment' => Jc::START, + ), + ), + ); + $styles = array( 'Paragraph' => 'Paragraph', 'Font' => 'Font', @@ -54,12 +69,13 @@ class StyleTest extends \PHPUnit\Framework\TestCase 'Table' => 'Table', 'Heading_1' => 'Font', 'Normal' => 'Paragraph', + 'Numbering' => 'Numbering', ); Style::addParagraphStyle('Paragraph', $paragraph); Style::addFontStyle('Font', $font); Style::addLinkStyle('Link', $font); - // @todo Style::addNumberingStyle + Style::addNumberingStyle('Numbering', $numbering); Style::addTitleStyle(1, $font); Style::addTableStyle('Table', $table); Style::setDefaultParagraphStyle($paragraph); From aa44594ed37b372574084eefa9f4239ea4c02c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dupont?= Date: Mon, 2 Dec 2019 14:23:34 +0100 Subject: [PATCH 5/6] fix: PHPUnit test Process() format \Symfony\Component\Process\Process refuses being passed a string with version > 5, which is installed with PHP > 7.2.5. It also refuses being passed an array with version < 3.3, which is installed with PHP < 5.5.9. Solved by checking if Process::fromShellCommandLine() exists, which was introduced in version 4.2.0. --- .../AbstractWebServerEmbeddedTest.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php b/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php index 9316a9fe..25fe836a 100644 --- a/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php +++ b/tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php @@ -26,7 +26,26 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase public static function setUpBeforeClass() { if (self::isBuiltinServerSupported()) { - self::$httpServer = new Process('php -S localhost:8080 -t tests/PhpWord/_files'); + $commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files'; + + /* + * Make sure to invoke \Symfony\Component\Process\Process correctly + * regardless of PHP version used. + * + * In Process version >= 5 / PHP >= 7.2.5, the constructor requires + * an array, while in version < 3.3 / PHP < 5.5.9 it requires a string. + * In between, it can accept both. + * + * Process::fromShellCommandLine() was introduced in version 4.2.0, + * to enable recent versions of Process to parse a command string, + * so if it is not available it means it is still possible to pass + * a string to the constructor. + */ + if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandLine')) { + self::$httpServer = Process::fromShellCommandline($commandLine); + } else { + self::$httpServer = new Process($commandLine); + } self::$httpServer->start(); while (!self::$httpServer->isRunning()) { usleep(1000); From f51811b96b08143573c7c489e5fe75b9d77d6467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Dupont?= Date: Thu, 28 Nov 2019 11:32:29 +0100 Subject: [PATCH 6/6] fix: documentation about paragraph indentation Documentation contained the wrong unit for Paragraph indentation. --- docs/styles.rst | 6 ++++-- src/PhpWord/Style/Paragraph.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/styles.rst b/docs/styles.rst index 27f8ee66..18a9c2ec 100644 --- a/docs/styles.rst +++ b/docs/styles.rst @@ -75,8 +75,10 @@ Available Paragraph style options: - ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values. - ``basedOn``. Parent style. -- ``hanging``. Hanging in *twip*. -- ``indent``. Indent in *twip*. +- ``hanging``. Hanging indentation in *half inches*. +- ``indent``. Indent (left indentation) in *half inches*. +- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine* and *hanging* indentation. + See ``\PhpOffice\PhpWord\Style\Indentation`` for possible identation types. - ``keepLines``. Keep all lines on one page, *true* or *false*. - ``keepNext``. Keep paragraph with next paragraph, *true* or *false*. - ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc. diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 6e9aaf15..72f0f809 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -198,7 +198,7 @@ class Paragraph extends Border { $key = Text::removeUnderscorePrefix($key); if ('indent' == $key || 'hanging' == $key) { - $value = $value * 720; + $value = $value * 720; // 720 twips is 0.5 inch } return parent::setStyleValue($key, $value);