/** * Test the successful execution of the 'read' method * * @return void */ public function testReadSuccessNotValidatedCase() { $content = '<config><item name="test1"></item><item name="test2"></item></config>'; $expectedResult = ['result_data']; $fileList = ['file' => $content]; $this->fileResolverMock->expects($this->once())->method('get')->with('system.xml', 'global')->willReturn($fileList); $this->compilerMock->expects($this->once())->method('compile')->with($this->isInstanceOf('\\DOMElement'), $this->isInstanceOf('Magento\\Framework\\DataObject'), $this->isInstanceOf('Magento\\Framework\\DataObject')); $this->converterMock->expects($this->once())->method('convert')->with($this->isInstanceOf('\\DOMDocument'))->willReturn($expectedResult); $this->assertEquals($expectedResult, $this->reader->read()); }
/** * Compiles the Element node * * @param CompilerInterface $compiler * @param \DOMElement $node * @param Object $processedObject * @param Object $context * @return void */ public function compile(CompilerInterface $compiler, \DOMElement $node, Object $processedObject, Object $context) { $name = $node->getAttribute('name'); /** @var UiComponentInterface $processedObject */ $content = (string) $processedObject->renderChildComponent($name); $name .= '_' . sprintf('%x', crc32(spl_object_hash($context))); if (!empty($content)) { $compiler->setPostprocessingData($name, $content); $newNode = $node->ownerDocument->createTextNode(CompilerInterface::PATTERN_TAG . $name . CompilerInterface::PATTERN_TAG); $node->parentNode->replaceChild($newNode, $node); } else { $node->parentNode->removeChild($node); } }
/** * Compiles the Element node * * @param CompilerInterface $compiler * @param \DOMElement $node * @param DataObject $processedObject * @param DataObject $context * @return void */ public function compile(CompilerInterface $compiler, \DOMElement $node, DataObject $processedObject, DataObject $context) { $ownerDocument = $node->ownerDocument; $parentNode = $node->parentNode; $document = new \DOMDocument(); $document->loadXML($this->getContent($node->getAttribute(static::INCLUDE_PATH))); foreach ($this->getChildNodes($document->documentElement) as $child) { $compiler->compile($child, $processedObject, $context); } $newFragment = $ownerDocument->createDocumentFragment(); foreach ($document->documentElement->childNodes as $child) { $newFragment->appendXML($document->saveXML($child)); } $parentNode->replaceChild($newFragment, $node); }
/** * Processing nodes of the document before merging * * @param string $content * @return string */ protected function processingDocument($content) { $object = new DataObject(); $document = new \DOMDocument(); $document->loadXML($content); $this->compiler->compile($document->documentElement, $object, $object); return $document->saveXML(); }
/** * Returns the string representation * * @return string */ public function __toString() { try { $templateRootElement = $this->getDocumentElement(); foreach ($templateRootElement->attributes as $name => $attribute) { if ('noNamespaceSchemaLocation' === $name) { $this->getDocumentElement()->removeAttributeNode($attribute); break; } } $templateRootElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); $this->compiler->compile($templateRootElement, $this->component, $this->component); $this->appendLayoutConfiguration(); $result = $this->compiler->postprocessing($this->template->__toString()); } catch (\Exception $e) { $result = ''; } return $result; }
/** * Compiles the Element node * * @param CompilerInterface $compiler * @param \DOMElement $node * @param DataObject $processedObject * @param DataObject $context * @return void */ public function compile(CompilerInterface $compiler, \DOMElement $node, DataObject $processedObject, DataObject $context) { foreach ($this->getChildNodes($node) as $child) { $compiler->compile($child, $processedObject, $context); } }