コード例 #1
0
 /**
  * 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));
     $schemaFileName = $rootDir . 'etc/' . self::CONFIGURATION_SCHEMA;
     if (!$document->validate($schemaFileName)) {
         $errors = $document->validateDomDocument($document->getDom(), $schemaFileName, $document::ERROR_FORMAT_DEFAULT);
         foreach ($errors as $error) {
             echo $error . PHP_EOL;
         }
         throw new Exception('XML file is invalid.');
     }
     $this->xml = new \DOMXPath($document->getDom());
     return $this;
 }
コード例 #2
0
ファイル: DomTest.php プロジェクト: nblair/magescotch
 public function testValidateUnknownError()
 {
     $xml = '<root><node id="id1"/><node id="id2"/></root>';
     $schemaFile = __DIR__ . '/_files/sample.xsd';
     $dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
     $domMock = $this->getMock('DOMDocument', ['schemaValidate'], []);
     $domMock->expects($this->once())
         ->method('schemaValidate')
         ->with($schemaFile)
         ->will($this->returnValue(false));
     $this->assertEquals(['Unknown validation error'], $dom->validateDomDocument($domMock, $schemaFile));
 }
コード例 #3
0
ファイル: DomTest.php プロジェクト: tingyeeh/magento2
 public function testValidateUnknownError()
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
     }
     $xml = '<root><node id="id1"/><node id="id2"/></root>';
     $schemaFile = __DIR__ . '/_files/sample.xsd';
     $dom = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock);
     $domMock = $this->getMock('DOMDocument', ['schemaValidate'], []);
     $domMock->expects($this->once())->method('schemaValidate')->with($schemaFile)->will($this->returnValue(false));
     $this->assertEquals(['Unknown validation error'], $dom->validateDomDocument($domMock, $schemaFile));
 }