PageRenderTime 74ms CodeModel.GetById 3ms app.highlight 55ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://bitbucket.org/webpolis/liiv
PHP | 1270 lines | 811 code | 79 blank | 380 comment | 0 complexity | 9bc9970576d470f966a7a694c2d075d0 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/**
 102 * testSerializeOnMultiDimensionalArray method
 103 *
 104 * @access public
 105 * @return void
 106 */
 107	function testSerializeOnMultiDimensionalArray() {
 108		$data = array(
 109			'Statuses' => array(
 110				array('Status' => array('id' => 1)),
 111				array('Status' => array('id' => 2))
 112			)
 113		);
 114		$result =& new Xml($data, array('format' => 'tags'));
 115		$expected = '<statuses><status><id>1</id></status><status><id>2</id></status></statuses>';
 116		$this->assertIdentical($result->toString(), $expected);
 117
 118	}
 119
 120/**
 121 * test serialization of boolean and null values.  false = 0, true = 1, null = ''
 122 *
 123 * @return void
 124 **/
 125	function testSerializationOfBooleanAndBooleanishValues() {
 126		$xml =& new Xml(array('data' => array('example' => false)));
 127		$result = $xml->toString(false);
 128		$expected = '<data example="0" />';
 129		$this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s');
 130
 131		$xml =& new Xml(array('data' => array('example' => true)));
 132		$result = $xml->toString(false);
 133		$expected = '<data example="1" />';
 134		$this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s');
 135
 136		$xml =& new Xml(array('data' => array('example' => null)));
 137		$result = $xml->toString(false);
 138		$expected = '<data example="" />';
 139		$this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s');
 140
 141		$xml =& new Xml(array('data' => array('example' => 0)));
 142		$result = $xml->toString(false);
 143		$expected = '<data example="0" />';
 144		$this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s');
 145
 146		$xml =& new Xml(array('data' => array('example' => 1)));
 147		$result = $xml->toString(false);
 148		$expected = '<data example="1" />';
 149		$this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s');
 150	}
 151/**
 152 * testSimpleArray method
 153 *
 154 * @access public
 155 * @return void
 156 */
 157	function testSimpleArray() {
 158		$xml = new Xml(array('hello' => 'world'), array('format' => 'tags'));
 159
 160		$result = $xml->toString(false);
 161		$expected = '<hello><![CDATA[world]]></hello>';
 162		$this->assertEqual($expected, $result);
 163	}
 164/**
 165 * testSimpleObject method
 166 *
 167 * @access public
 168 * @return void
 169 */
 170	function testSimpleObject() {
 171		$input = new StdClass();
 172		$input->hello = 'world';
 173		$xml = new Xml($input, array('format' => 'tags'));
 174
 175		$result = $xml->toString(false);
 176		$expected = '<hello><![CDATA[world]]></hello>';
 177		$this->assertEqual($expected, $result);
 178	}
 179/**
 180 * testHeader method
 181 *
 182 * @access public
 183 * @return void
 184 */
 185	function testHeader() {
 186		$input = new stdClass();
 187		$input->hello = 'world';
 188		$xml = new Xml($input, array('format' => 'tags'));
 189
 190		$result = $xml->toString(array('header' => true));
 191		$expected = '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'."\n".'<hello><![CDATA[world]]></hello>';
 192		$this->assertEqual($expected, $result);
 193	}
 194/**
 195 * testOwnerAssignment method
 196 *
 197 * @access public
 198 * @return void
 199 */
 200	function testOwnerAssignment() {
 201		$xml = new Xml();
 202		$node =& $xml->createElement('hello', 'world');
 203		$owner =& $node->document();
 204		$this->assertTrue($xml === $owner);
 205
 206		$children =& $node->children;
 207		$childOwner =& $children[0]->document();
 208		$this->assertTrue($xml === $childOwner);
 209	}
 210/**
 211 * testArraySingleSerialization method
 212 *
 213 * @access public
 214 * @return void
 215 */
 216	function testArraySingleSerialization() {
 217		$input = array(
 218			'Post' => array(
 219				'id' => '1', 'author_id' => '1', 'title' => 'First Post',
 220				'body' => 'First Post Body', 'published' => 'Y',
 221				'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
 222			),
 223			'Author' => array(
 224				'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
 225				'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'
 226			)
 227		);
 228
 229		$expected = '<post><id>1</id><author_id>1</author_id><title><![CDATA[First Post]]>';
 230		$expected .= '</title><body><![CDATA[First Post Body]]></body><published><![CDATA[Y]]>';
 231		$expected .= '</published><created><![CDATA[2007-03-18 10:39:23]]></created><updated>';
 232		$expected .= '<![CDATA[2007-03-18 10:41:31]]></updated><author><id>1</id><user>';
 233		$expected .= '<![CDATA[mariano]]></user><password><![CDATA[5f4dcc3b5aa765d61d8327deb882';
 234		$expected .= 'cf99]]></password><created><![CDATA[2007-03-17 01:16:23]]></created>';
 235		$expected .= '<updated><![CDATA[2007-03-17 01:18:31]]></updated><test><![CDATA[working]]>';
 236		$expected .= '</test></author></post>';
 237
 238		$xml = new Xml($input, array('format' => 'tags'));
 239		$result = $xml->toString(false);
 240		$this->assertEqual($expected, $result);
 241	}
 242/**
 243 * testArraySerialization method
 244 *
 245 * @access public
 246 * @return void
 247 */
 248	function testArraySerialization() {
 249		$input = array(
 250			array(
 251				'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),
 252				'Style' => array('id' => null, 'name' => null),
 253				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 254				'Industry' => array('id' => 1, 'name' => 'Financial')
 255			),
 256			array(
 257				'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),
 258				'Style' => array('id' => null, 'name' => null),
 259				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 260				'Industry' => array('id' => 2, 'name' => 'Education'),
 261			)
 262		);
 263		$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>';
 264
 265		$xml = new Xml($input, array('format' => 'tags'));
 266		$result = $xml->toString(array('header' => false, 'cdata' => false));
 267		$this->assertEqual($expected, $result);
 268	}
 269/**
 270 * testNestedArraySerialization method
 271 *
 272 * @access public
 273 * @return void
 274 */
 275	function testNestedArraySerialization() {
 276		$input = array(
 277			array(
 278				'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),
 279				'Style' => array('id' => null, 'name' => null),
 280				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 281				'Industry' => array('id' => 1, 'name' => 'Financial'),
 282				'BusinessSolution' => array(array('id' => 6, 'name' => 'Convert Sales')),
 283				'MediaType' => array(
 284					array('id' => 15, 'name' => 'Print'),
 285					array('id' => 7, 'name' => 'Web Demo'),
 286					array('id' => 6, 'name' => 'CD-ROM')
 287				)
 288			),
 289			array(
 290				'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),
 291				'Style' => array('id' => null, 'name' => null),
 292				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 293				'Industry' => array('id' => 2, 'name' => 'Education'),
 294				'BusinessSolution' => array(
 295					array('id' => 4, 'name' => 'Build Relationship'),
 296					array('id' => 6, 'name' => 'Convert Sales')
 297				),
 298				'MediaType' => array(
 299					array('id' => 17, 'name' => 'Web'),
 300					array('id' => 6, 'name' => 'CD-ROM')
 301				)
 302			)
 303		);
 304		$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>';
 305
 306		$xml = new Xml($input, array('format' => 'tags'));
 307		$result = $xml->toString(array('header' => false, 'cdata' => false));
 308		$this->assertEqual($expected, $result);
 309	}
 310/**
 311 * Prove that serialization with a given root node works
 312 * as expected.
 313 *
 314 * @access public
 315 * @return void
 316 * @link   https://trac.cakephp.org/ticket/6294
 317 */
 318	function testArraySerializationWithRoot() {
 319		$input = array(
 320					array('Shirt' => array('id' => 1, 'color' => 'green')),
 321					array('Shirt' => array('id' => 2, 'color' => 'blue')),
 322					);
 323		$expected = '<collection><shirt id="1" color="green" />';
 324		$expected .= '<shirt id="2" color="blue" /></collection>';
 325
 326		$Xml = new Xml($input, array('root' => 'collection'));
 327		$result = $Xml->toString(array('header' => false));
 328		$this->assertEqual($expected, $result);
 329	}
 330/**
 331 * testCloneNode
 332 *
 333 * @access public
 334 * @return void
 335 */
 336	function testCloneNode() {
 337		$node =& new XmlNode('element', 'myValue');
 338		$twin =& $node->cloneNode();
 339		$this->assertEqual($node, $twin);
 340	}
 341/**
 342 * testNextSibling
 343 *
 344 * @access public
 345 * @return void
 346 */
 347	function testNextSibling() {
 348		$input = array(
 349			array(
 350				'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),
 351				'Style' => array('id' => null, 'name' => null),
 352				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 353				'Industry' => array('id' => 1, 'name' => 'Financial')
 354			),
 355			array(
 356				'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),
 357				'Style' => array('id' => null, 'name' => null),
 358				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 359				'Industry' => array('id' => 2, 'name' => 'Education'),
 360			)
 361		);
 362		$xml =& new Xml($input, array('format' => 'tags'));
 363		$node =& $xml->children[0]->children[0];
 364
 365		$nextSibling =& $node->nextSibling();
 366		$this->assertEqual($nextSibling, $xml->children[0]->children[1]);
 367
 368		$nextSibling2 =& $nextSibling->nextSibling();
 369		$this->assertEqual($nextSibling2, $xml->children[0]->children[2]);
 370
 371		$noFriends =& $xml->children[0]->children[12];
 372		$this->assertNull($noFriends->nextSibling());
 373	}
 374/**
 375 * testPreviousSibling
 376 *
 377 * @access public
 378 * @return void
 379 */
 380	function testPreviousSibling() {
 381		$input = array(
 382			array(
 383				'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),
 384				'Style' => array('id' => null, 'name' => null),
 385				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 386				'Industry' => array('id' => 1, 'name' => 'Financial')
 387			),
 388			array(
 389				'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),
 390				'Style' => array('id' => null, 'name' => null),
 391				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 392				'Industry' => array('id' => 2, 'name' => 'Education'),
 393			)
 394		);
 395		$xml =& new Xml($input, array('format' => 'tags'));
 396		$node =& $xml->children[0]->children[1];
 397
 398		$prevSibling =& $node->previousSibling();
 399		$this->assertEqual($prevSibling, $xml->children[0]->children[0]);
 400
 401		$this->assertNull($prevSibling->previousSibling());
 402	}
 403/**
 404 * testAddAndRemoveAttributes
 405 *
 406 * @access public
 407 * @return void
 408 */
 409	function testAddAndRemoveAttributes() {
 410		$node =& new XmlElement('myElement', 'superValue');
 411		$this->assertTrue(empty($node->attributes));
 412
 413		$attrs = array(
 414			'id' => 'test',
 415			'show' => 1,
 416			'is_spotlight' => 1,
 417		);
 418		$node->addAttribute($attrs);
 419		$this->assertEqual($node->attributes, $attrs);
 420
 421		$node =& new XmlElement('myElement', 'superValue');
 422		$node->addAttribute('test', 'value');
 423		$this->assertTrue(isset($node->attributes['test']));
 424
 425		$node =& new XmlElement('myElement', 'superValue');
 426		$obj =& new StdClass();
 427		$obj->class = 'info';
 428		$obj->id = 'primaryInfoBox';
 429		$node->addAttribute($obj);
 430		$expected = array(
 431			'class' => 'info',
 432			'id' => 'primaryInfoBox',
 433		);
 434		$this->assertEqual($node->attributes, $expected);
 435
 436		$result = $node->removeAttribute('class');
 437		$this->assertTrue($result);
 438		$this->assertFalse(isset($node->attributes['class']));
 439
 440		$result = $node->removeAttribute('missing');
 441		$this->assertFalse($result);
 442	}
 443
 444	/**
 445	 * Tests that XML documents with non-standard spacing (i.e. leading whitespace, whole document
 446	 * on one line) still parse properly.
 447	 *
 448	 * @return void
 449	 */
 450	function testParsingWithNonStandardWhitespace() {
 451		$raw = '<?xml version="1.0" encoding="ISO-8859-1" ?><prices><price>1.0</price></prices>';
 452		$array = array('Prices' => array('price' => 1.0));
 453
 454		$xml = new Xml($raw);
 455		$this->assertEqual($xml->toArray(), $array);
 456		$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
 457
 458		$xml = new Xml(' ' . $raw);
 459		$this->assertEqual($xml->toArray(), $array);
 460		$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
 461
 462		$xml = new Xml("\n" . $raw);
 463		$this->assertEqual($xml->toArray(), $array);
 464		$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
 465	}
 466
 467	/* Not implemented yet */
 468	/* function testChildFilter() {
 469	 	$input = array(
 470	 		array(
 471	 			'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),
 472	 			'Style' => array('id' => null, 'name' => null),
 473	 			'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 474	 			'Industry' => array('id' => 1, 'name' => 'Financial'),
 475	 			'BusinessSolution' => array(array('id' => 6, 'name' => 'Convert Sales')),
 476	 			'MediaType' => array(
 477	 				array('id' => 15, 'name' => 'Print'),
 478	 				array('id' => 7, 'name' => 'Web Demo'),
 479	 				array('id' => 6, 'name' => 'CD-ROM')
 480	 			)
 481	 		),
 482	 		array(
 483	 			'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),
 484	 			'Style' => array('id' => null, 'name' => null),
 485	 			'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 486	 			'Industry' => array('id' => 2, 'name' => 'Education'),
 487	 			'BusinessSolution' => array(
 488	 				array('id' => 4, 'name' => 'Build Relationship'),
 489	 				array('id' => 6, 'name' => 'Convert Sales')
 490	 			),
 491	 			'MediaType' => array(
 492	 				array('id' => 17, 'name' => 'Web'),
 493	 				array('id' => 6, 'name' => 'CD-ROM')
 494	 			)
 495	 		)
 496	 	);
 497
 498	 	$xml = new Xml($input, array('format' => 'tags', 'tags' => array(
 499	 		'MediaType'	=> array('value' => 'id', 'children' => false),
 500	 		'JobType'	=> array('children' => array()),
 501	 		'Industry'	=> array('children' => array('name')),
 502	 		'show'		=> false
 503	 	)));
 504
 505	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 506	 	$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>';
 507	 	$this->assertEqual($expected, $result);
 508	} */
 509
 510	/* Broken due to a Set class issue */
 511	/* function testMixedArray() {
 512	 	$input = array('OptionGroup' => array(
 513	 		array('name' => 'OptA', 'id' => 12, 'OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6'),
 514	 		array('name' => 'OptB', 'id' => 12, 'OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
 515	 	));
 516	 	$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>';
 517	 	$xml = new Xml($input, array('format' => 'tags'));
 518	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 519	 	$this->assertEqual($expected, $result);
 520	} */
 521
 522	/* function testMixedNestedArray() {
 523	 	$input = array(
 524	 		'OptionA' =>  array(
 525	 			'name' => 'OptA',
 526	 			'id' => 12,
 527	 			'opt' => array('OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6')
 528	 		),
 529	 		'OptionB' 	=> array(
 530	 			'name' => 'OptB',
 531	 			'id' => 12,
 532	 			'opt' => array('OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
 533	 		)
 534	 	);
 535	 	$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>';
 536	 	$xml = new Xml($input, array('format' => 'tags'));
 537	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 538	 	$this->assertEqual($expected, $result);
 539	} */
 540
 541	/* function testMixedArrayAttributes() {
 542	 	$input = array('OptionGroup' => array(
 543	 		array(
 544	 			'name' => 'OptA',
 545	 			'id' => 12,
 546	 			array('opt' => 'OptA 1'),
 547	 			array('opt' => 'OptA 2'),
 548	 			array('opt' => 'OptA 3'),
 549	 			array('opt' => 'OptA 4'),
 550	 			array('opt' => 'OptA 5'),
 551	 			array('opt' => 'OptA 6')
 552	 		),
 553	 		array(
 554	 			'name' => 'OptB',
 555	 			'id' => 12,
 556	 			array('opt' => 'OptB 1'),
 557	 			array('opt' => 'OptB 2'),
 558	 			array('opt' => 'OptB 3'),
 559	 			array('opt' => 'OptB 4'),
 560	 			array('opt' => 'OptB 5'),
 561	 			array('opt' => 'OptB 6')
 562	 		)
 563	 	));
 564	 	$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>';
 565
 566	 	$options = array('tags' => array('option_group' => array('attributes' => array('id', 'name'))));
 567	 	$xml = new Xml($input, $options);
 568	 	$result = $xml->toString(false);
 569
 570	 	$this->assertEqual($expected, $result);
 571	} */
 572
 573	 /* Not implemented yet */
 574	 /* function testTagMap() {
 575	 	$input = array(
 576	 		array(
 577	 			'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),
 578	 			'Style' => array('id' => null, 'name' => null),
 579	 			'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 580	 			'Industry' => array('id' => 1, 'name' => 'Financial')
 581	 		),
 582	 		array(
 583	 			'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),
 584	 			'Style' => array('id' => null, 'name' => null),
 585	 			'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 586	 			'Industry' => array('id' => 2, 'name' => 'Education'),
 587	 		)
 588	 	);
 589	 	$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>';
 590
 591	 	$xml = new Xml($input, array('tags' => array(
 592	 		'Project'	=> array('attributes' => array('id')),
 593	 		'style'		=> array('attributes' => array('id')),
 594	 		'JobType'	=> array('name' => 'jobtype', 'attributes' => array('id'), 'value' => 'name'),
 595	 		'Industry'	=> array('attributes' => array('id'))
 596	 	)));
 597	 	$result = $xml->toString(array('header' => false, 'cdata' => false));
 598	 	$this->assertEqual($expected, $result);
 599	} */
 600/**
 601 * testAllCData method
 602 *
 603 * @access public
 604 * @return void
 605 */
 606	function testAllCData() {
 607		$input = array(
 608			array(
 609				'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),
 610				'Style' => array('id' => null, 'name' => null),
 611				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 612				'Industry' => array('id' => 1, 'name' => 'Financial')
 613			),
 614			array(
 615				'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),
 616				'Style' => array('id' => null, 'name' => null),
 617				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 618				'Industry' => array('id' => 2, 'name' => 'Education'),
 619			)
 620		);
 621		$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>';
 622		$xml = new Xml($input, array('format' => 'tags'));
 623		$result = $xml->toString(array('header' => false, 'cdata' => true));
 624		$this->assertEqual($expected, $result);
 625	}
 626	/* PHP-native Unicode support pending */
 627	/* function testConvertEntities() {
 628	 	$input = array('project' => '&eacute;c&icirc;t');
 629	 	$xml = new Xml($input);
 630
 631	 	$result = $xml->toString(array('header' => false, 'cdata' => false, 'convertEntities' => true));
 632	 	$expected = '<project>&#233;c&#238;t</project>';
 633	 	$this->assertEqual($result, $expected);
 634	} */
 635/**
 636 * testWhitespace method
 637 *
 638 * @access public
 639 * @return void
 640 */
 641	function testWhitespace() {
 642		$input = array(
 643			array(
 644				'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),
 645				'Style' => array('id' => null, 'name' => null),
 646				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 647				'Industry' => array('id' => 1, 'name' => 'Financial')
 648			),
 649			array(
 650				'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),
 651				'Style' => array('id' => null, 'name' => null),
 652				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 653				'Industry' => array('id' => 2, 'name' => 'Education'),
 654			)
 655		);
 656		$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";
 657
 658		$xml = new Xml($input, array('format' => 'tags'));
 659		$result = $xml->toString(array('header' => false, 'cdata' => false, 'whitespace' => true));
 660		$this->assertEqual($expected, $result);
 661	}
 662/**
 663 * testSetSerialization method
 664 *
 665 * @access public
 666 * @return void
 667 */
 668	function testSetSerialization() {
 669		$input = array(
 670			array(
 671				'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),
 672				'Style' => array('id' => null, 'name' => null),
 673				'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
 674				'Industry' => array('id' => 1, 'name' => 'Financial')
 675			),
 676			array(
 677				'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),
 678				'Style' => array('id' => null, 'name' => null),
 679				'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
 680				'Industry' => array('id' => 2, 'name' => 'Education'),
 681			)
 682		);
 683		$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>';
 684
 685		$xml = new Xml(Set::map($input), array('format' => 'tags'));
 686		$result = $xml->toString(array('header' => false, 'cdata' => false));
 687		$this->assertEqual($expected, $result);
 688	}
 689/**
 690 * testSimpleParsing method
 691 *
 692 * @access public
 693 * @return void
 694 */
 695	function testSimpleParsing() {
 696		$source = '<response><hello><![CDATA[happy world]]></hello><goodbye><![CDATA[cruel world]]></goodbye></response>';
 697		$xml = new Xml($source);
 698		$result = $xml->toString();
 699		$this->assertEqual($source, $result);
 700	}
 701/**
 702 * test that elements with empty tag values do not collapse and corrupt data structures
 703 *
 704 * @access public
 705 * @return void
 706 **/
 707	function testElementCollapsing() {
 708		$xmlDataThatFails = '<resultpackage>
 709		<result qid="46b1c46ed6208"><![CDATA[46b1c46ed3af9]]></result>
 710		<result qid="46b1c46ed332a"><![CDATA[]]></result>
 711		<result qid="46b1c46ed90e6"><![CDATA[46b1c46ed69d8]]></result>
 712		<result qid="46b1c46ed71a7"><![CDATA[46b1c46ed5a38]]></result>
 713		<result qid="46b1c46ed8146"><![CDATA[46b1c46ed98b6]]></result>
 714		<result qid="46b1c46ed7978"><![CDATA[]]></result>
 715		<result qid="46b1c46ed4a98"><![CDATA[]]></result>
 716		<result qid="46b1c46ed42c8"><![CDATA[]]></result>
 717		<result qid="46b1c46ed5268"><![CDATA[46b1c46ed8917]]></result>
 718		</resultpackage>';
 719
 720		$Xml = new Xml();
 721		$Xml->load('<?xml version="1.0" encoding="UTF-8" ?>' . $xmlDataThatFails);
 722		$result = $Xml->toArray(false);
 723
 724		$this->assertTrue(is_array($result));
 725		$expected = array(
 726			'resultpackage' => array(
 727				'result' => array(
 728					0 => array(
 729						'value' => '46b1c46ed3af9',
 730						'qid' => '46b1c46ed6208'),
 731					1 => array(
 732						'qid' => '46b1c46ed332a'),
 733					2 => array(
 734						'value' => '46b1c46ed69d8',
 735						'qid' => '46b1c46ed90e6'),
 736					3 => array(
 737						'value' => '46b1c46ed5a38',
 738						'qid' => '46b1c46ed71a7'),
 739					4 => array(
 740						'value' => '46b1c46ed98b6',
 741						'qid' => '46b1c46ed8146'),
 742					5 => array(
 743						'qid' => '46b1c46ed7978'),
 744					6 => array(
 745						'qid' => '46b1c46ed4a98'),
 746					7 => array(
 747						'qid' => '46b1c46ed42c8'),
 748					8 => array(
 749						'value' => '46b1c46ed8917',
 750						'qid' => '46b1c46ed5268'),
 751				)
 752		));
 753		$this->assertEqual(
 754			count($result['resultpackage']['result']), count($expected['resultpackage']['result']),
 755			'Incorrect array length %s');
 756
 757		$this->assertFalse(
 758			isset($result['resultpackage']['result'][0][0]['qid']), 'Nested array exists, data is corrupt. %s');
 759
 760		$this->assertEqual($result, $expected);
 761	}
 762/**
 763 * test that empty values do not casefold collapse
 764 * 
 765 * @see http://code.cakephp.org/tickets/view/8
 766 * @return void
 767 **/
 768	function testCaseFoldingWithEmptyValues() {
 769		$filledValue = '<method name="set_user_settings">
 770			<title>update user information</title>
 771			<user>1</user>
 772			<User>
 773				<id>1</id>
 774				<name>varchar(45)</name>
 775			</User>
 776		</method>';
 777		$xml =& new XML($filledValue);
 778		$expected = array(
 779			'Method' => array(
 780				'name' => 'set_user_settings',
 781				'title' => 'update user information',
 782				'user' => '1',
 783				'User' => array(
 784					'id' => 1,
 785					'name' => 'varchar(45)',
 786				),
 787			)
 788		);
 789		$result = $xml->toArray();
 790		$this->assertEqual($result, $expected);
 791
 792		$emptyValue ='<method name="set_user_settings">
 793			<title>update user information</title>
 794			<user></user>
 795			<User>
 796				<id>1</id>
 797				<name>varchar(45)</name>
 798			</User>
 799		</method>';
 800		
 801		$xml =& new XML($emptyValue);
 802		$expected = array(
 803			'Method' => array(
 804				'name' => 'set_user_settings',
 805				'title' => 'update user information',
 806				'user' => array(),
 807				'User' => array(
 808					'id' => 1,
 809					'name' => 'varchar(45)',
 810				),
 811			)
 812		);
 813		$result = $xml->toArray();
 814		$this->assertEqual($result, $expected);
 815	}
 816/**
 817 * testMixedParsing method
 818 *
 819 * @access public
 820 * @return void
 821 */
 822	function testMixedParsing() {
 823		$source = '<response><body><hello><![CDATA[happy world]]></hello><![CDATA[in between]]><goodbye><![CDATA[cruel world]]></goodbye></body></response>';
 824		$xml = new Xml($source);
 825		$result = $xml->toString();
 826		$this->assertEqual($source, $result);
 827	}
 828/**
 829 * testComplexParsing method
 830 *
 831 * @access public
 832 * @return void
 833 */
 834	function testComplexParsing() {
 835		$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>';
 836		$xml = new Xml($source);
 837		$result = $xml->toString(array('cdata' => false));
 838		$this->assertEqual($source, $result);
 839	}
 840/**
 841 * testNamespaceParsing method
 842 *
 843 * @access public
 844 * @return void
 845 */
 846	function testNamespaceParsing() {
 847		$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>';
 848		$xml = new Xml($source);
 849
 850		$result = $xml->toString(array('cdata' => false));
 851		$this->assertEqual($source, $result);
 852
 853		$children = $xml->children('container');
 854		$this->assertEqual($children[0]->namespace, 'a');
 855
 856		$children = $children[0]->children('rule');
 857		$this->assertEqual($children[0]->namespace, 'b');
 858	}
 859/**
 860 * testNamespaces method
 861 *
 862 * @access public
 863 * @return void
 864 */
 865	function testNamespaces() {
 866		$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>';
 867		$xml = new Xml($source);
 868
 869		$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>';
 870
 871		$_xml = XmlManager::getInstance();
 872		$xml->addNamespace('f', 'http://example.com/f');
 873		$result = $xml->toString(array('cdata' => false));
 874		$this->assertEqual($expects, $result);
 875	}
 876/**
 877 * testEscapeCharSerialization method
 878 *
 879 * @access public
 880 * @return void
 881 */
 882	function testEscapeCharSerialization() {
 883		$xml = new Xml(array('text' => 'JavaScript & DHTML'), array('attributes' => false, 'format' => 'attributes'));
 884
 885		$result = $xml->toString(false);
 886		$expected = '<std_class text="JavaScript &amp; DHTML" />';
 887		$this->assertEqual($expected, $result);
 888	}
 889/**
 890 * testCompleteEscapeCharSerialization method
 891 *
 892 * @access public
 893 * @return void
 894 */
 895	function testCompleteEscapeCharSerialization() {
 896		$xml = new Xml(array('text' => '<>&"\''), array('attributes' => false, 'format' => 'attributes'));
 897
 898		$result = $xml->toString(false);
 899		$expected = '<std_class text="&lt;&gt;&amp;&quot;&#039;" />';
 900		$this->assertEqual($expected, $result);
 901	}
 902/**
 903 * testToArray method
 904 *
 905 * @access public
 906 * @return void
 907 */
 908	function testToArray() {
 909		App::import('Set');
 910		$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 911		<rss version="2.0">
 912		<channel>
 913			<title>Cake PHP Google Group</title>
 914			<link>http://groups.google.com/group/cake-php</link>
 915			<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>
 916			<language>en</language>
 917			<item>
 918				<title>constructng result array when using findall</title>
 919				<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
 920				<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>
 921				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
 922				<author>bmil...@gmail.com(bpscrugs)</author>
 923				<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
 924			</item>
 925			<item>
 926				<title>Re: share views between actions?</title>
 927				<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
 928				<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>
 929				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
 930				<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
 931				<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
 932			</item>
 933		</channel>
 934		</rss>';
 935		$xml = new Xml($string);
 936		$result = $xml->toArray();
 937		$expected = array('Rss' => array(
 938			'version' => '2.0',
 939			'Channel' => array(
 940				'title' => 'Cake PHP Google Group',
 941				'link' => 'http://groups.google.com/group/cake-php',
 942				'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.',
 943				'language' => 'en',
 944				'Item' => array(
 945					array(
 946						'title' => 'constructng result array when using findall',
 947						'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
 948						'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(",
 949						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
 950						'author' => 'bmil...@gmail.com(bpscrugs)',
 951						'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
 952					),
 953					array(
 954						'title' => 'Re: share views between actions?',
 955						'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
 956						'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',
 957						'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
 958						'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
 959						'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
 960					)
 961				)
 962			)
 963		));
 964		$this->assertEqual($result, $expected);
 965
 966		$string ='<data><post title="Title of this post" description="cool"/></data>';
 967		$xml = new Xml($string);
 968		$result = $xml->toArray();
 969		$expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));
 970		$this->assertEqual($result, $expected);
 971
 972		$xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');
 973		$result = Set::reverse($xml);
 974		$expected = array(
 975			'Example' => array(
 976				'Item' => array(
 977					'title' => 'An example of a correctly reversed XMLNode',
 978					'desc' => array(),
 979				)
 980			)
 981		);
 982		$this->assertIdentical($result, $expected);
 983
 984		$xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
 985		$result = $xml->toArray();
 986		$expected = array(
 987			'Example' => array(
 988				'Item' => array(
 989					'attr' => '123',
 990					'Titles' => array(
 991						'Title' => array('title1', 'title2')
 992					)
 993				)
 994			)
 995		);
 996		$this->assertIdentical($result, $expected);
 997
 998		$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
 999		$result = $xml->toArray();
1000		$expected = array(
1001			'Example' => array(
1002				'attr' => 'ex_attr',
1003				'Item' => array(
1004					'attr' => '123',
1005					'titles' => 'list',
1006					'value'  => 'textforitems'
1007				)
1008			)
1009		);
1010		$this->assertIdentical($result, $expected);
1011
1012		$xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
1013		$example = $xml->child('example');
1014		$item = $example->child('item');
1015		$result = $item->toArray();
1016
1017		$expected = array(
1018			'attr' => '123',
1019			'titles' => 'list',
1020			'value'  => 'textforitems'
1021		);
1022		$this->assertIdentical($result, $expected);
1023
1024		$string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1025		<rss version="2.0">
1026		<channel>
1027			<title>Cake PHP Google Group</title>
1028			<link>http://groups.google.com/group/cake-php</link>
1029			<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>
1030			<language>en</language>
1031			<item>
1032				<title>constructng result array when using findall</title>
1033				<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
1034				<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>
1035				<dc:creator>cakephp</dc:creator>
1036				<category><![CDATA[cakephp]]></category>
1037				<category><![CDATA[model]]></category>
1038				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
1039				<author>bmil...@gmail.com(bpscrugs)</author>
1040				<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
1041			</item>
1042			<item>
1043				<title>Re: share views between actions?</title>
1044				<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
1045				<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>
1046				<dc:creator>cakephp</dc:creator>
1047				<category><![CDATA[cakephp]]></category>
1048				<category><![CDATA[model]]></category>
1049				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
1050				<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
1051				<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
1052			</item>
1053		</channel>
1054		</rss>';
1055
1056		$xml = new Xml($string);
1057		$result = $xml->toArray();
1058
1059		$expected = array('Rss' => array(
1060			'version' => '2.0',
1061			'Channel' => array(
1062				'title' => 'Cake PHP Google Group',
1063				'link' => 'http://groups.google.com/group/cake-php',
1064				'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.',
1065				'language' => 'en',
1066				'Item' => array(
1067					array(
1068						'title' => '

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