/** * Inject content */ public function injectContent(NodeInterface $child, NodeInterface $parent) { if ($child instanceof BlockInterface or !$child->isPhp()) { $source = $child->compile(); } else { $source = $this->php($child->compile()); } if (!($validate = $child->validate())) { $this->getLexicon()->getFoundation()->getNodeFactory()->getCollection()->forget($child->getId()); } $content = preg_replace($this->search($child->getExtractionId()), $source, $parent->getCurrentContent(), self::LIMIT); $parent->setCurrentContent($content); }
function it_can_inject_non_php_content(NodeInterface $child, BlockInterface $parent) { $child->compile()->willReturn($content = '{{ ignoredTag1 }}{{ ignoredTag2 }}{{ ignoredTag3 }}'); $child->isPhp()->willReturn(false); $child->getExtractionId()->willReturn('__content__'); $child->validate()->willReturn(true); $parent->getCurrentContent()->willReturn('<?php foreach($items as $item): ?>__content__<?php endforeach; ?>'); $parent->setCurrentContent('<?php foreach($items as $item): ?>{{ ignoredTag1 }}{{ ignoredTag2 }}{{ ignoredTag3 }}<?php endforeach; ?>')->shouldBeCalled(); $this->injectContent($child, $parent); }