public function testRouteConfigsValidation() { global $magentoBaseDir; $invalidFiles = array(); $mask = $magentoBaseDir . '/app/code/*/*/etc/*/routes.xml'; $files = glob($mask); $mergedConfig = new \Magento\Framework\Config\Dom('<config></config>', $this->_idAttributes); foreach ($files as $file) { $content = file_get_contents($file); try { new \Magento\Framework\Config\Dom($content, $this->_idAttributes, null, $this->_schemaFile); //merge won't be performed if file is invalid because of exception thrown $mergedConfig->merge($content); } catch (\Magento\Framework\Config\Dom\ValidationException $e) { $invalidFiles[] = $file; } } if (!empty($invalidFiles)) { $this->fail('Found broken files: ' . implode("\n", $invalidFiles)); } try { $errors = array(); $mergedConfig->validate($this->_mergedSchemaFile, $errors); } catch (\Exception $e) { $this->fail('Merged routes config is invalid: ' . "\n" . implode("\n", $errors)); } }
/** * Test that email template configuration file matches the format * * @param string $file * @dataProvider fileFormatDataProvider */ public function testFileFormat($file) { $schemaFile = BP . '/app/code/Magento/Email/etc/email_templates.xsd'; $dom = new \Magento\Framework\Config\Dom(file_get_contents($file)); $result = $dom->validate($schemaFile, $errors); $this->assertTrue($result, print_r($errors, true)); }
/** * @param string $file * @dataProvider themeConfigFileDataProvider */ public function testThemeConfigFileSchema($file) { $domConfig = new \Magento\Framework\Config\Dom(file_get_contents($file), $this->validationStateMock); $errors = []; $result = $domConfig->validate('urn:magento:framework:Config/etc/theme.xsd', $errors); $this->assertTrue($result, "Invalid XML-file: {$file}\n" . join("\n", $errors)); }
/** * Test that XSD schema validates fixture XML contents producing expected results * * @param string $fixtureXml * @param string $schemaFile * @param array $expectedErrors */ protected function _testXmlAgainstXsd($fixtureXml, $schemaFile, array $expectedErrors) { $dom = new \Magento\Framework\Config\Dom($fixtureXml, array(), null, null, '%message%'); $actualResult = $dom->validate($schemaFile, $actualErrors); $this->assertEquals(empty($expectedErrors), $actualResult); $this->assertEquals($expectedErrors, $actualErrors); }
public function testMergedConfigFiles() { $invalidFiles = []; $files = $this->getConfigFiles(); $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(false); $mergedConfig = new \Magento\Framework\Config\Dom('<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></config>', $validationStateMock, $this->getIdAttributes()); foreach ($files as $file) { $content = file_get_contents($file[0]); try { $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); new \Magento\Framework\Config\Dom($content, $validationStateMock, $this->getIdAttributes()); //merge won't be performed if file is invalid because of exception thrown $mergedConfig->merge($content); } catch (\Magento\Framework\Config\Dom\ValidationException $e) { $invalidFiles[] = $file[0]; } } if (!empty($invalidFiles)) { $this->fail('Found broken files: ' . implode("\n", $invalidFiles)); } $errors = []; $mergedConfig->validate($this->getMergedSchemaFile(), $errors); if ($errors) { $this->fail('Merged routes config is invalid: ' . "\n" . implode("\n", $errors)); } }
/** * @param string $fixtureXml * @param array $expectedErrors * @dataProvider exemplarXmlDataProvider */ public function testExemplarXml($fixtureXml, array $expectedErrors) { $dom = new \Magento\Framework\Config\Dom($fixtureXml, [], null, null, '%message%'); $actualResult = $dom->validate($this->_schemaFile, $actualErrors); $this->assertEquals(empty($expectedErrors), $actualResult); $this->assertEquals($expectedErrors, $actualErrors); }
public function testRouteConfigsValidation() { $invalidFiles = []; $componentRegistrar = new ComponentRegistrar(); $files = []; foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) { $mask = $moduleDir . '/etc/*/routes.xml'; $files = array_merge($files, glob($mask)); } $mergedConfig = new \Magento\Framework\Config\Dom('<config></config>', $this->_idAttributes); foreach ($files as $file) { $content = file_get_contents($file); try { new \Magento\Framework\Config\Dom($content, $this->_idAttributes, null, $this->schemaFile); //merge won't be performed if file is invalid because of exception thrown $mergedConfig->merge($content); } catch (\Magento\Framework\Config\Dom\ValidationException $e) { $invalidFiles[] = $file; } } if (!empty($invalidFiles)) { $this->fail('Found broken files: ' . implode("\n", $invalidFiles)); } try { $errors = []; $mergedConfig->validate($this->mergedSchemaFile, $errors); } catch (\Exception $e) { $this->fail('Merged routes config is invalid: ' . "\n" . implode("\n", $errors)); } }
/** * @param string $file * @dataProvider fileFormatDataProvider */ public function testFileFormat($file) { $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock); $result = $dom->validate($this->_schemaFile, $errors); $this->assertTrue($result, print_r($errors, true)); }
/** * @param string $fixtureXml * @param array $expectedErrors * @dataProvider exemplarXmlDataProvider */ public function testExemplarXml($fixtureXml, array $expectedErrors) { $messageFormat = '%message%'; $dom = new \Magento\Framework\Config\Dom($fixtureXml, [], null, null, $messageFormat); $actualResult = $dom->validate($this->_schemaFile, $actualErrors); $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match."); $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid."); }
/** * Test that email template configuration file matches the format * * @param string $file * @dataProvider fileFormatDataProvider */ public function testFileFormat($file) { $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver(); $schemaFile = $urnResolver->getRealPath('urn:magento:module:Magento_Email:etc/email_templates.xsd'); $dom = new \Magento\Framework\Config\Dom(file_get_contents($file)); $result = $dom->validate($schemaFile, $errors); $this->assertTrue($result, print_r($errors, true)); }
/** * Test that XSD schema validates fixture XML contents producing expected results * * @param string $fixtureXml * @param string $schemaFile * @param array $expectedErrors */ protected function _testXmlAgainstXsd($fixtureXml, $schemaFile, array $expectedErrors) { $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationStateMock, [], null, null, '%message%'); $actualResult = $dom->validate($schemaFile, $actualErrors); $this->assertEquals(empty($expectedErrors), $actualResult); $this->assertEquals($expectedErrors, $actualErrors); }
/** * @param string $file * @dataProvider fileFormatDataProvider */ public function testFileFormat($file) { /** @var \Magento\Sales\Model\Order\Pdf\Config\SchemaLocator $schemaLocator */ $schemaLocator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Sales\\Model\\Order\\Pdf\\Config\\SchemaLocator'); $schemaFile = $schemaLocator->getPerFileSchema(); $dom = new \Magento\Framework\Config\Dom(file_get_contents($file)); $result = $dom->validate($schemaFile, $errors); $this->assertTrue($result, print_r($errors, true)); }
/** * @param string $file * @dataProvider viewConfigFileDataProvider */ public function testViewConfigFile($file) { /** @var \Magento\Framework\View\Xsd\Reader $reader */ $reader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\Xsd\\Reader'); $mergeXsd = $reader->read(); $domConfig = new \Magento\Framework\Config\Dom($file); $result = $domConfig->validate($mergeXsd, $errors); $this->assertTrue($result, "Invalid XML-file: {$file}\n" . join("\n", $errors)); }
/** * Test that email template configuration file matches the format * * @param string $file * @dataProvider fileFormatDataProvider */ public function testFileFormat($file) { $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver(); $schemaFile = $urnResolver->getRealPath('urn:magento:module:Magento_Email:etc/email_templates.xsd'); $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock); $result = $dom->validate($schemaFile, $errors); $this->assertTrue($result, print_r($errors, true)); }
public function testLayoutFormat() { $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this); $invoker(function ($layoutFile) { $schemaFile = BP . '/app/code/Magento/Core/etc/layout_single.xsd'; $domLayout = new \Magento\Framework\Config\Dom(file_get_contents($layoutFile)); $result = $domLayout->validate($schemaFile, $errors); $this->assertTrue($result, print_r($errors, true)); }, \Magento\TestFramework\Utility\Files::init()->getLayoutFiles()); }
/** * Test each acl configuration file * @param string $file * @dataProvider mviewConfigFileDataProvider */ public function testIndexerConfigFile($file) { $domConfig = new \Magento\Framework\Config\Dom(file_get_contents($file)); $result = $domConfig->validate($this->schemeFile, $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error}\n"; } $this->assertTrue($result, $message); }
/** * @param string $file * @dataProvider viewConfigFileDataProvider */ public function testViewConfigFile($file) { $domConfig = new \Magento\Framework\Config\Dom($file); $result = $domConfig->validate(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\Filesystem')->getPath(\Magento\Framework\App\Filesystem::LIB_INTERNAL) . '/Magento/Framework/Config/etc/view.xsd', $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error->message} Line: {$error->line}\n"; } $this->assertTrue($result, $message); }
/** * @param string $fixtureXml * @param array $expectedErrors * @dataProvider exemplarXmlDataProvider */ public function testExemplarXml($fixtureXml, array $expectedErrors) { $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $messageFormat = '%message%'; $dom = new \Magento\Framework\Config\Dom($fixtureXml, $validationStateMock, [], null, null, $messageFormat); $actualResult = $dom->validate($this->_schemaFile, $actualErrors); $this->assertEquals($expectedErrors, $actualErrors, "Validation errors does not match."); $this->assertEquals(empty($expectedErrors), $actualResult, "Validation result is invalid."); }
/** * @param string $file * @dataProvider eventConfigFilesDataProvider */ public function testEventConfigFiles($file) { $errors = []; $dom = new \Magento\Framework\Config\Dom(file_get_contents($file)); $result = $dom->validate($this->_schemaFile, $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error->message} Line: {$error->line}\n"; } $this->assertTrue($result, $message); }
/** * @param string $file * @dataProvider fileFormatDataProvider */ public function testFileFormat($file) { /** @var \Magento\Sales\Model\Order\Pdf\Config\SchemaLocator $schemaLocator */ $schemaLocator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Sales\\Model\\Order\\Pdf\\Config\\SchemaLocator'); $schemaFile = $schemaLocator->getPerFileSchema(); $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $dom = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock); $result = $dom->validate($schemaFile, $errors); $this->assertTrue($result, print_r($errors, true)); }
/** * @param string $file * @dataProvider viewConfigFileDataProvider */ public function testViewConfigFile($file) { $domConfig = new \Magento\Framework\Config\Dom($file); /** @var \Magento\Framework\Filesystem $filesystem */ $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Filesystem'); $result = $domConfig->validate($filesystem->getDirectoryRead(DirectoryList::LIB_INTERNAL)->getAbsolutePath('Magento/Framework/Config/etc/view.xsd'), $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error->message} Line: {$error->line}\n"; } $this->assertTrue($result, $message); }
/** * Test each acl configuration file * @param string $file * @dataProvider aclConfigFileDataProvider */ public function testAclConfigFile($file) { $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $domConfig = new \Magento\Framework\Config\Dom(file_get_contents($file), $validationStateMock); $result = $domConfig->validate($this->_schemeFile, $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error}\n"; } $this->assertTrue($result, $message); }
/** * @dataProvider xmlConfigFileProvider */ public function testXmlConfigFile($file, $skip = false) { if ($skip) { $this->markTestSkipped('There are no xml files in the system for this test.'); } $domConfig = new \Magento\Framework\Config\Dom($file); $result = $domConfig->validate($this->_schemaFile, $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error}\n"; } $this->assertTrue($result, $message); }
/** * @param string $file * @dataProvider viewConfigFileDataProvider */ public function testViewConfigFile($file) { $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $domConfig = new \Magento\Framework\Config\Dom($file, $validationStateMock); $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver(); $result = $domConfig->validate($urnResolver->getRealPath('urn:magento:framework:Config/etc/view.xsd'), $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error->message} Line: {$error->line}\n"; } $this->assertTrue($result, $message); }
/** * Init configuration * * @param string $groupsFile * @return $this * @throws Exception */ public function init($groupsFile) { $xmlFile = $this->getRootDir() . $groupsFile; if (!is_file($xmlFile)) { throw new Exception('Invalid groups filename: ' . $xmlFile); } $xml = file_get_contents($xmlFile); $document = new \Magento\Framework\Config\Dom($xml, $this->validationState); if (!$document->validate($this->getRootDir() . 'etc/' . self::CONFIGURATION_SCHEMA)) { throw new Exception('XML file is invalid.'); } $this->xml = new \DOMXPath($document->getDom()); return $this; }
/** * Validating xml file * * @return $this * @throws Exception */ protected function validate() { $mapFile = $this->config->getOption(self::MAP_FILE_OPTION); $rootDir = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR; $configFile = $rootDir . $mapFile; if (!is_file($configFile)) { throw new Exception('Invalid map filename: ' . $configFile); } $xml = file_get_contents($configFile); $document = $document = new \Magento\Framework\Config\Dom($xml, new \Magento\Framework\App\Arguments\ValidationState(\Magento\Framework\App\State::MODE_DEVELOPER)); if (!$document->validate($rootDir . 'etc/' . self::CONFIGURATION_SCHEMA)) { throw new Exception('XML file is invalid.'); } $this->xml = new \DOMXPath($document->getDom()); return $this; }
/** * Init configuration * * @param string $mapFile * @return $this * @throws Exception */ protected function init($mapFile) { $this->ignoredDocuments = []; $this->wildcards = null; $configFile = $this->getRootDir() . $mapFile; if (!is_file($configFile)) { throw new Exception('Invalid map filename: ' . $configFile); } $xml = file_get_contents($configFile); $document = new \Magento\Framework\Config\Dom($xml); if (!$document->validate($this->getRootDir() . 'etc/' . self::CONFIGURATION_SCHEMA)) { throw new Exception('XML file is invalid.'); } $this->xml = new \DOMXPath($document->getDom()); return $this; }
/** * @dataProvider xmlConfigFileProvider */ public function testXmlConfigFile($file, $skip = false) { if ($skip) { $this->markTestSkipped('There are no xml files in the system for this test.'); } $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(false); $domConfig = new \Magento\Framework\Config\Dom($file, $validationStateMock); $errors = []; $result = $domConfig->validate($this->_schemaFile, $errors); $message = "Invalid XML-file: {$file}\n"; foreach ($errors as $error) { $message .= "{$error}\n"; } $this->assertTrue($result, $message); }
/** * Init configuration * * @param string $configFile * @return $this * @throws Exception */ public function init($configFile = null) { if ($configFile === null) { $configFile = $this->getConfigDirectoryPath() . self::CONFIGURATION_FILE; } if (empty($configFile) || !file_exists($configFile)) { throw new Exception('Invalid config filename: ' . $configFile); } $xml = file_get_contents($configFile); $document = new \Magento\Framework\Config\Dom($xml); if (!$document->validate($this->getConfigDirectoryPath() . self::CONFIGURATION_SCHEMA)) { throw new Exception('XML file is invalid.'); } $this->config = new \DOMXPath($document->getDom()); $this->options = null; return $this; }
/** * Load configuration * * @return array */ public function load() { $localConfig = new \Magento\Framework\Config\Dom('<config/>', $this->_idAttributes); $localConfigFile = $this->_dir . '/' . self::LOCAL_CONFIG_FILE; if (file_exists($localConfigFile)) { // 1. app/etc/local.xml $localConfig->merge(file_get_contents($localConfigFile)); // 2. app/etc/<dir>/<file>.xml if (preg_match('/^[a-z\\d_-]+(\\/|\\\\)+[a-z\\d_-]+\\.xml$/', $this->_customFile)) { $localConfigExtraFile = $this->_dir . '/' . $this->_customFile; $localConfig->merge(file_get_contents($localConfigExtraFile)); } } $arrayNodeConfig = new \Magento\Framework\Config\Dom\ArrayNodeConfig(new \Magento\Framework\Config\Dom\NodePathMatcher(), $this->_idAttributes); $converter = new \Magento\Framework\Config\Converter\Dom\Flat($arrayNodeConfig); $result = $converter->convert($localConfig->getDom()); return !empty($result['config']) ? $result['config'] : array(); }