add test to cover get TemplateProcessor::getVariables
This commit is contained in:
parent
575c5531b8
commit
8ffaa1c8b7
|
|
@ -425,6 +425,9 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
|
|||
$this->assertEquals('<w:t>$</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/><w:r><w:t xml:space="preserve">15,000.00. </w:t></w:r><w:r w:rsidR="0056499B"><w:t>${variable_name}</w:t></w:r>', $fixed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getMainPartName
|
||||
*/
|
||||
public function testMainPartNameDetection()
|
||||
{
|
||||
$templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/document22-xml.docx');
|
||||
|
|
@ -433,4 +436,21 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->assertEquals($variables, $templateProcessor->getVariables());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getVariables
|
||||
*/
|
||||
public function testGetVariables()
|
||||
{
|
||||
$templateProcessor = new TestableTemplateProcesor();
|
||||
|
||||
$variables = $templateProcessor->getVariablesForPart('<w:r><w:t>normal text</w:t></w:r>');
|
||||
$this->assertEquals(array(), $variables);
|
||||
|
||||
$variables = $templateProcessor->getVariablesForPart('<w:r><w:t>${documentContent}</w:t></w:r>');
|
||||
$this->assertEquals(array('documentContent'), $variables);
|
||||
|
||||
$variables = $templateProcessor->getVariablesForPart('<w:t>$</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/><w:r><w:t xml:space="preserve">15,000.00. </w:t></w:r><w:r w:rsidR="0056499B"><w:t>$</w:t></w:r><w:r w:rsidR="00573DFD" w:rsidRPr="00573DFD"><w:rPr><w:iCs/></w:rPr><w:t>{</w:t></w:r><w:proofErr w:type="spellStart"/><w:r w:rsidR="00573DFD" w:rsidRPr="00573DFD"><w:rPr><w:iCs/></w:rPr><w:t>variable_name</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r w:rsidR="00573DFD" w:rsidRPr="00573DFD"><w:rPr><w:iCs/></w:rPr><w:t>}</w:t></w:r>');
|
||||
$this->assertEquals(array('variable_name'), $variables);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@
|
|||
|
||||
namespace PhpOffice\PhpWord;
|
||||
|
||||
/**
|
||||
* This class is used to expose publicly methods that are otherwise private or protected.
|
||||
* This makes testing those methods easier
|
||||
*
|
||||
* @author troosan
|
||||
*/
|
||||
class TestableTemplateProcesor extends TemplateProcessor
|
||||
{
|
||||
public function __construct()
|
||||
|
|
@ -27,4 +33,11 @@ class TestableTemplateProcesor extends TemplateProcessor
|
|||
{
|
||||
return parent::fixBrokenMacros($documentPart);
|
||||
}
|
||||
|
||||
public function getVariablesForPart($documentPartXML)
|
||||
{
|
||||
$documentPartXML = parent::fixBrokenMacros($documentPartXML);
|
||||
|
||||
return parent::getVariablesForPart($documentPartXML);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue