PageRenderTime 44ms CodeModel.GetById 3ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/libs/xml.test.php

https://github.com/hardsshah/bookmarks
PHP | 1060 lines | 657 code | 60 blank | 343 comment | 0 complexity | cdbd28e116b3dd7c03c09bd6c9655eeb MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/* SVN FILE: $Id$ */
   3/**
   4 * XmlTest file
   5 *
   6 * Long description for file
   7 *
   8 * PHP versions 4 and 5
   9 *
  10 * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11 * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12 *
  13 *  Licensed under The Open Group Test Suite License
  14 *  Redistributions of files must retain the above copyright notice.
  15 *
  16 * @filesource
  17 * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18 * @link          https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19 * @package       cake
  20 * @subpackage    cake.tests.cases.libs
  21 * @since         CakePHP(tm) v 1.2.0.5432
  22 * @version       $Revision$
  23 * @modifiedby    $LastChangedBy$
  24 * @lastmodified  $Date$
  25 * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26 */
  27App::import('Core', 'Xml');
  28/**
  29 * XmlTest class
  30 *
  31 * @package       cake
  32 * @subpackage    cake.tests.cases.libs
  33 */
  34class XmlTest extends CakeTestCase {
  35/**
  36 * setUp method
  37 *
  38 * @access public
  39 * @return void
  40 */
  41	function setUp() {
  42		$manager =& new XmlManager();
  43		$manager->namespaces = array();
  44	}
  45/**
  46 * testRootTagParsing method
  47 *
  48 * @access public
  49 * @return void
  50 */
  51	function testRootTagParsing() {
  52		$input = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . "\n" .
  53			'<plugin id="1" version_id="1" name="my_plugin" title="My Plugin" author="Me" author_email="me@cakephp.org" description="My awesome package" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13">'
  54			.'<current id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13" />'
  55			.'<version id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13" />'
  56			.'</plugin>';
  57		$xml = new Xml($input);
  58		$this->assertEqual($xml->children[0]->name, 'plugin');
  59		$this->assertEqual($xml->children[0]->children[0]->name, 'current');
  60		$this->assertEqual($xml->toString(true), $input);
  61	}
  62/**
  63 * testSerialization method
  64 *
  65 * @access public
  66 * @return void
  67 */
  68	function testSerialization() {
  69		$input = array(
  70			array(
  71				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
  72				'Style' => array('id' => null, 'name' => null),
  73				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  74				'Industry' => array('id' => 1, 'name' => 'Financial')
  75			),
  76			array(
  77				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
  78				'Style' => array('id' => null, 'name' => null),
  79				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  80				'Industry' => array('id' => 2, 'name' => 'Education')
  81			)
  82		);
  83
  84		$xml = new Xml($input);
  85		$result = preg_replace("/\n/",'', $xml->toString(false));
  86		$expected = '<project id="1" title="" client_id="1" show="1" is_spotlight="" style_id="0" job_type_id="1" industry_id="1" modified="" created=""><style id="" name="" /><job_type id="1" name="Touch Screen Kiosk" /><industry id="1" name="Financial" /></project><project id="2" title="" client_id="2" show="1" is_spotlight="" style_id="0" job_type_id="2" industry_id="2" modified="2007-11-26 14:48:36" created=""><style id="" name="" /><job_type id="2" name="Awareness Campaign" /><industry id="2" name="Education" /></project>';
  87		$this->assertEqual($result, $expected);
  88
  89		$input = array(
  90			'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
  91			'Style' => array('id' => null, 'name' => null),
  92			'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  93			'Industry' => array('id' => 1, 'name' => 'Financial')
  94		);
  95		$expected = '<project id="1" title="" client_id="1" show="1" is_spotlight="" style_id="0" job_type_id="1" industry_id="1" modified="" created=""><style id="" name="" /><job_type id="1" name="Touch Screen Kiosk" /><industry id="1" name="Financial" /></project>';
  96		$xml = new Xml($input);
  97		$result = preg_replace("/\n/",'', $xml->toString(false));
  98		$this->assertEqual($result, $expected);
  99	}
 100/**
 101 * testSimpleArray method
 102 *
 103 * @access public
 104 * @return void
 105 */
 106	function testSimpleArray() {
 107		$xml = new Xml(array('hello' => 'world'), array('format' => 'tags'));
 108
 109		$result = $xml->toString(false);
 110		$expected = '<hello><![CDATA[world]]></hello>';
 111		$this->assertEqual($expected, $result);
 112	}
 113/**
 114 * testSimpleObject method
 115 *
 116 * @access public
 117 * @return void
 118 */
 119	function testSimpleObject() {
 120		$input = new StdClass();
 121		$input->hello = 'world';
 122		$xml = new Xml($input, array('format' => 'tags'));
 123
 124		$result = $xml->toString(false);
 125		$expected = '<hello><![CDATA[world]]></hello>';
 126		$this->assertEqual($expected, $result);
 127	}
 128/**
 129 * testHeader method
 130 *
 131 * @access public
 132 * @return void
 133 */
 134	function testHeader() {
 135		$input = new stdClass();
 136		$input->hello = 'world';
 137		$xml = new Xml($input, array('format' => 'tags'));
 138
 139		$result = $xml->toString(array('header' => true));
 140		$expected = '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'."\n".'<hello><![CDATA[world]]></hello>';
 141		$this->assertEqual($expected, $result);
 142	}
 143/**
 144 * testOwnerAssignment method
 145 *
 146 * @access public
 147 * @return void
 148 */
 149	function testOwnerAssignment() {
 150		$xml = new Xml();
 151		$node =& $xml->createElement('hello', 'world');
 152		$owner =& $node->document();
 153		$this->assertTrue($xml === $owner);
 154
 155		$children =& $node->children;
 156		$childOwner =& $children[0]->document();
 157		$this->assertTrue($xml === $childOwner);
 158	}
 159/**
 160 * testArraySingleSerialization method
 161 *
 162 * @access public
 163 * @return void
 164 */
 165	function testArraySingleSerialization() {
 166		$input = array(
 167			'Post' => array(
 168				'id' => '1', 'author_id' => '1', 'title' => 'First Post',
 169				'body' => 'First Post Body', 'published' => 'Y',
 170				'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
 171			),
 172			'Author' => array(
 173				'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
 174				'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'
 175			)
 176		);
 177
 178		$expected = '<post><id>1</id><author_id>1</author_id><title><![CDATA[First Post]]>';
 179		$expected .= '</title><body><![CDATA[First Post Body]]></body><published><![CDATA[Y]]>';
 180		$expected .= '</published><created><![CDATA[2007-03-18 10:39:23]]></created><updated>';
 181		$expected .= '<![CDATA[2007-03-18 10:41:31]]></updated><author><id>1</id><user>';
 182		$expected .= '<![CDATA[mariano]]></user><password><![CDATA[5f4dcc3b5aa765d61d8327deb882';
 183		$expected .= 'cf99]]></password><created><![CDATA[2007-03-17 01:16:23]]></created>';
 184		$expected .= '<updated><![CDATA[2007-03-17 01:18:31]]></updated><test><![CDATA[working]]>';
 185		$expected .= '</test></author></post>';
 186
 187		$xml = new Xml($input, array('format' => 'tags'));
 188		$result = $xml->toString(false);
 189		$this->assertEqual($expected, $result);
 190	}
 191/**
 192 * testArraySerialization method
 193 *
 194 * @access public
 195 * @return void
 196 */
 197	function testArraySerialization() {
 198		$input = array(
 199			array(
 200				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
 201				'Style' => array('id' => null, 'name' => null),
 202				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 203				'Industry' => array('id' => 1, 'name' => 'Financial')
 204			),
 205			array(
 206				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 207				'Style' => array('id' => null, 'name' => null),
 208				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 209				'Industry' => array('id' => 2, 'name' => 'Education'),
 210			)
 211		);
 212		$expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project>';
 213
 214		$xml = new Xml($input, array('format' => 'tags'));
 215		$result = $xml->toString(array('header' => false, 'cdata' => false));
 216		$this->assertEqual($expected, $result);
 217	}
 218/**
 219 * testNestedArraySerialization method
 220 *
 221 * @access public
 222 * @return void
 223 */
 224	function testNestedArraySerialization() {
 225		$input = array(
 226			array(
 227				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
 228				'Style' => array('id' => null, 'name' => null),
 229				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 230				'Industry' => array('id' => 1, 'name' => 'Financial'),
 231				'BusinessSolution' => array(array('id' => 6, 'name' => 'Convert Sales')),
 232				'MediaType' => array(
 233					array('id' => 15, 'name' => 'Print'),
 234					array('id' => 7, 'name' => 'Web Demo'),
 235					array('id' => 6, 'name' => 'CD-ROM')
 236				)
 237			),
 238			array(
 239				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 240				'Style' => array('id' => null, 'name' => null),
 241				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 242				'Industry' => array('id' => 2, 'name' => 'Education'),
 243				'BusinessSolution' => array(
 244					array('id' => 4, 'name' => 'Build Relationship'),
 245					array('id' => 6, 'name' => 'Convert Sales')
 246				),
 247				'MediaType' => array(
 248					array('id' => 17, 'name' => 'Web'),
 249					array('id' => 6, 'name' => 'CD-ROM')
 250				)
 251			)
 252		);
 253		$expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type><id>15</id><name>Print</name></media_type><media_type><id>7</id><name>Web Demo</name></media_type><media_type><id>6</id><name>CD-ROM</name></media_type></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry><business_solution><id>4</id><name>Build Relationship</name></business_solution><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type><id>17</id><name>Web</name></media_type><media_type><id>6</id><name>CD-ROM</name></media_type></project>';
 254
 255		$xml = new Xml($input, array('format' => 'tags'));
 256		$result = $xml->toString(array('header' => false, 'cdata' => false));
 257		$this->assertEqual($expected, $result);
 258	}
 259/**
 260 * testCloneNode
 261 *
 262 * @access public
 263 * @return void
 264 */
 265	function testCloneNode() {
 266		$node =& new XmlNode('element', 'myValue');
 267		$twin =& $node->cloneNode();
 268		$this->assertEqual($node, $twin);
 269	}
 270/**
 271 * testNextSibling
 272 *
 273 * @access public
 274 * @return void
 275 */
 276	function testNextSibling() {
 277		$input = array(
 278			array(
 279				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => '1', 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => '1.89', 'industry_id' => '1.56', 'modified' => null, 'created' => null),
 280				'Style' => array('id' => null, 'name' => null),
 281				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 282				'Industry' => array('id' => 1, 'name' => 'Financial')
 283			),
 284			array(
 285				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => '1', 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => '2.2', 'industry_id' => 2.2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 286				'Style' => array('id' => null, 'name' => null),
 287				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 288				'Industry' => array('id' => 2, 'name' => 'Education'),
 289			)
 290		);
 291		$xml =& new Xml($input, array('format' => 'tags'));
 292		$node =& $xml->children[0]->children[0];
 293
 294		$nextSibling =& $node->nextSibling();
 295		$this->assertEqual($nextSibling, $xml->children[0]->children[1]);
 296
 297		$nextSibling2 =& $nextSibling->nextSibling();
 298		$this->assertEqual($nextSibling2, $xml->children[0]->children[2]);
 299
 300		$noFriends =& $xml->children[0]->children[12];
 301		$this->assertNull($noFriends->nextSibling());
 302	}
 303/**
 304 * testPreviousSibling
 305 *
 306 * @access public
 307 * @return void
 308 */
 309	function testPreviousSibling() {
 310		$input = array(
 311			array(
 312				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => '1', 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => '1.89', 'industry_id' => '1.56', 'modified' => null, 'created' => null),
 313				'Style' => array('id' => null, 'name' => null),
 314				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 315				'Industry' => array('id' => 1, 'name' => 'Financial')
 316			),
 317			array(
 318				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => '1', 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => '2.2', 'industry_id' => 2.2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 319				'Style' => array('id' => null, 'name' => null),
 320				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 321				'Industry' => array('id' => 2, 'name' => 'Education'),
 322			)
 323		);
 324		$xml =& new Xml($input, array('format' => 'tags'));
 325		$node =& $xml->children[0]->children[1];
 326
 327		$prevSibling =& $node->previousSibling();
 328		$this->assertEqual($prevSibling, $xml->children[0]->children[0]);
 329
 330		$this->assertNull($prevSibling->previousSibling());
 331	}
 332/**
 333 * testAddAndRemoveAttributes
 334 *
 335 * @access public
 336 * @return void
 337 */
 338	function testAddAndRemoveAttributes() {
 339		$node =& new XmlElement('myElement', 'superValue');
 340		$this->assertTrue(empty($node->attributes));
 341
 342		$attrs = array(
 343			'id' => 'test',
 344			'show' => 1,
 345			'is_spotlight' => 1,
 346		);
 347		$node->addAttribute($attrs);
 348		$this->assertEqual($node->attributes, $attrs);
 349
 350		$node =& new XmlElement('myElement', 'superValue');
 351		$node->addAttribute('test', 'value');
 352		$this->assertTrue(isset($node->attributes['test']));
 353
 354		$node =& new XmlElement('myElement', 'superValue');
 355		$obj =& new StdClass();
 356		$obj->class = 'info';
 357		$obj->id = 'primaryInfoBox';
 358		$node->addAttribute($obj);
 359		$expected = array(
 360			'class' => 'info',
 361			'id' => 'primaryInfoBox',
 362		);
 363		$this->assertEqual($node->attributes, $expected);
 364
 365		$result = $node->removeAttribute('class');
 366		$this->assertTrue($result);
 367		$this->assertFalse(isset($node->attributes['class']));
 368
 369		$result = $node->removeAttribute('missing');
 370		$this->assertFalse($result);
 371	}
 372	/* Not implemented yet */
 373	/* function testChildFilter() {
 374	 	$input = array(
 375	 		array(
 376	 			'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
 377	 			'Style' => array('id' => null, 'name' => null),
 378	 			'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 379	 			'Industry' => array('id' => 1, 'name' => 'Financial'),
 380	 			'BusinessSolution' => array(array('id' => 6, 'name' => 'Convert Sales')),
 381	 			'MediaType' => array(
 382	 				array('id' => 15, 'name' => 'Print'),
 383	 				array('id' => 7, 'name' => 'Web Demo'),
 384	 				array('id' => 6, 'name' => 'CD-ROM')
 385	 			)
 386	 		),
 387	 		array(
 388	 			'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 389	 			'Style' => array('id' => null, 'name' => null),
 390	 			'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 391	 			'Industry' => array('id' => 2, 'name' => 'Education'),
 392	 			'BusinessSolution' => array(
 393	 				array('id' => 4, 'name' => 'Build Relationship'),
 394	 				array('id' => 6, 'name' => 'Convert Sales')
 395	 			),
 396	 			'MediaType' => array(
 397	 				array('id' => 17, 'name' => 'Web'),
 398	 				array('id' => 6, 'name' => 'CD-ROM')
 399	 			)
 400	 		)
 401	 	);
 402
 403	 	$xml = new Xml($input, array('format' => 'tags', 'tags' => array(
 404	 		'MediaType'	=> array('value' => 'id', 'children' => false),
 405	 		'JobType'	=> array('children' => array()),
 406	 		'Industry'	=> array('children' => array('name')),
 407	 		'show'		=> false
 408	 	)));
 409
 410	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 411	 	$expected = '<project><id>1</id><title /><client_id>1</client_id><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><name>Financial</name></industry><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type>15</media_type><media_type>7</media_type><media_type>6</media_type></project><project><id>2</id><title /><client_id>2</client_id><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><name>Education</name></industry><business_solution><id>4</id><name>Build Relationship</name></business_solution><business_solution><id>6</id><name>Convert Sales</name></business_solution><media_type>17</media_type><media_type>6</media_type></project>';
 412	 	$this->assertEqual($expected, $result);
 413	} */
 414
 415	/* Broken due to a Set class issue */
 416	/* function testMixedArray() {
 417	 	$input = array('OptionGroup' => array(
 418	 		array('name' => 'OptA', 'id' => 12, 'OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6'),
 419	 		array('name' => 'OptB', 'id' => 12, 'OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
 420	 	));
 421	 	$expected = '<option_group><name>OptA</name><id>12</id><option_group>OptA 1</option_group><option_group>OptA 2</option_group><option_group>OptA 3</option_group><option_group>OptA 4</option_group><option_group>OptA 5</option_group><option_group>OptA 6</option_group></option_group><option_group><name>OptB</name><id>12</id><option_group>OptB 1</option_group><option_group>OptB 2</option_group><option_group>OptB 3</option_group><option_group>OptB 4</option_group><option_group>OptB 5</option_group><option_group>OptB 6</option_group></option_group>';
 422	 	$xml = new Xml($input, array('format' => 'tags'));
 423	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 424	 	$this->assertEqual($expected, $result);
 425	} */
 426
 427	/* function testMixedNestedArray() {
 428	 	$input = array(
 429	 		'OptionA' =>  array(
 430	 			'name' => 'OptA',
 431	 			'id' => 12,
 432	 			'opt' => array('OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6')
 433	 		),
 434	 		'OptionB' 	=> array(
 435	 			'name' => 'OptB',
 436	 			'id' => 12,
 437	 			'opt' => array('OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
 438	 		)
 439	 	);
 440	 	$expected = '<option_a><name>OptA</name><id>12</id><opt>OptA 1</opt><opt>OptA 2</opt><opt>OptA 3</opt><opt>OptA 4</opt><opt>OptA 5</opt><opt>OptA 6</opt></option_a><option_b><name>OptB</name><id>12</id><opt>OptB 1</opt><opt>OptB 2</opt><opt>OptB 3</opt><opt>OptB 4</opt><opt>OptB 5</opt><opt>OptB 6</opt></option_b>';
 441	 	$xml = new Xml($input, array('format' => 'tags'));
 442	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 443	 	$this->assertEqual($expected, $result);
 444	} */
 445
 446	/* function testMixedArrayAttributes() {
 447	 	$input = array('OptionGroup' => array(
 448	 		array(
 449	 			'name' => 'OptA',
 450	 			'id' => 12,
 451	 			array('opt' => 'OptA 1'),
 452	 			array('opt' => 'OptA 2'),
 453	 			array('opt' => 'OptA 3'),
 454	 			array('opt' => 'OptA 4'),
 455	 			array('opt' => 'OptA 5'),
 456	 			array('opt' => 'OptA 6')
 457	 		),
 458	 		array(
 459	 			'name' => 'OptB',
 460	 			'id' => 12,
 461	 			array('opt' => 'OptB 1'),
 462	 			array('opt' => 'OptB 2'),
 463	 			array('opt' => 'OptB 3'),
 464	 			array('opt' => 'OptB 4'),
 465	 			array('opt' => 'OptB 5'),
 466	 			array('opt' => 'OptB 6')
 467	 		)
 468	 	));
 469	 	$expected = '<option_group name="OptA" id="12"><opt>OptA 1</opt><opt>OptA 2</opt><opt>OptA 3</opt><opt>OptA 4</opt><opt>OptA 5</opt><opt>OptA 6</opt></option_group><option_group name="OptB" id="12"><opt>OptB 1</opt><opt>OptB 2</opt><opt>OptB 3</opt><opt>OptB 4</opt><opt>OptB 5</opt><opt>OptB 6</opt></option_group>';
 470
 471	 	$options = array('tags' => array('option_group' => array('attributes' => array('id', 'name'))));
 472	 	$xml = new Xml($input, $options);
 473	 	$result = $xml->toString(false);
 474
 475	 	$this->assertEqual($expected, $result);
 476	} */
 477
 478	 /* Not implemented yet */
 479	 /* function testTagMap() {
 480	 	$input = array(
 481	 		array(
 482	 			'Project' => array('id' => 1, 'title' => null, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
 483	 			'Style' => array('id' => null, 'name' => null),
 484	 			'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 485	 			'Industry' => array('id' => 1, 'name' => 'Financial')
 486	 		),
 487	 		array(
 488	 			'Project' => array('id' => 2, 'title' => null, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 489	 			'Style' => array('id' => null, 'name' => null),
 490	 			'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 491	 			'Industry' => array('id' => 2, 'name' => 'Education'),
 492	 		)
 493	 	);
 494	 	$expected = '<project id="1"><title /><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style id=""><name /></style><jobtype id="1">Touch Screen Kiosk</jobtype><industry id="1"><name>Financial</name></industry></project><project id="2"><title /><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style id=""><name /></style><jobtype id="2">Awareness Campaign</jobtype><industry id="2"><name>Education</name></industry></project>';
 495
 496	 	$xml = new Xml($input, array('tags' => array(
 497	 		'Project'	=> array('attributes' => array('id')),
 498	 		'style'		=> array('attributes' => array('id')),
 499	 		'JobType'	=> array('name' => 'jobtype', 'attributes' => array('id'), 'value' => 'name'),
 500	 		'Industry'	=> array('attributes' => array('id'))
 501	 	)));
 502	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 503	 	$this->assertEqual($expected, $result);
 504	} */
 505/**
 506 * testAllCData method
 507 *
 508 * @access public
 509 * @return void
 510 */
 511	function testAllCData() {
 512		$input = array(
 513			array(
 514				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => '1', 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => '1.89', 'industry_id' => '1.56', 'modified' => null, 'created' => null),
 515				'Style' => array('id' => null, 'name' => null),
 516				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 517				'Industry' => array('id' => 1, 'name' => 'Financial')
 518			),
 519			array(
 520				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => '1', 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => '2.2', 'industry_id' => 2.2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 521				'Style' => array('id' => null, 'name' => null),
 522				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 523				'Industry' => array('id' => 2, 'name' => 'Education'),
 524			)
 525		);
 526		$expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1.89</job_type_id><industry_id>1.56</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name><![CDATA[Touch Screen Kiosk]]></name></job_type><industry><id>1</id><name><![CDATA[Financial]]></name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2.2</job_type_id><industry_id>2.2</industry_id><modified><![CDATA[2007-11-26 14:48:36]]></modified><created /><style><id /><name /></style><job_type><id>2</id><name><![CDATA[Awareness Campaign]]></name></job_type><industry><id>2</id><name><![CDATA[Education]]></name></industry></project>';
 527		$xml = new Xml($input, array('format' => 'tags'));
 528		$result = $xml->toString(array('header' => false, 'cdata' => true));
 529		$this->assertEqual($expected, $result);
 530	}
 531	/* PHP-native Unicode support pending */
 532	/* function testConvertEntities() {
 533	 	$input = array('project' => '&eacute;c&icirc;t');
 534	 	$xml = new Xml($input);
 535
 536	 	$result = $xml->toString(array('header' => false, 'cdata' => false, 'convertEntities' => true));
 537	 	$expected = '<project>&#233;c&#238;t</project>';
 538	 	$this->assertEqual($result, $expected);
 539	} */
 540/**
 541 * testWhitespace method
 542 *
 543 * @access public
 544 * @return void
 545 */
 546	function testWhitespace() {
 547		$input = array(
 548			array(
 549				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
 550				'Style' => array('id' => null, 'name' => null),
 551				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 552				'Industry' => array('id' => 1, 'name' => 'Financial')
 553			),
 554			array(
 555				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 556				'Style' => array('id' => null, 'name' => null),
 557				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 558				'Industry' => array('id' => 2, 'name' => 'Education'),
 559			)
 560		);
 561		$expected = "\n\t<project>\n\t\t<id>\n\t\t\t1\n\t\t</id>\n\t\t<title />\n\t\t<client_id>\n\t\t\t1\n\t\t</client_id>\n\t\t<show>\n\t\t\t1\n\t\t</show>\n\t\t<is_spotlight />\n\t\t<style_id>\n\t\t\t0\n\t\t</style_id>\n\t\t<job_type_id>\n\t\t\t1\n\t\t</job_type_id>\n\t\t<industry_id>\n\t\t\t1\n\t\t</industry_id>\n\t\t<modified />\n\t\t<created />\n\t\t<style>\n\t\t\t<id />\n\t\t\t<name />\n\t\t</style>\n\t\t<job_type>\n\t\t\t<id>\n\t\t\t\t1\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tTouch Screen Kiosk\n\t\t\t</name>\n\t\t</job_type>\n\t\t<industry>\n\t\t\t<id>\n\t\t\t\t1\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tFinancial\n\t\t\t</name>\n\t\t</industry>\n\t</project>\n\t<project>\n\t\t<id>\n\t\t\t2\n\t\t</id>\n\t\t<title />\n\t\t<client_id>\n\t\t\t2\n\t\t</client_id>\n\t\t<show>\n\t\t\t1\n\t\t</show>\n\t\t<is_spotlight />\n\t\t<style_id>\n\t\t\t0\n\t\t</style_id>\n\t\t<job_type_id>\n\t\t\t2\n\t\t</job_type_id>\n\t\t<industry_id>\n\t\t\t2\n\t\t</industry_id>\n\t\t<modified>\n\t\t\t2007-11-26 14:48:36\n\t\t</modified>\n\t\t<created />\n\t\t<style>\n\t\t\t<id />\n\t\t\t<name />\n\t\t</style>\n\t\t<job_type>\n\t\t\t<id>\n\t\t\t\t2\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tAwareness Campaign\n\t\t\t</name>\n\t\t</job_type>\n\t\t<industry>\n\t\t\t<id>\n\t\t\t\t2\n\t\t\t</id>\n\t\t\t<name>\n\t\t\t\tEducation\n\t\t\t</name>\n\t\t</industry>\n\t</project>\n";
 562
 563		$xml = new Xml($input, array('format' => 'tags'));
 564		$result = $xml->toString(array('header' => false, 'cdata' => false, 'whitespace' => true));
 565		$this->assertEqual($expected, $result);
 566	}
 567/**
 568 * testSetSerialization method
 569 *
 570 * @access public
 571 * @return void
 572 */
 573	function testSetSerialization() {
 574		$input = array(
 575			array(
 576				'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
 577				'Style' => array('id' => null, 'name' => null),
 578				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 579				'Industry' => array('id' => 1, 'name' => 'Financial')
 580			),
 581			array(
 582				'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
 583				'Style' => array('id' => null, 'name' => null),
 584				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 585				'Industry' => array('id' => 2, 'name' => 'Education'),
 586			)
 587		);
 588		$expected = '<project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project>';
 589
 590		$xml = new Xml(Set::map($input), array('format' => 'tags'));
 591		$result = $xml->toString(array('header' => false, 'cdata' => false));
 592		$this->assertEqual($expected, $result);
 593	}
 594/**
 595 * testSimpleParsing method
 596 *
 597 * @access public
 598 * @return void
 599 */
 600	function testSimpleParsing() {
 601		$source = '<response><hello><![CDATA[happy world]]></hello><goodbye><![CDATA[cruel world]]></goodbye></response>';
 602		$xml = new Xml($source);
 603		$result = $xml->toString();
 604		$this->assertEqual($source, $result);
 605	}
 606/**
 607 * testMixedParsing method
 608 *
 609 * @access public
 610 * @return void
 611 */
 612	function testMixedParsing() {
 613		$source = '<response><body><hello><![CDATA[happy world]]></hello><![CDATA[in between]]><goodbye><![CDATA[cruel world]]></goodbye></body></response>';
 614		$xml = new Xml($source);
 615		$result = $xml->toString();
 616		$this->assertEqual($source, $result);
 617	}
 618/**
 619 * testComplexParsing method
 620 *
 621 * @access public
 622 * @return void
 623 */
 624	function testComplexParsing() {
 625		$source = '<projects><project><id>1</id><title /><client_id>1</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>1</job_type_id><industry_id>1</industry_id><modified /><created /><style><id /><name /></style><job_type><id>1</id><name>Touch Screen Kiosk</name></job_type><industry><id>1</id><name>Financial</name></industry></project><project><id>2</id><title /><client_id>2</client_id><show>1</show><is_spotlight /><style_id>0</style_id><job_type_id>2</job_type_id><industry_id>2</industry_id><modified>2007-11-26 14:48:36</modified><created /><style><id /><name /></style><job_type><id>2</id><name>Awareness Campaign</name></job_type><industry><id>2</id><name>Education</name></industry></project></projects>';
 626		$xml = new Xml($source);
 627		$result = $xml->toString(array('cdata' => false));
 628		$this->assertEqual($source, $result);
 629	}
 630/**
 631 * testNamespaceParsing method
 632 *
 633 * @access public
 634 * @return void
 635 */
 636	function testNamespaceParsing() {
 637		$source = '<a:container xmlns:a="http://example.com/a" xmlns:b="http://example.com/b" xmlns:c="http://example.com/c" xmlns:d="http://example.com/d" xmlns:e="http://example.com/e"><b:rule test=""><c:result>value</c:result></b:rule><d:rule test=""><e:result>value</e:result></d:rule></a:container>';
 638		$xml = new Xml($source);
 639
 640		$result = $xml->toString(array('cdata' => false));
 641		$this->assertEqual($source, $result);
 642
 643		$children = $xml->children('container');
 644		$this->assertEqual($children[0]->namespace, 'a');
 645
 646		$children = $children[0]->children('rule');
 647		$this->assertEqual($children[0]->namespace, 'b');
 648	}
 649/**
 650 * testNamespaces method
 651 *
 652 * @access public
 653 * @return void
 654 */
 655	function testNamespaces() {
 656		$source = '<a:container xmlns:a="http://example.com/a" xmlns:b="http://example.com/b" xmlns:c="http://example.com/c" xmlns:d="http://example.com/d" xmlns:e="http://example.com/e"><b:rule test=""><c:result>value</c:result></b:rule><d:rule test=""><e:result>value</e:result></d:rule></a:container>';
 657		$xml = new Xml($source);
 658
 659		$expects = '<a:container xmlns:a="http://example.com/a" xmlns:b="http://example.com/b" xmlns:c="http://example.com/c" xmlns:d="http://example.com/d" xmlns:e="http://example.com/e" xmlns:f="http://example.com/f"><b:rule test=""><c:result>value</c:result></b:rule><d:rule test=""><e:result>value</e:result></d:rule></a:container>';
 660
 661		$_xml = XmlManager::getInstance();
 662		$xml->addNamespace('f', 'http://example.com/f');
 663		$result = $xml->toString(array('cdata' => false));
 664		$this->assertEqual($expects, $result);
 665	}
 666/**
 667 * testEscapeCharSerialization method
 668 *
 669 * @access public
 670 * @return void
 671 */
 672	function testEscapeCharSerialization() {
 673		$xml = new Xml(array('text' => 'JavaScript & DHTML'), array('attributes' => false, 'format' => 'attributes'));
 674
 675		$result = $xml->toString(false);
 676		$expected = '<std_class text="JavaScript &amp; DHTML" />';
 677		$this->assertEqual($expected, $result);
 678	}
 679/**
 680 * testCompleteEscapeCharSerialization method
 681 *
 682 * @access public
 683 * @return void
 684 */
 685	function testCompleteEscapeCharSerialization() {
 686		$xml = new Xml(array('text' => '<>&"\''), array('attributes' => false, 'format' => 'attributes'));
 687
 688		$result = $xml->toString(false);
 689		$expected = '<std_class text="&lt;&gt;&amp;&quot;&#039;" />';
 690		$this->assertEqual($expected, $result);
 691	}
 692/**
 693 * testToArray method
 694 *
 695 * @access public
 696 * @return void
 697 */
 698	function testToArray() {
 699		App::import('Set');
 700		$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 701		<rss version="2.0">
 702		<channel>
 703			<title>Cake PHP Google Group</title>
 704			<link>http://groups.google.com/group/cake-php</link>
 705			<description>Search this group before posting anything. There are over 20,000 posts and it&amp;#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
 706			<language>en</language>
 707			<item>
 708				<title>constructng result array when using findall</title>
 709				<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
 710				<description>i&#39;m using cakephp to construct a logical data model array that will be &lt;br&gt; passed to a flex app. I have the following model association: &lt;br&gt; ServiceDay-&amp;gt;(hasMany)ServiceTi me-&amp;gt;(hasMany)ServiceTimePrice. So what &lt;br&gt; the current output from my findall is something like this example: &lt;br&gt; &lt;p&gt;Array( &lt;br&gt; [0] =&amp;gt; Array(</description>
 711				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
 712				<author>bmil...@gmail.com(bpscrugs)</author>
 713				<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
 714			</item>
 715			<item>
 716				<title>Re: share views between actions?</title>
 717				<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
 718				<description>Then perhaps you might do us all a favour and refrain from replying to &lt;br&gt; things you do not understand. That goes especially for asinine comments. &lt;br&gt; Indeed. &lt;br&gt; To sum up: &lt;br&gt; No comment. &lt;br&gt; In my day, a simple &amp;quot;RTFM&amp;quot; would suffice. I&#39;ll keep in mind to ignore any &lt;br&gt; further responses from you. &lt;br&gt; You (and I) were referring to the *online documentation*, not other</description>
 719				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
 720				<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
 721				<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
 722			</item>
 723		</channel>
 724		</rss>';
 725		$xml = new Xml($string);
 726		$result = $xml->toArray();
 727		$expected = array('Rss' => array(
 728			'version' => '2.0',
 729			'Channel' => array(
 730				'title' => 'Cake PHP Google Group',
 731				'link' => 'http://groups.google.com/group/cake-php',
 732				'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
 733				'language' => 'en',
 734				'Item' => array(
 735					array(
 736						'title' => 'constructng result array when using findall',
 737						'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
 738						'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] =&gt; Array(",
 739						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
 740						'author' => 'bmil...@gmail.com(bpscrugs)',
 741						'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
 742					),
 743					array(
 744						'title' => 'Re: share views between actions?',
 745						'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
 746						'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other',
 747						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
 748						'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
 749						'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
 750					)
 751				)
 752			)
 753		));
 754		$this->assertEqual($result, $expected);
 755
 756		$string ='<data><post title="Title of this post" description="cool"/></data>';
 757		$xml = new Xml($string);
 758		$result = $xml->toArray();
 759		$expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));
 760		$this->assertEqual($result, $expected);
 761
 762		$xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');
 763		$result = Set::reverse($xml);
 764		$expected = array(
 765			'Example' => array(
 766				'Item' => array(
 767					'title' => 'An example of a correctly reversed XMLNode',
 768					'Desc' => array(),
 769				)
 770			)
 771		);
 772		$this->assertIdentical($result, $expected);
 773
 774		$xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
 775		$result = $xml->toArray();
 776		$expected = array(
 777			'Example' => array(
 778				'Item' => array(
 779					'attr' => '123',
 780					'Titles' => array(
 781						'Title' => array('title1', 'title2')
 782					)
 783				)
 784			)
 785		);
 786		$this->assertIdentical($result, $expected);
 787
 788		$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
 789		$result = $xml->toArray();
 790		$expected = array(
 791			'Example' => array(
 792				'attr' => 'ex_attr',
 793				'Item' => array(
 794					'attr' => '123',
 795					'titles' => 'list',
 796					'value'  => 'textforitems'
 797				)
 798			)
 799		);
 800		$this->assertIdentical($result, $expected);
 801
 802		$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
 803		$example = $xml->child('example');
 804		$item = $example->child('item');
 805		$result = $item->toArray();
 806
 807		$expected = array(
 808			'attr' => '123',
 809			'titles' => 'list',
 810			'value'  => 'textforitems'
 811		);
 812		$this->assertIdentical($result, $expected);
 813
 814		$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 815		<rss version="2.0">
 816		<channel>
 817			<title>Cake PHP Google Group</title>
 818			<link>http://groups.google.com/group/cake-php</link>
 819			<description>Search this group before posting anything. There are over 20,000 posts and it&amp;#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
 820			<language>en</language>
 821			<item>
 822				<title>constructng result array when using findall</title>
 823				<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
 824				<description>i&#39;m using cakephp to construct a logical data model array that will be &lt;br&gt; passed to a flex app. I have the following model association: &lt;br&gt; ServiceDay-&amp;gt;(hasMany)ServiceTi me-&amp;gt;(hasMany)ServiceTimePrice. So what &lt;br&gt; the current output from my findall is something like this example: &lt;br&gt; &lt;p&gt;Array( &lt;br&gt; [0] =&amp;gt; Array(</description>
 825				<dc:creator>cakephp</dc:creator>
 826				<category><![CDATA[cakephp]]></category>
 827				<category><![CDATA[model]]></category>
 828				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
 829				<author>bmil...@gmail.com(bpscrugs)</author>
 830				<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
 831			</item>
 832			<item>
 833				<title>Re: share views between actions?</title>
 834				<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
 835				<description>Then perhaps you might do us all a favour and refrain from replying to &lt;br&gt; things you do not understand. That goes especially for asinine comments. &lt;br&gt; Indeed. &lt;br&gt; To sum up: &lt;br&gt; No comment. &lt;br&gt; In my day, a simple &amp;quot;RTFM&amp;quot; would suffice. I&#39;ll keep in mind to ignore any &lt;br&gt; further responses from you. &lt;br&gt; You (and I) were referring to the *online documentation*, not other</description>
 836				<dc:creator>cakephp</dc:creator>
 837				<category><![CDATA[cakephp]]></category>
 838				<category><![CDATA[model]]></category>
 839				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
 840				<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
 841				<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
 842			</item>
 843		</channel>
 844		</rss>';
 845
 846		$xml = new Xml($string);
 847		$result = $xml->toArray();
 848
 849		$expected = array('Rss' => array(
 850			'version' => '2.0',
 851			'Channel' => array(
 852				'title' => 'Cake PHP Google Group',
 853				'link' => 'http://groups.google.com/group/cake-php',
 854				'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.',
 855				'language' => 'en',
 856				'Item' => array(
 857					array(
 858						'title' => 'constructng result array when using findall',
 859						'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
 860						'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br><p>Array( <br> [0] =&gt; Array(",
 861						'creator' => 'cakephp',
 862						'Category' => array('cakephp', 'model'),
 863						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
 864						'author' => 'bmil...@gmail.com(bpscrugs)',
 865						'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
 866					),
 867					array(
 868						'title' => 'Re: share views between actions?',
 869						'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
 870						'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other',
 871						'creator' => 'cakephp',
 872						'Category' => array('cakephp', 'model'),
 873						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
 874						'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
 875						'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
 876					)
 877				)
 878			)
 879		));
 880		$this->assertEqual($result, $expected);
 881
 882		$text = "<?xml version='1.0' encoding='utf-8'?>
 883		          <course>
 884		            <comps>
 885		              <comp>1</comp>
 886		              <comp>2</comp>
 887		              <comp>3</comp>
 888		              <comp>4</comp>
 889		            </comps>
 890		          </course>";
 891		$xml = new Xml($text);
 892		$result = $xml->toArray();
 893
 894		$expected = array('Course' => array(
 895			'Comps' => array(
 896				'Comp' => array(
 897					1, 2, 3, 4
 898				)
 899			)
 900		));
 901
 902		$this->assertEqual($result, $expected);
 903
 904		$text = '<?xml version="1.0" encoding="UTF-8"?>
 905		<XRDS xmlns="xri://$xrds">
 906		<XRD xml:id="oauth" xmlns="xri://$XRD*($v*2.0)" version="2.0">
 907			<Type>xri://$xrds*simple</Type>
 908			<Expires>2008-04-13T07:34:58Z</Expires>
 909			<Service>
 910				<Type>http://oauth.net/core/1.0/endpoint/authorize</Type>
 911				<Type>http://oauth.net/core/1.0/parameters/auth-header</Type>
 912				<Type>http://oauth.net/core/1.0/parameters/uri-query</Type>
 913				<URI priority="10">https://ma.gnolia.com/oauth/authorize</URI>
 914				<URI priority="20">http://ma.gnolia.com/oauth/authorize</URI>
 915			</Service>
 916		</XRD>
 917		<XRD xmlns="xri://$XRD*($v*2.0)" version="2.0">
 918			<Type>xri://$xrds*simple</Type>
 919				<Service priority="10">
 920					<Type>http://oauth.net/discovery/1.0</Type>
 921					<URI>#oauth</URI>
 922				</Service>
 923		</XRD>
 924		</XRDS>';
 925
 926		$xml = new Xml($text);
 927		$result = $xml->toArray();
 928
 929		$expected = array('XRDS' => array(
 930			'xmlns' => 'xri://$xrds',
 931			'XRD' => array(
 932				array(
 933					'xml:id' => 'oauth',
 934					'xmlns' => 'xri://$XRD*($v*2.0)',
 935					'version' => '2.0',
 936					'Type' => 'xri://$xrds*simple',
 937					'Expires' => '2008-04-13T07:34:58Z',
 938					'Service' => array(
 939						'Type' => array(
 940							'http://oauth.net/core/1.0/endpoint/authorize',
 941							'http://oauth.net/core/1.0/parameters/auth-header',
 942							'http://oauth.net/core/1.0/parameters/uri-query'
 943						),
 944						'URI' => array(
 945							array(
 946								'value' => 'https://ma.gnolia.com/oauth/authorize',
 947								'priority' => '10',
 948							),
 949							array(
 950								'value' => 'http://ma.gnolia.com/oauth/authorize',
 951								'priority' => '20'
 952							)
 953						)
 954					)
 955				),
 956				array(
 957					'xmlns' => 'xri://$XRD*($v*2.0)',
 958					'version' => '2.0',
 959					'Type' => 'xri://$xrds*simple',
 960					'Service' => array(
 961						'priority' => '10',
 962						'Type' => 'http://oauth.net/discovery/1.0',
 963						'URI' => '#oauth'
 964					)
 965				)
 966			)
 967		));
 968
 969		$this->assertEqual($result, $expected);
 970	}
 971/**
 972 * testAppend method
 973 *
 974 * @access public
 975 * @return void
 976 */
 977	function testAppend() {
 978		$parentNode = new XmlNode('ourParentNode');
 979		$parentNode->append( new XmlNode('ourChildNode'));
 980		$first =& $parentNode->first();
 981		$this->assertEqual($first->name, 'ourChildNode');
 982
 983		$string = 'ourChildNode';
 984		$parentNode = new XmlNode('ourParentNode');
 985		$parentNode->append($string);
 986		$last =& $parentNode->last();
 987		$this->assertEqual($last->name, 'ourChildNode');
 988
 989		$this->expectError();
 990		$parentNode->append($parentNode);
 991	}
 992/**
 993 * testNamespacing method
 994 *
 995 * @access public
 996 * @return void
 997 */
 998	function testNamespacing() {
 999		$node = new Xml('<xml></xml>');
1000		$node->addNamespace('cake', 'http://cakephp.org');
1001		$this->assertEqual($node->toString(), '<xml xmlns:cake="http://cakephp.org" />');
1002
1003		$this->assertTrue($node->removeNamespace('cake'));
1004		$this->assertEqual($node->toString(), '<xml />');
1005
1006
1007		$node = new Xml('<xml xmlns:cake="http://cakephp.org" />');
1008		$this->assertTrue($node->removeNamespace('cake'));
1009		$this->assertEqual($node->toString(), '<xml />');
1010
1011		$node->addNamespace('cake', 'http://cakephp.org');
1012		$this->assertEqual($node->toString(), '<xml xmlns:cake="http://cakephp.org" />');
1013	}
1014/**
1015 * testCamelize method
1016 *
1017 * @access public
1018 * @return void
1019 */
1020	function testCamelize() {
1021		$xmlString = '<methodCall><methodName>examples.getStateName</methodName>' .
1022			'<params><param><value><i4>41</i4></value></param></params></methodCall>';
1023
1024		$Xml = new Xml($xmlString);
1025		$expected = array(
1026			'methodCall' => array(
1027				'methodName' => 'examples.getStateName',
1028					'params' => array(
1029						'param' => array('value' => array('i4' => 41)))));
1030		$this->assertEqual($expected, $Xml->toArray(false));
1031
1032		$Xml = new Xml($xmlString);
1033		$expected = array(
1034			'MethodCall' => array(
1035				'methodName' => 'examples.getStateName',
1036					'Params' => array(
1037						'Param' => array('Value' => array('i4' => 41)))));
1038		$this->assertEqual($expected, $Xml->toArray());
1039	}
1040/**
1041 * testNumericDataHandling method
1042 *
1043 * @access public
1044 * @return void
1045 */
1046	function testNumericDataHandling() {
1047		$data = '<xml><data>012345</data></xml>';
1048
1049		$node = new Xml();
1050		$node->load($data);
1051		$node->parse();
1052
1053		$result = $node->first();
1054		$result = $result->children("data");
1055
1056		

Large files files are truncated, but you can click here to view the full file