From 1717bd4978439c8fe782e5fd7ef756c5d2df7282 Mon Sep 17 00:00:00 2001 From: troosan Date: Thu, 27 Dec 2018 00:24:45 +0100 Subject: [PATCH] add test for cloneBlock operation --- tests/PhpWord/TemplateProcessorTest.php | 30 +++++++++++++++++++ .../_includes/TestableTemplateProcesor.php | 8 ++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/PhpWord/TemplateProcessorTest.php b/tests/PhpWord/TemplateProcessorTest.php index e4789671..73b4910c 100644 --- a/tests/PhpWord/TemplateProcessorTest.php +++ b/tests/PhpWord/TemplateProcessorTest.php @@ -393,6 +393,36 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase } } + /** + * @covers ::cloneBlock + * @test + */ + public function testCloneBlock() + { + $mainPart = ' + + + + ${CLONEME} + + + + + This block will be cloned + + + + + ${/CLONEME} + + '; + + $templateProcessor = new TestableTemplateProcesor($mainPart); + $templateProcessor->cloneBlock('CLONEME', 3); + + $this->assertEquals(3, substr_count($templateProcessor->getMainPart(), 'This block will be cloned')); + } + /** * Template macros can be fixed. * diff --git a/tests/PhpWord/_includes/TestableTemplateProcesor.php b/tests/PhpWord/_includes/TestableTemplateProcesor.php index 65e83695..3b6f5b56 100644 --- a/tests/PhpWord/_includes/TestableTemplateProcesor.php +++ b/tests/PhpWord/_includes/TestableTemplateProcesor.php @@ -25,8 +25,9 @@ namespace PhpOffice\PhpWord; */ class TestableTemplateProcesor extends TemplateProcessor { - public function __construct() + public function __construct($mainPart = null) { + $this->tempDocumentMainPart = $mainPart; } public function fixBrokenMacros($documentPart) @@ -40,4 +41,9 @@ class TestableTemplateProcesor extends TemplateProcessor return parent::getVariablesForPart($documentPartXML); } + + public function getMainPart() + { + return $this->tempDocumentMainPart; + } }