/** * @param string $xmlFile * @param string $newXmlFile * @param array $ids * @param string $expectedXmlFile * @dataProvider mergeDataProvider */ public function testMerge($xmlFile, $newXmlFile, $ids, $expectedXmlFile) { $xml = file_get_contents(__DIR__ . "/_files/dom/{$xmlFile}"); $newXml = file_get_contents(__DIR__ . "/_files/dom/{$newXmlFile}"); $expectedXml = file_get_contents(__DIR__ . "/_files/dom/{$expectedXmlFile}"); $config = new Magento_Config_Dom($xml, $ids); $config->merge($newXml); $this->assertXmlStringEqualsXmlString($expectedXml, $config->getDom()->saveXML()); }
/** * Merge the config XML-files * * @param array $configFiles * @throws Exception if a non-existing or invalid XML-file passed */ protected function _merge($configFiles) { $domConfig = new Magento_Config_Dom($this->_getInitialXml(), $this->_getIdAttributes()); foreach ($configFiles as $file) { if (!file_exists($file)) { throw new Exception("File does not exist: {$file}"); } $domConfig->merge(file_get_contents($file)); if (!$domConfig->validate($this->getSchemaFile(), $errors)) { $message = "Invalid XML-file: {$file}\n"; /** @var libXMLError $error */ foreach ($errors as $error) { $message .= "{$error->message} Line: {$error->line}\n"; } throw new Exception($message); } } $this->_dom = $domConfig->getDom(); }