Ejemplo n.º 1
0
 public function testGetSchemaFile()
 {
     $config = new \Magento\Framework\Config\Theme($this->urnResolverMock, null);
     $this->urnResolverMock->expects($this->exactly(2))->method('getRealPath')->with('urn:magento:framework:Config/etc/theme.xsd')->willReturn($this->urnResolver->getRealPath('urn:magento:framework:Config/etc/theme.xsd'));
     $this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:Config/etc/theme.xsd'), $config->getSchemaFile());
     $this->assertFileExists($config->getSchemaFile());
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Invalid XML in file
  */
 public function testReadWithInvalidXml()
 {
     $this->_schemaLocatorMock->expects($this->any())->method('getPerFileSchema')->will($this->returnValue($this->urnResolver->getRealPath('urn:magento:framework:Config/Test/Unit/_files/reader/schema.xsd')));
     $this->_validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
     $model = new Filesystem($this->_fileResolverMock, $this->_converterMock, $this->_schemaLocatorMock, $this->_validationStateMock, 'fileName', []);
     $this->_fileResolverMock->expects($this->once())->method('get')->will($this->returnValue([$this->_file]));
     $model->read('scope');
 }
 public function testFileSchemaUsingInvalidXml()
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         $this->markTestSkipped('Skipped due to MAGETWO-45033');
     }
     $xmlFile = __DIR__ . '/_files/invalid_widget.xml';
     $schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget_file.xsd');
     $this->_validateFileExpectFailure($xmlFile, $schema);
 }
 public function testFileSchemaUsingInvalidXml()
 {
     $xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
     $dom = new \DOMDocument();
     $dom->loadXML(file_get_contents($xmlFile));
     $schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
     $errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
     if (!$errors) {
         $this->fail('There is a problem with the schema.  A known bad XML file passed validation');
     }
 }
 public function testFileSchemaUsingInvalidXml()
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         $this->markTestSkipped('Skipped due to MAGETWO-45033');
     }
     $xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
     $dom = new \DOMDocument();
     $dom->loadXML(file_get_contents($xmlFile));
     $schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
     $errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
     if (!$errors) {
         $this->fail('There is a problem with the schema.  A known bad XML file passed validation');
     }
 }
 /**
  * Get an array of URNs
  *
  * @param OutputInterface $output
  * @return array
  */
 private function getUrnDictionary(OutputInterface $output)
 {
     $files = $this->filesUtility->getXmlCatalogFiles('*.xml');
     $files = array_merge($files, $this->filesUtility->getXmlCatalogFiles('*.xsd'));
     $urns = [];
     foreach ($files as $file) {
         $content = $this->rootDirRead->readFile($this->rootDirRead->getRelativePath($file[0]));
         $matches = [];
         preg_match_all('/schemaLocation="(urn\\:magento\\:[^"]*)"/i', $content, $matches);
         if (isset($matches[1])) {
             $urns = array_merge($urns, $matches[1]);
         }
     }
     $urns = array_unique($urns);
     $paths = [];
     foreach ($urns as $urn) {
         try {
             $paths[$urn] = $this->urnResolver->getRealPath($urn);
         } catch (\Exception $e) {
             // don't add unsupported element to array
             if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                 $output->writeln($e->getMessage());
             }
         }
     }
     return $paths;
 }
Ejemplo n.º 7
0
 /**
  * Validate dom document
  *
  * @param \DOMDocument $dom
  * @param string $schema Absolute schema file path or URN
  * @param string $errorFormat
  * @return array of errors
  * @throws \Exception
  */
 public static function validateDomDocument(\DOMDocument $dom, $schema, $errorFormat = self::ERROR_FORMAT_DEFAULT)
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         return [];
     }
     if (!self::$urnResolver) {
         self::$urnResolver = new UrnResolver();
     }
     $schema = self::$urnResolver->getRealPath($schema);
     libxml_use_internal_errors(true);
     libxml_set_external_entity_loader([self::$urnResolver, 'registerEntityLoader']);
     $errors = [];
     try {
         $result = $dom->schemaValidate($schema);
         if (!$result) {
             $errors = self::getXmlErrors($errorFormat);
         }
     } catch (\Exception $exception) {
         libxml_use_internal_errors(false);
         throw $exception;
     }
     libxml_set_external_entity_loader(null);
     libxml_use_internal_errors(false);
     return $errors;
 }
