1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- abstract class WP_Test_XML_TestCase extends WP_UnitTestCase {
-
- public function loadXML( $xml, $options = 0 ) {
-
-
- $internal = libxml_use_internal_errors( true );
- libxml_clear_errors();
- $xml_dom = new DOMDocument();
- $xml_dom->loadXML( $xml, $options );
- $libxml_last_error = libxml_get_last_error();
- $this->assertFalse(
- isset( $libxml_last_error->message ),
- isset( $libxml_last_error->message ) ? sprintf( 'Non-well-formed XML: %s.', $libxml_last_error->message ) : ''
- );
-
- libxml_use_internal_errors( $internal );
- libxml_clear_errors();
- return $xml_dom;
- }
-
- public function normalizeXML( $xml, $options = 0 ) {
- if ( ! class_exists( 'XSLTProcessor' ) ) {
- $this->markTestSkipped( 'This test requires the XSL extension.' );
- }
- static $xslt_proc;
- if ( ! $xslt_proc ) {
- $xslt_proc = new XSLTProcessor();
- $xslt_proc->importStyleSheet( simplexml_load_file( __DIR__ . '/normalize-xml.xsl' ) );
- }
- return $xslt_proc->transformToXML( $this->loadXML( $xml, $options ) );
- }
-
- public function assertXMLEquals( $expectedXml, $actualXml, $message = '' ) {
- $this->assertSame( $this->normalizeXML( $expectedXml ), $this->normalizeXML( $actualXml ), $message );
- }
-
- public function assertXMLNotEquals( $expectedXml, $actualXml, $message = '' ) {
- $this->assertNotEquals( $this->normalizeXML( $expectedXml ), $this->normalizeXML( $actualXml ), $message );
- }
- }
|