/** @test */ public function it_works() { // tag 1 $tagData = array('summary' => array('textContent' => '[[iamtag]]', 'position' => 5, 'length' => 10), 'path' => array('iamtag'), 'functions' => array()); $tag1 = new Tag($tagData['summary'], $tagData['path'], $tagData['functions']); // tag 2 $tagData = array('summary' => array('textContent' => '[[xortag]]', 'position' => 21, 'length' => 10), 'path' => array('xortag'), 'functions' => array()); $tag2 = new Tag($tagData['summary'], $tagData['path'], $tagData['functions']); // prepare xml $xml = '<supernode>The [[iamtag]] text [[xortag]] after</supernode>'; $content = new \DOMDocument('1.0', 'UTF-8'); $content->loadXML($xml); $node = $content->documentElement; // testing! $processor = new Processor(); $processor->insertTemplateLogic($tag1, $node); $expectedString = '<supernode>The <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="/values/iamtag"/> text [[xortag]] after</supernode>'; $this->assertEquals($expectedString, $content->saveXML($node)); $processor->insertTemplateLogic($tag2, $node); $expectedString = '<supernode>The <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="/values/iamtag"/> text <xsl:value-of xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="/values/xortag"/> after</supernode>'; $this->assertEquals($expectedString, $content->saveXML($node)); }
/** * @test */ public function it_collect_tokens() { $filePath = __DIR__ . '/../static/document.xml'; $cachePath = __DIR__ . '/../static/cache/'; $document = new BasicDocument($filePath); $documentFile = $document->extract($cachePath, true); $template = new \DOMDocument('1.0', 'UTF-8'); $template->preserveWhiteSpace = false; // TODO NESSESARY $template->load($documentFile); // find them all $tokenCollection = $document->getTokenCollection($template); $this->assertEquals(8, $tokenCollection->count()); // strip them all $processor = new Processor(array('[[', ']]')); $processor->wrapIntoTemplate($template); $processor->insertTemplateLogic($template, $tokenCollection); $template->formatOutput = true; $compare = $template->saveXML(); $against = '<document><paragraph><run><text>Привет </text></run><run><text></text></run><run><text>!</text></run></paragraph><paragraph><run><text>Мы протестируем </text></run><run><text>с помощью </text></run><run><text></text></run></paragraph><paragraph><run><text>Wish me</text></run><run><text></text></run><run><text>!</text></run></paragraph><paragraph><run><text>Данный </text></run><run><text></text></run><run><text>- полный бред</text></run></paragraph><paragraph><run><text></text></run><run><text></text></run><run><text></text></run></paragraph></document>'; //$this->assertEquals($against, $compare); }