PageRenderTime 98ms CodeModel.GetById 60ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

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