PageRenderTime 69ms CodeModel.GetById 2ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 1ms

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

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