PageRenderTime 8ms CodeModel.GetById 3ms app.highlight 58ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://github.com/msadouni/cakephp2x
PHP | 1349 lines | 852 code | 111 blank | 386 comment | 0 complexity | 4ef52f67ade66133d0b09badf6a27a8e MD5 | raw file

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

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

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