Ejemplo n.º 8
0
 /**
  * Build DOM with initial XML contents and specifying identifier attributes for merging
  *
  * Format of $schema: Absolute schema file path or URN
  * Format of $idAttributes: array('name', 'id')
  * Format of $contextXPath: array('/config/ui')
  * The path to ID attribute name should not include any attribute notations or modifiers -- only node names
  *
  * @param UrnResolver $urnResolver
  * @param string $schema Absolute schema file path or URN
  * @param bool $isMergeSimpleXMLElement
  * @param array $contextXPath
  * @param array $idAttributes
  */
 public function __construct(UrnResolver $urnResolver, $schema, $isMergeSimpleXMLElement = false, array $contextXPath = [], array $idAttributes = [])
 {
     $this->schemaFilePath = $urnResolver->getRealPath($schema);
     $this->isMergeSimpleXMLElement = $isMergeSimpleXMLElement;
     $this->contextXPath = $contextXPath;
     $this->idAttributes = $idAttributes;
 }
Ejemplo n.º 9
0
 /**
  * Validate dom document
  *
  * @param \DOMDocument $dom
  * @param string $schema Absolute schema file path or URN
  * @param string $errorFormat
  * @return array of errors
  * @throws \Exception
  */
 public static function validateDomDocument(
     \DOMDocument $dom,
     $schema,
     $errorFormat = self::ERROR_FORMAT_DEFAULT
 ) {
     if (!self::$urnResolver) {
         self::$urnResolver = new UrnResolver();
     }
     $schema = self::$urnResolver->getRealPath($schema);
     libxml_use_internal_errors(true);
     libxml_set_external_entity_loader([self::$urnResolver, 'registerEntityLoader']);
     try {
         $result = $dom->schemaValidate($schema);
         $errors = [];
         if (!$result) {
             $validationErrors = libxml_get_errors();
             if (count($validationErrors)) {
                 foreach ($validationErrors as $error) {
                     $errors[] = self::_renderErrorMessage($error, $errorFormat);
                 }
             } else {
                 $errors[] = 'Unknown validation error';
             }
         }
     } catch (\Exception $exception) {
         libxml_use_internal_errors(false);
         throw $exception;
     }
     libxml_set_external_entity_loader(null);
     libxml_use_internal_errors(false);
     return $errors;
 }
Ejemplo n.º 10
0
 /**
  * Test schema file exists
  */
 public function testGetSchemaFile()
 {
     $this->_initConfig();
     $this->assertEquals(
         $this->urnResolver->getRealPath('urn:magento:framework:Validator/etc/validation.xsd'),
         $this->_config->getSchemaFile()
     );
     $this->assertFileExists($this->_config->getSchemaFile());
 }
Ejemplo n.º 11
0
 /**
  * Get merged xsd file
  *
  * @param array $fileList
  * @param string $baseXsd
  * @return null|string
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function readXsdFiles($fileList, $baseXsd = null)
 {
     $baseXsd = new \DOMDocument();
     $baseXsdPath = $this->urnResolver->getRealPath($this->searchFilesPattern . $this->fileName);
     $baseXsd->load($baseXsdPath);
     $configMerge = null;
     foreach ($fileList as $key => $content) {
         if ($key == $baseXsdPath) {
             continue;
         }
         try {
             if (!empty($content)) {
                 if ($configMerge) {
                     $configMerge = $this->mergeXsd($configMerge, $content);
                 } else {
                     $configMerge = $this->mergeXsd($baseXsd->saveXML(), $content);
                 }
             }
         } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
             throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase("Invalid XSD in file %1:\n%2", [$key, $e->getMessage()]));
         }
     }
     return $configMerge;
 }
Ejemplo n.º 12
0
 /**
  * Get path to merged config schema
  *
  * @return string|null
  */
 public function getSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Cache/etc/cache.xsd');
 }
Ejemplo n.º 13
0
 public function testGetPerFileSchema()
 {
     $this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:Api/etc/extension_attributes.xsd'), $this->model->getPerFileSchema());
 }
Ejemplo n.º 14
0
 /**
  * Initialize dependencies.
  *
  * @param \Magento\Framework\Config\Dom\UrnResolver $urnResolver
  */
 public function __construct(\Magento\Framework\Config\Dom\UrnResolver $urnResolver)
 {
     $this->schema = $urnResolver->getRealPath('urn:magento:framework:Communication/etc/communication.xsd');
     $this->perFileSchema = $urnResolver->getRealPath('urn:magento:framework:Communication/etc/communication.xsd');
 }
Ejemplo n.º 15
0
 /**
  * Get path to pre file validation schema
  *
  * @return null
  */
 public function getPerFileSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_request.xsd');
 }
