function test_issue267() { $testFile = dirname(__FILE__) . '/files/test2-issue267.xml'; $testFileContents = preg_replace("/\n\$/", '', file_get_contents($testFile)); $parser = new cs_phpxmlParser($testFileContents); if (!$this->assertEquals('location of this TAG is /MAIN/TAGONE/VALUE', $parser->get_tag_value('/MAIN/TAGONE/VALUE'))) { $this->gfObj->debug_print($parser->get_path('/MAIN/TAGONE/VALUE/value')); } $expectedArray = array('MAIN' => array(0 => array('TAGONE' => array(0 => array('VALUE' => array(0 => array('__data__' => "location of this TAG is /MAIN/TAGONE/VALUE")))), 'TAGTWO' => array(0 => array('__attribs__' => array('VALUE' => "this is the attribute of /MAIN/TAGTWO/attributes/VALUE"))), 'DATA' => array(0 => array('VALUE' => array(0 => array('DATA' => array(0 => array('VALUE' => array(0 => array('__data__' => "data"))))))))))); if (!$this->assertEquals($expectedArray, $parser->get_path('/'))) { $this->gfObj->debug_print(serialize($parser->get_path('/'))); $this->gfObj->debug_print(serialize($expectedArray)); } $creator = new cs_phpxmlCreator($parser->get_root_element()); $creator->load_xmlparser_data($parser); if (!$this->assertEquals($expectedArray, $creator->get_data('/'))) { $this->gfObj->debug_print($expectedArray); $this->gfObj->debug_print($creator->get_data('/')); $this->gfObj->debug_print($creator); } $creator->add_tag('/MAIN/TAGTHREE', "Test tag 3 creation", array('VALUE' => "tag3 value")); $expectedArray['MAIN'][0]['TAGTHREE'][0] = array(cs_phpxmlCreator::attributeIndex => array('VALUE' => "tag3 value"), cs_phpxmlCreator::dataIndex => "Test tag 3 creation"); if (!$this->assertEquals($expectedArray, $creator->get_data('/'))) { $this->gfObj->debug_print($expectedArray); $this->gfObj->debug_print($creator->get_data('/')); } //now see if the XML created appears identical. $expectedXml = "<main>\n" . "\t<tagone>\n" . "\t\t<value>location of this TAG is /MAIN/TAGONE/VALUE</value>\n" . "\t</tagone>\n" . "\t<tagtwo value=\"this is the attribute of /MAIN/TAGTWO/attributes/VALUE\" />\n" . "\t<data>\n" . "\t\t<value>\n" . "\t\t\t<data>\n" . "\t\t\t\t<value>data</value>\n" . "\t\t\t</data>\n" . "\t\t</value>\n" . "\t</data>\n" . "\t<tagthree value=\"tag3 value\">Test tag 3 creation</tagthree>\n" . "</main>"; if (!$this->assertEquals($expectedXml, $creator->create_xml_string())) { $this->gfObj->debug_print(serialize(htmlentities($expectedXml))); $this->gfObj->debug_print(serialize(htmlentities($creator->create_xml_string()))); } //get data on the long path... $this->assertEquals('data', $creator->get_tag_value('/MAIN/DATA/VALUE/DATA/VALUE')); $parser = new cs_phpxmlParser($testFileContents); $creator = new cs_phpxmlCreator($parser->get_root_element()); $creator->load_xmlparser_data($parser); $builder = new cs_phpxmlBuilder($creator->get_data()); $expectedXml = $testFileContents; $actualXml = $builder->get_xml_string(); if (!$this->assertEquals($expectedXml, $actualXml)) { $this->gfObj->debug_print(serialize(htmlentities($expectedXml))); $this->gfObj->debug_print(serialize(htmlentities($actualXml))); } //sub-test: make SURE that calling $builder->get_xml_string() returns the same thing on all subsequent calls. $nextCall = $builder->get_xml_string(); $this->assertEquals($actualXml, $nextCall, "Builder is not resetting internal XML string"); ///METHODRESPONSE/PARAMS/PARAM/value/STRUCT/MEMBER $creator = new cs_phpxmlCreator('methodresponse', null, false); $creator->add_tag('/METHODRESPONSE/PARAMS/PARAM/VALUE/STRUCT/MEMBER', 'stuff', array('teSt' => "1234")); $this->assertEquals('stuff', $creator->get_tag_value('/METHODRESPONSE/PARAMS/PARAM/VALUE/STRUCT/MEMBER')); //this will be equal because the path gets upper-cased. $this->assertEquals('stuff', $creator->get_tag_value('/methodResponse/params/param/value/struct/member')); //These have different cases, but should be the same because it is NOT preserving case. $this->assertEquals('1234', $creator->get_attribute('/METHODRESPONSE/PARAMS/PARAM/VALUE/STRUCT/MEMBER', 'teSt')); $this->assertEquals('1234', $creator->get_attribute('/METHODRESPONSE/PARAMS/PARAM/VALUE/STRUCT/MEMBER', 'TEST')); }
/** * Creates an XML string based upon the current internal array structure. */ public function create_xml_string($addXmlVersion = FALSE, $addEncoding = FALSE) { $xmlBuilder = new cs_phpxmlBuilder($this->a2p->get_data(), $this->preserveCase); $retval = $xmlBuilder->get_xml_string($addXmlVersion, $addEncoding); return $retval; }