PageRenderTime 9ms CodeModel.GetById 9ms app.highlight 52ms RepoModel.GetById 3ms app.codeStats 1ms

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

https://github.com/Dieterbe/cake
PHP | 1048 lines | 657 code | 70 blank | 321 comment | 0 complexity | 83e6a5d509a5b9a3cd124575c07f4c2b MD5 | raw file

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

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

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