Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
XsdValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class XsdValidatorTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_validator;
14 
19  protected $_xsdSchema;
20 
21  protected function setUp()
22  {
23  if (!function_exists('libxml_set_external_entity_loader')) {
24  $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
25  }
26  $this->_validator = new \Magento\Framework\TestFramework\Unit\Utility\XsdValidator();
27  $this->_xsdSchema = realpath(__DIR__ . '/_files/valid.xsd');
28  }
29 
30  public function testValidXml()
31  {
32  $xmlFile = realpath(__DIR__ . '/_files/valid.xml');
33  $xmlString = file_get_contents($xmlFile);
34 
35  $this->assertEquals([], $this->_validator->validate($this->_xsdSchema, $xmlString));
36  }
37 
38  public function testInvalidXml()
39  {
40  $xmlFile = realpath(__DIR__ . '/_files/invalid.xml');
41  $expected = [
42  "Element 'block', attribute 'type': The attribute 'type' is not allowed.\nLine: 9\n",
43  "Element 'actions': This element is not expected. Expected is ( property ).\nLine: 10\n",
44  ];
45  $xmlString = file_get_contents($xmlFile);
46 
47  $this->assertEquals($expected, $this->_validator->validate($this->_xsdSchema, $xmlString));
48  }
49 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60