Ejemplo n.º 16
0
 /**
  * Get absolute path to theme.xsd
  *
  * @return string
  */
 public function getSchemaFile()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Config/etc/theme.xsd');
 }
Ejemplo n.º 17
0
 public function testGetPerFileSchema()
 {
     $this->urnResolverMock->expects($this->once())->method('getRealPath')->with('urn:magento:framework:Search/etc/search_request.xsd')->willReturn($this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_request.xsd'));
     $this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_request.xsd'), $this->schemaLocator->getPerFileSchema());
 }
Ejemplo n.º 18
0
 /**
  * @param \Magento\Framework\Config\DomFactory $domConfigFactory
  * @param \Magento\Framework\Config\Dom\UrnResolver $urnResolver
  */
 public function __construct(\Magento\Framework\Config\DomFactory $domConfigFactory, UrnResolver $urnResolver)
 {
     $this->_domConfigFactory = $domConfigFactory;
     $this->_initMessageTemplates();
     $this->_xsdSchemas = [self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath('urn:magento:framework:View/Layout/etc/page_layout.xsd'), self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath('urn:magento:framework:View/Layout/etc/layout_merged.xsd')];
 }
Ejemplo n.º 19
0
 /**
  * Get path to merged config schema
  *
  * @return string
  */
 public function getSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:ObjectManager/etc/config.xsd');
 }
Ejemplo n.º 20
0
 public function testGetSchemaFile()
 {
     $method = new \ReflectionMethod($this->config, 'getSchemaFile');
     $method->setAccessible(true);
     $this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:App/Language/package.xsd'), $method->invoke($this->config));
 }
Ejemplo n.º 21
0
 /**
  * @param \Magento\Framework\Config\Dom\UrnResolver $urnResolver
  */
 public function __construct(\Magento\Framework\Config\Dom\UrnResolver $urnResolver)
 {
     $this->schema = $urnResolver->getRealPath('urn:magento:framework:View/Layout/etc/page_types.xsd');
 }
Ejemplo n.º 22
0
 /**
  * @expectedException \Magento\Framework\Exception\NotFoundException
  * @expectedExceptionMessage Could not locate schema: 'urn:magento:module:Magento_Test:test.xsd' at '/test.xsd'
  */
 public function testGetRealPathWrongModule()
 {
     $xsdUrn = 'urn:magento:module:Magento_Test:test.xsd';
     $this->urnResolver->getRealPath($xsdUrn);
 }
Ejemplo n.º 23
0
 /**
  * @param string $xmlString
  * @param array $expectedError
  * @dataProvider schemaCorrectlyIdentifiesInvalidXmlDataProvider
  */
 public function testSchemaCorrectlyIdentifiesInvalidXml($xmlString, $expectedError)
 {
     $actualError = $this->_xsdValidator->validate($this->urnResolver->getRealPath('urn:magento:framework:Indexer/etc/indexer_merged.xsd'), $xmlString);
     $this->assertEquals($expectedError, $actualError);
 }
Ejemplo n.º 24
0
 /**
  * Get path to pre file validation schema
  *
  * @return string
  */
 public function getPerFileSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Event/etc/events.xsd');
 }
Ejemplo n.º 25
0
 /**
  * Returns the name of the XSD file to be used to validate partial XML
  *
  * @return string
  */
 protected function _getFileXsd()
 {
     return $this->urnResolver->getRealPath('urn:magento:module:Magento_Payment:etc/payment_file.xsd');
 }
 /**
  * Returns the name of the XSD file to be used to validate partial XML
  *
  * @return string
  */
 protected function _getFileXsd()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_request.xsd');
 }
Ejemplo n.º 27
0
 public function testGetPerFileSchema()
 {
     $this->urnResolverMock->expects($this->once())->method('getRealPath')->with('urn:magento:framework:Indexer/etc/indexer.xsd')->willReturn($this->urnResolver->getRealPath('urn:magento:framework:Indexer/etc/indexer.xsd'));
     $this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:Indexer/etc/indexer.xsd'), $this->model->getPerFileSchema());
 }
Ejemplo n.º 28
0
 /**
  * Get path to merged config schema
  *
  * @return string
  */
 public function getSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Api/etc/extension_attributes.xsd');
 }
Ejemplo n.º 29
0
 /**
  * Get absolute path to validation scheme for language.xml
  *
  * @return string
  */
 protected function getSchemaFile()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:App/Language/package.xsd');
 }
Ejemplo n.º 30
0
 /**
  * Returns the name of the XSD file to be used to validate partial XML
  *
  * @return string
  */
 protected function _getFileXsd()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Indexer/etc/indexer.xsd');
 }