Skip to content

Commit 1717bd4

Browse files
committed
add test for cloneBlock operation
1 parent 0f963e4 commit 1717bd4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

tests/PhpWord/TemplateProcessorTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,36 @@ public function cloneBlockCanCloneABlockTwice()
393393
}
394394
}
395395

396+
/**
397+
* @covers ::cloneBlock
398+
* @test
399+
*/
400+
public function testCloneBlock()
401+
{
402+
$mainPart = '<?xml version="1.0" encoding="UTF-8"?>
403+
<w:p>
404+
<w:r>
405+
<w:rPr></w:rPr>
406+
<w:t>${CLONEME}</w:t>
407+
</w:r>
408+
</w:p>
409+
<w:p>
410+
<w:r>
411+
<w:t xml:space="preserve">This block will be cloned</w:t>
412+
</w:r>
413+
</w:p>
414+
<w:p>
415+
<w:r w:rsidRPr="00204FED">
416+
<w:t>${/CLONEME}</w:t>
417+
</w:r>
418+
</w:p>';
419+
420+
$templateProcessor = new TestableTemplateProcesor($mainPart);
421+
$templateProcessor->cloneBlock('CLONEME', 3);
422+
423+
$this->assertEquals(3, substr_count($templateProcessor->getMainPart(), 'This block will be cloned'));
424+
}
425+
396426
/**
397427
* Template macros can be fixed.
398428
*

tests/PhpWord/_includes/TestableTemplateProcesor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
*/
2626
class TestableTemplateProcesor extends TemplateProcessor
2727
{
28-
public function __construct()
28+
public function __construct($mainPart = null)
2929
{
30+
$this->tempDocumentMainPart = $mainPart;
3031
}
3132

3233
public function fixBrokenMacros($documentPart)
@@ -40,4 +41,9 @@ public function getVariablesForPart($documentPartXML)
4041

4142
return parent::getVariablesForPart($documentPartXML);
4243
}
44+
45+
public function getMainPart()
46+
{
47+
return $this->tempDocumentMainPart;
48+
}
4349
}

0 commit comments

Comments
 (0)