add test for cloneBlock operation
This commit is contained in:
parent
0f963e40a7
commit
1717bd4978
|
|
@ -393,6 +393,36 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::cloneBlock
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function testCloneBlock()
|
||||||
|
{
|
||||||
|
$mainPart = '<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<w:p>
|
||||||
|
<w:r>
|
||||||
|
<w:rPr></w:rPr>
|
||||||
|
<w:t>${CLONEME}</w:t>
|
||||||
|
</w:r>
|
||||||
|
</w:p>
|
||||||
|
<w:p>
|
||||||
|
<w:r>
|
||||||
|
<w:t xml:space="preserve">This block will be cloned</w:t>
|
||||||
|
</w:r>
|
||||||
|
</w:p>
|
||||||
|
<w:p>
|
||||||
|
<w:r w:rsidRPr="00204FED">
|
||||||
|
<w:t>${/CLONEME}</w:t>
|
||||||
|
</w:r>
|
||||||
|
</w:p>';
|
||||||
|
|
||||||
|
$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.
|
* Template macros can be fixed.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,9 @@ namespace PhpOffice\PhpWord;
|
||||||
*/
|
*/
|
||||||
class TestableTemplateProcesor extends TemplateProcessor
|
class TestableTemplateProcesor extends TemplateProcessor
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct($mainPart = null)
|
||||||
{
|
{
|
||||||
|
$this->tempDocumentMainPart = $mainPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fixBrokenMacros($documentPart)
|
public function fixBrokenMacros($documentPart)
|
||||||
|
|
@ -40,4 +41,9 @@ class TestableTemplateProcesor extends TemplateProcessor
|
||||||
|
|
||||||
return parent::getVariablesForPart($documentPartXML);
|
return parent::getVariablesForPart($documentPartXML);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMainPart()
|
||||||
|
{
|
||||||
|
return $this->tempDocumentMainPart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue