PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://goldcat.googlecode.com/
PHP | 1249 lines | 765 code | 110 blank | 374 comment | 0 complexity | 2e6f0c94120dc87e93e696c56d267b9e MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, BSD-3-Clause

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

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

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