Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FieldsetConfigTest.php
Go to the documentation of this file.
1 <?php
9 
10 class FieldsetConfigTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $urnResolver;
14 
15  protected function setUp()
16  {
17  $this->urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
18  }
19 
20  public function testXmlFiles()
21  {
22  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
23  $invoker(
27  function ($configFile) {
28  $dom = new \DOMDocument();
29  $dom->loadXML(file_get_contents($configFile));
30  $schema = $this->urnResolver->getRealPath(
31  'urn:magento:framework:DataObject/etc/fieldset_file.xsd'
32  );
34  if ($errors) {
35  $this->fail(
36  'XML-file ' . $configFile . ' has validation errors:' . PHP_EOL . implode(
37  PHP_EOL . PHP_EOL,
38  $errors
39  )
40  );
41  }
42  },
43  \Magento\Framework\App\Utility\Files::init()->getConfigFiles('fieldset.xml', [], true)
44  );
45  }
46 
47  public function testSchemaUsingValidXml()
48  {
49  $xmlFile = __DIR__ . '/_files/fieldset.xml';
50  $dom = new \DOMDocument();
51  $dom->loadXML(file_get_contents($xmlFile));
52  $schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset.xsd');
54  if ($errors) {
55  $this->fail(
56  'There is a problem with the schema. A known good XML file failed validation: ' . PHP_EOL . implode(
57  PHP_EOL . PHP_EOL,
58  $errors
59  )
60  );
61  }
62  }
63 
64  public function testSchemaUsingInvalidXml()
65  {
66  if (!function_exists('libxml_set_external_entity_loader')) {
67  $this->markTestSkipped('Skipped due to MAGETWO-45033');
68  }
69  $xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
70  $dom = new \DOMDocument();
71  $dom->loadXML(file_get_contents($xmlFile));
72  $schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset.xsd');
74  if (!$errors) {
75  $this->fail('There is a problem with the schema. A known bad XML file passed validation');
76  }
77  }
78 
79  public function testFileSchemaUsingValidXml()
80  {
81  $xmlFile = __DIR__ . '/_files/fieldset_file.xml';
82  $dom = new \DOMDocument();
83  $dom->loadXML(file_get_contents($xmlFile));
84  $schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
86  if ($errors) {
87  $this->fail(
88  'There is a problem with the schema. A known good XML file failed validation: ' . PHP_EOL . implode(
89  PHP_EOL . PHP_EOL,
90  $errors
91  )
92  );
93  }
94  }
95 
97  {
98  if (!function_exists('libxml_set_external_entity_loader')) {
99  $this->markTestSkipped('Skipped due to MAGETWO-45033');
100  }
101  $xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
102  $dom = new \DOMDocument();
103  $dom->loadXML(file_get_contents($xmlFile));
104  $schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
106  if (!$errors) {
107  $this->fail('There is a problem with the schema. A known bad XML file passed validation');
108  }
109  }
110 }
static validateDomDocument(\DOMDocument $dom, $schema, $errorFormat=self::ERROR_FORMAT_DEFAULT)
Definition: Dom.php:301
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$errors
Definition: overview.phtml:9