PageRenderTime 63ms CodeModel.GetById 19ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://bitbucket.org/unsl/listop
PHP | 1338 lines | 867 code | 80 blank | 391 comment | 0 complexity | d19d39c29c3a37120bee4ef25bd2fabc MD5 | raw file

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

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

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