Open Journal Systems  3.3.0
XMLTypeDescriptionTest.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 import('lib.pkp.classes.xslt.XMLTypeDescription');
19 
21 
25  function tearDown() : void {
27  }
28 
32  public function testInstantiateAndCheck() {
33  $this->markTestSkipped();
34  // Xdebug's scream parameter will disable the @ operator
35  // that we need for XML validation.
37 
38  // Test with dtd validation
39  $typeDescription = new XMLTypeDescription('dtd');
40  $testXmlDom = new DOMDocument();
41  $testXmlDom->load(dirname(__FILE__).'/dtdsample-valid.xml');
42  self::assertTrue($typeDescription->isCompatible($testXmlDom));
43  $testXmlDom->load(dirname(__FILE__).'/dtdsample-invalid.xml');
44  self::assertFalse($typeDescription->isCompatible($testXmlDom));
45 
46  // Test with xsd validation
47  $typeDescription = new XMLTypeDescription('schema('.dirname(__FILE__).'/xsdsample.xsd)');
48  $testXmlDom = new DOMDocument();
49  $testXmlDom->load(dirname(__FILE__).'/xsdsample-valid.xml');
50  self::assertTrue($typeDescription->isCompatible($testXmlDom));
51  $testXmlDom->load(dirname(__FILE__).'/xsdsample-invalid.xml');
52  self::assertFalse($typeDescription->isCompatible($testXmlDom));
53 
54  // Test with rng validation
55  $typeDescription = new XMLTypeDescription('relax-ng('.dirname(__FILE__).'/rngsample.rng)');
56  $testXmlDom = new DOMDocument();
57  $testXmlDom->load(dirname(__FILE__).'/rngsample-valid.xml');
58  self::assertTrue($typeDescription->isCompatible($testXmlDom));
59  $testXmlDom->load(dirname(__FILE__).'/rngsample-invalid.xml');
60  self::assertFalse($typeDescription->isCompatible($testXmlDom));
61 
62  // Try passing in the document as a string
63  $document =
64  '<addressBook>
65  <card>
66  <name>John Smith</name>
67  <email>js@example.com</email>
68  </card>
69  <card>
70  <name>Fred Bloggs</name>
71  <email>fb@example.net</email>
72  </card>
73  </addressBook>';
74  self::assertTrue($typeDescription->isCompatible($document));
75 
76 
77  // Test without schema validation
78  $typeDescription = new XMLTypeDescription('*');
79  $testXmlDom = new DOMDocument();
80  $testXmlDom->load(dirname(__FILE__).'/rngsample-valid.xml');
81  self::assertTrue($typeDescription->isCompatible($testXmlDom));
82  $testXmlDom->load(dirname(__FILE__).'/rngsample-invalid.xml');
83  self::assertTrue($typeDescription->isCompatible($testXmlDom));
84  }
85 
86 }
87 
XMLTypeDescriptionTest\tearDown
tearDown()
Definition: XMLTypeDescriptionTest.php:25
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
PKPTestHelper\xdebugScream
static xdebugScream($scream)
Definition: PKPTestHelper.inc.php:150
XMLTypeDescriptionTest\testInstantiateAndCheck
testInstantiateAndCheck()
Definition: XMLTypeDescriptionTest.php:32
XMLTypeDescription
Class that describes an XML input/output type.
Definition: XMLTypeDescription.inc.php:34
XMLTypeDescriptionTest
Test class for XMLTypeDescription.
Definition: XMLTypeDescriptionTest.php:20