PageRenderTime 85ms CodeModel.GetById 3ms app.highlight 72ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://bitbucket.org/enangyusup/vbulletin-cakephp
PHP | 1363 lines | 867 code | 112 blank | 384 comment | 0 complexity | f7cabc055656556e44aa2cf5ea3bdf43 MD5 | raw file

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

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

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