PageRenderTime 62ms CodeModel.GetById 3ms app.highlight 45ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://github.com/mariuz/firetube
PHP | 1584 lines | 1092 code | 92 blank | 400 comment | 2 complexity | e43dcd75fd51221c0d530d13eed637ae MD5 | raw file

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

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

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