コード例 #1
0
ファイル: ThemeTest.php プロジェクト: tingyeeh/magento2
 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());
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: FilesystemTest.php プロジェクト: tingyeeh/magento2
 /**
  * @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');
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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');
     }
 }
コード例 #6
0
 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');
     }
 }
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
ファイル: Dom.php プロジェクト: Doability/magento2dev
 /**
  * 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;
 }
コード例 #9
0
ファイル: Dom.php プロジェクト: nblair/magescotch
 /**
  * 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;
 }
コード例 #10
0
ファイル: ConfigTest.php プロジェクト: nblair/magescotch
 /**
  * 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());
 }
コード例 #11
0
ファイル: Reader.php プロジェクト: whoople/magento2-testing
 /**
  * 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;
 }
コード例 #12
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');
 }
コード例 #13
0
 /**
  * Get path to merged config schema
  *
  * @return string
  */
 public function getSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:ObjectManager/etc/config.xsd');
 }
コード例 #14
0
ファイル: SchemaLocator.php プロジェクト: tingyeeh/magento2
 /**
  * Get path to merged config schema
  *
  * @return string|null
  */
 public function getSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Cache/etc/cache.xsd');
 }
コード例 #15
0
 public function testGetPerFileSchema()
 {
     $this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:Api/etc/extension_attributes.xsd'), $this->model->getPerFileSchema());
 }
コード例 #16
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');
 }
コード例 #17
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');
 }
コード例 #18
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');
 }
コード例 #19
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());
 }
コード例 #20
0
 /**
  * Get path to merged config schema
  *
  * @return string
  */
 public function getSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Api/etc/extension_attributes.xsd');
 }
コード例 #21
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:Search/etc/search_request.xsd');
 }
コード例 #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);
 }
コード例 #23
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')];
 }
コード例 #24
0
ファイル: ConfigTest.php プロジェクト: Doability/magento2dev
 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));
 }
コード例 #25
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');
 }
コード例 #26
0
 /**
  * Get path to pre file validation schema
  *
  * @return string
  */
 public function getPerFileSchema()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Event/etc/events.xsd');
 }
コード例 #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());
 }
コード例 #28
0
ファイル: XsdTest.php プロジェクト: whoople/magento2-testing
 /**
  * @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);
 }
コード例 #29
0
ファイル: Config.php プロジェクト: whoople/magento2-testing
 /**
  * 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');
 }
コード例 #30
0
ファイル: Theme.php プロジェクト: IlyaGluschenko/test001
 /**
  * Get absolute path to theme.xsd
  *
  * @return string
  */
 public function getSchemaFile()
 {
     return $this->urnResolver->getRealPath('urn:magento:framework:Config/etc/theme.xsd');
 }