PageRenderTime 90ms CodeModel.GetById 13ms app.highlight 59ms RepoModel.GetById 2ms app.codeStats 1ms

/code/ryzom/tools/server/www/webtt/cake/tests/cases/libs/xml.test.php

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

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