PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/felixge/raleigh-workshop-08
PHP | 902 lines | 530 code | 55 blank | 317 comment | 0 complexity | 808f49f0724b4867917fc99fc8159cfa MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* SVN FILE: $Id: xml.test.php 7514 2008-08-26 23:15:48Z mark_story $ */
  3. /**
  4. * Short description for 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.
  12. * 1785 E. Sahara Avenue, Suite 490-204
  13. * Las Vegas, Nevada 89104
  14. *
  15. * Licensed under The Open Group Test Suite License
  16. * Redistributions of files must retain the above copyright notice.
  17. *
  18. * @filesource
  19. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
  20. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  21. * @package cake.tests
  22. * @subpackage cake.tests.cases.libs
  23. * @since CakePHP(tm) v 1.2.0.5432
  24. * @version $Revision: 7514 $
  25. * @modifiedby $LastChangedBy: mark_story $
  26. * @lastmodified $Date: 2008-08-27 01:15:48 +0200 (Mi, 27 Aug 2008) $
  27. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  28. */
  29. App::import('Core', 'Xml');
  30. /**
  31. * Short description for class.
  32. *
  33. * @package cake.tests
  34. * @subpackage cake.tests.cases.libs
  35. */
  36. class XmlTest extends CakeTestCase {
  37. function setUp() {
  38. $manager =& new XmlManager();
  39. $manager->namespaces = array();
  40. }
  41. function KgetTests() {
  42. return array('testRootTagParsing');
  43. }
  44. /**
  45. * testRootTagParsing method
  46. *
  47. * @access public
  48. * @return void
  49. */
  50. function testRootTagParsing() {
  51. $input = '<' . '?xml version="1.0" encoding="UTF-8" ?' . '>' . "\n" .
  52. '<plugin id="1" version_id="1" name="my_plugin" title="My Plugin" author="Me" author_email="me@cakephp.org" description="My awesome package" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13">'
  53. .'<current id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13" />'
  54. .'<version id="1" plugin_id="1" name="1.0" file="" created="2008-01-28 18:21:13" updated="2008-01-28 18:21:13" />'
  55. .'</plugin>';
  56. $xml = new Xml($input);
  57. $this->assertEqual($xml->children[0]->name, 'plugin');
  58. $this->assertEqual($xml->children[0]->children[0]->name, 'current');
  59. $this->assertEqual($xml->toString(true), $input);
  60. }
  61. /**
  62. * testSerialization method
  63. *
  64. * @access public
  65. * @return void
  66. */
  67. function testSerialization() {
  68. $input = array(
  69. array(
  70. 'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
  71. 'Style' => array('id' => null, 'name' => null),
  72. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  73. 'Industry' => array('id' => 1, 'name' => 'Financial')
  74. ),
  75. array(
  76. 'Project' => array('id' => 2, 'title' => null, 'client_id' => 2, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 2, 'industry_id' => 2, 'modified' => '2007-11-26 14:48:36', 'created' => null),
  77. 'Style' => array('id' => null, 'name' => null),
  78. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  79. 'Industry' => array('id' => 2, 'name' => 'Education')
  80. )
  81. );
  82. $xml = new Xml($input);
  83. $result = preg_replace("/\n/",'', $xml->toString(false));
  84. $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>';
  85. $this->assertEqual($result, $expected);
  86. $input = array(
  87. 'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
  88. 'Style' => array('id' => null, 'name' => null),
  89. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  90. 'Industry' => array('id' => 1, 'name' => 'Financial')
  91. );
  92. $expected = '<project id="1" title="" client_id="1" show="1" is_spotlight="" style_id="0" job_type_id="1" industry_id="1" modified="" created=""><style id="" name="" /><job_type id="1" name="Touch Screen Kiosk" /><industry id="1" name="Financial" /></project>';
  93. $xml = new Xml($input);
  94. $result = preg_replace("/\n/",'', $xml->toString(false));
  95. $this->assertEqual($result, $expected);
  96. }
  97. /**
  98. * testSimpleArray method
  99. *
  100. * @access public
  101. * @return void
  102. */
  103. function testSimpleArray() {
  104. $xml = new Xml(array('hello' => 'world'), array('format' => 'tags'));
  105. $result = $xml->toString(false);
  106. $expected = '<hello><![CDATA[world]]></hello>';
  107. $this->assertEqual($expected, $result);
  108. }
  109. /**
  110. * testSimpleObject method
  111. *
  112. * @access public
  113. * @return void
  114. */
  115. function testSimpleObject() {
  116. $input = new StdClass();
  117. $input->hello = 'world';
  118. $xml = new Xml($input, array('format' => 'tags'));
  119. $result = $xml->toString(false);
  120. $expected = '<hello><![CDATA[world]]></hello>';
  121. $this->assertEqual($expected, $result);
  122. }
  123. /**
  124. * testHeader method
  125. *
  126. * @access public
  127. * @return void
  128. */
  129. function testHeader() {
  130. $input = new stdClass();
  131. $input->hello = 'world';
  132. $xml = new Xml($input, array('format' => 'tags'));
  133. $result = $xml->toString(array('header' => true));
  134. $expected = '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'."\n".'<hello><![CDATA[world]]></hello>';
  135. $this->assertEqual($expected, $result);
  136. }
  137. /**
  138. * testOwnerAssignment method
  139. *
  140. * @access public
  141. * @return void
  142. */
  143. function testOwnerAssignment() {
  144. $xml = new Xml();
  145. $node =& $xml->createElement('hello', 'world');
  146. $owner =& $node->document();
  147. $this->assertTrue($xml === $owner);
  148. $children =& $node->children;
  149. $childOwner =& $children[0]->document();
  150. $this->assertTrue($xml === $childOwner);
  151. }
  152. /**
  153. * testArraySingleSerialization method
  154. *
  155. * @access public
  156. * @return void
  157. */
  158. function testArraySingleSerialization() {
  159. $input = array(
  160. 'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
  161. 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'),
  162. );
  163. $expected = '<post><id>1</id><author_id>1</author_id><title><![CDATA[First Post]]></title><body><![CDATA[First Post Body]]></body><published><![CDATA[Y]]></published><created><![CDATA[2007-03-18 10:39:23]]></created><updated><![CDATA[2007-03-18 10:41:31]]></updated><author><id>1</id><user><![CDATA[mariano]]></user><password><![CDATA[5f4dcc3b5aa765d61d8327deb882cf99]]></password><created><![CDATA[2007-03-17 01:16:23]]></created><updated><![CDATA[2007-03-17 01:18:31]]></updated><test><![CDATA[working]]></test></author></post>';
  164. $xml = new Xml($input, array('format' => 'tags'));
  165. $result = $xml->toString(false);
  166. $this->assertEqual($expected, $result);
  167. }
  168. /**
  169. * testArraySerialization method
  170. *
  171. * @access public
  172. * @return void
  173. */
  174. function testArraySerialization() {
  175. $input = array(
  176. array(
  177. '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),
  178. 'Style' => array('id' => null, 'name' => null),
  179. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  180. 'Industry' => array('id' => 1, 'name' => 'Financial')
  181. ),
  182. array(
  183. '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),
  184. 'Style' => array('id' => null, 'name' => null),
  185. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  186. 'Industry' => array('id' => 2, 'name' => 'Education'),
  187. )
  188. );
  189. $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>';
  190. $xml = new Xml($input, array('format' => 'tags'));
  191. $result = $xml->toString(array('header' => false, 'cdata' => false));
  192. $this->assertEqual($expected, $result);
  193. }
  194. /**
  195. * testNestedArraySerialization method
  196. *
  197. * @access public
  198. * @return void
  199. */
  200. function testNestedArraySerialization() {
  201. $input = array(
  202. array(
  203. '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),
  204. 'Style' => array('id' => null, 'name' => null),
  205. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  206. 'Industry' => array('id' => 1, 'name' => 'Financial'),
  207. 'BusinessSolution' => array(array('id' => 6, 'name' => 'Convert Sales')),
  208. 'MediaType' => array(
  209. array('id' => 15, 'name' => 'Print'),
  210. array('id' => 7, 'name' => 'Web Demo'),
  211. array('id' => 6, 'name' => 'CD-ROM')
  212. )
  213. ),
  214. array(
  215. '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),
  216. 'Style' => array('id' => null, 'name' => null),
  217. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  218. 'Industry' => array('id' => 2, 'name' => 'Education'),
  219. 'BusinessSolution' => array(
  220. array('id' => 4, 'name' => 'Build Relationship'),
  221. array('id' => 6, 'name' => 'Convert Sales')
  222. ),
  223. 'MediaType' => array(
  224. array('id' => 17, 'name' => 'Web'),
  225. array('id' => 6, 'name' => 'CD-ROM')
  226. )
  227. )
  228. );
  229. $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>';
  230. $xml = new Xml($input, array('format' => 'tags'));
  231. $result = $xml->toString(array('header' => false, 'cdata' => false));
  232. $this->assertEqual($expected, $result);
  233. }
  234. /**
  235. * testCloneNode
  236. *
  237. * @access public
  238. * @return void
  239. */
  240. function testCloneNode() {
  241. $node =& new XmlNode('element', 'myValue');
  242. $twin =& $node->cloneNode();
  243. $this->assertEqual($node, $twin);
  244. }
  245. /**
  246. * testNextSibling
  247. *
  248. * @access public
  249. * @return void
  250. */
  251. function testNextSibling() {
  252. $input = array(
  253. array(
  254. '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),
  255. 'Style' => array('id' => null, 'name' => null),
  256. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  257. 'Industry' => array('id' => 1, 'name' => 'Financial')
  258. ),
  259. array(
  260. '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),
  261. 'Style' => array('id' => null, 'name' => null),
  262. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  263. 'Industry' => array('id' => 2, 'name' => 'Education'),
  264. )
  265. );
  266. $xml =& new Xml($input, array('format' => 'tags'));
  267. $node =& $xml->children[0]->children[0];
  268. $nextSibling =& $node->nextSibling();
  269. $this->assertEqual($nextSibling, $xml->children[0]->children[1]);
  270. $nextSibling2 =& $nextSibling->nextSibling();
  271. $this->assertEqual($nextSibling2, $xml->children[0]->children[2]);
  272. $noFriends =& $xml->children[0]->children[12];
  273. $this->assertNull($noFriends->nextSibling());
  274. }
  275. /**
  276. * testPreviousSibling
  277. *
  278. * @access public
  279. * @return void
  280. */
  281. function testPreviousSibling() {
  282. $input = array(
  283. array(
  284. '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),
  285. 'Style' => array('id' => null, 'name' => null),
  286. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  287. 'Industry' => array('id' => 1, 'name' => 'Financial')
  288. ),
  289. array(
  290. '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),
  291. 'Style' => array('id' => null, 'name' => null),
  292. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  293. 'Industry' => array('id' => 2, 'name' => 'Education'),
  294. )
  295. );
  296. $xml =& new Xml($input, array('format' => 'tags'));
  297. $node =& $xml->children[0]->children[1];
  298. $prevSibling =& $node->previousSibling();
  299. $this->assertEqual($prevSibling, $xml->children[0]->children[0]);
  300. $this->assertNull($prevSibling->previousSibling());
  301. }
  302. /**
  303. * testAddAndRemoveAttributes
  304. *
  305. * @access public
  306. * @return void
  307. */
  308. function testAddAndRemoveAttributes() {
  309. $node =& new XmlElement('myElement', 'superValue');
  310. $this->assertTrue(empty($node->attributes));
  311. $attrs = array(
  312. 'id' => 'test',
  313. 'show' => 1,
  314. 'is_spotlight' => 1,
  315. );
  316. $node->addAttribute($attrs);
  317. $this->assertEqual($node->attributes, $attrs);
  318. $node =& new XmlElement('myElement', 'superValue');
  319. $node->addAttribute('test', 'value');
  320. $this->assertTrue(isset($node->attributes['test']));
  321. $node =& new XmlElement('myElement', 'superValue');
  322. $obj =& new StdClass();
  323. $obj->class = 'info';
  324. $obj->id = 'primaryInfoBox';
  325. $node->addAttribute($obj);
  326. $expected = array(
  327. 'class' => 'info',
  328. 'id' => 'primaryInfoBox',
  329. );
  330. $this->assertEqual($node->attributes, $expected);
  331. $result = $node->removeAttribute('class');
  332. $this->assertTrue($result);
  333. $this->assertFalse(isset($node->attributes['class']));
  334. $result = $node->removeAttribute('missing');
  335. $this->assertFalse($result);
  336. }
  337. /*
  338. * Not implemented yet
  339. */
  340. // function testChildFilter() {
  341. // $input = array(
  342. // array(
  343. // '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),
  344. // 'Style' => array('id' => null, 'name' => null),
  345. // 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  346. // 'Industry' => array('id' => 1, 'name' => 'Financial'),
  347. // 'BusinessSolution' => array(array('id' => 6, 'name' => 'Convert Sales')),
  348. // 'MediaType' => array(
  349. // array('id' => 15, 'name' => 'Print'),
  350. // array('id' => 7, 'name' => 'Web Demo'),
  351. // array('id' => 6, 'name' => 'CD-ROM')
  352. // )
  353. // ),
  354. // array(
  355. // '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),
  356. // 'Style' => array('id' => null, 'name' => null),
  357. // 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  358. // 'Industry' => array('id' => 2, 'name' => 'Education'),
  359. // 'BusinessSolution' => array(
  360. // array('id' => 4, 'name' => 'Build Relationship'),
  361. // array('id' => 6, 'name' => 'Convert Sales')
  362. // ),
  363. // 'MediaType' => array(
  364. // array('id' => 17, 'name' => 'Web'),
  365. // array('id' => 6, 'name' => 'CD-ROM')
  366. // )
  367. // )
  368. // );
  369. //
  370. // $xml = new Xml($input, array('format' => 'tags', 'tags' => array(
  371. // 'MediaType' => array('value' => 'id', 'children' => false),
  372. // 'JobType' => array('children' => array()),
  373. // 'Industry' => array('children' => array('name')),
  374. // 'show' => false
  375. // )));
  376. //
  377. // $result = $xml->toString(array('header' => false, 'cdata' => false));
  378. // $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>';
  379. // $this->assertEqual($expected, $result);
  380. // }
  381. /*
  382. * Broken due to a Set class issue
  383. */
  384. // function testMixedArray() {
  385. // $input = array('OptionGroup' => array(
  386. // array('name' => 'OptA', 'id' => 12, 'OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6'),
  387. // array('name' => 'OptB', 'id' => 12, 'OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
  388. // ));
  389. // $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>';
  390. // $xml = new Xml($input, array('format' => 'tags'));
  391. // $result = $xml->toString(array('header' => false, 'cdata' => false));
  392. // $this->assertEqual($expected, $result);
  393. // }
  394. // function testMixedNestedArray() {
  395. // $input = array(
  396. // 'OptionA' => array(
  397. // 'name' => 'OptA',
  398. // 'id' => 12,
  399. // 'opt' => array('OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6')
  400. // ),
  401. // 'OptionB' => array(
  402. // 'name' => 'OptB',
  403. // 'id' => 12,
  404. // 'opt' => array('OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
  405. // )
  406. // );
  407. // $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>';
  408. // $xml = new Xml($input, array('format' => 'tags'));
  409. // $result = $xml->toString(array('header' => false, 'cdata' => false));
  410. // $this->assertEqual($expected, $result);
  411. // }
  412. // function testMixedArrayAttributes() {
  413. // $input = array('OptionGroup' => array(
  414. // array(
  415. // 'name' => 'OptA',
  416. // 'id' => 12,
  417. // array('opt' => 'OptA 1'),
  418. // array('opt' => 'OptA 2'),
  419. // array('opt' => 'OptA 3'),
  420. // array('opt' => 'OptA 4'),
  421. // array('opt' => 'OptA 5'),
  422. // array('opt' => 'OptA 6')
  423. // ),
  424. // array(
  425. // 'name' => 'OptB',
  426. // 'id' => 12,
  427. // array('opt' => 'OptB 1'),
  428. // array('opt' => 'OptB 2'),
  429. // array('opt' => 'OptB 3'),
  430. // array('opt' => 'OptB 4'),
  431. // array('opt' => 'OptB 5'),
  432. // array('opt' => 'OptB 6')
  433. // )
  434. // ));
  435. // $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>';
  436. //
  437. // $options = array('tags' => array('option_group' => array('attributes' => array('id', 'name'))));
  438. // $xml = new Xml($input, $options);
  439. // $result = $xml->toString(false);
  440. //
  441. // $this->assertEqual($expected, $result);
  442. // }
  443. /*
  444. * Not implemented yet
  445. */
  446. // function testTagMap() {
  447. // $input = array(
  448. // array(
  449. // '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),
  450. // 'Style' => array('id' => null, 'name' => null),
  451. // 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  452. // 'Industry' => array('id' => 1, 'name' => 'Financial')
  453. // ),
  454. // array(
  455. // '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),
  456. // 'Style' => array('id' => null, 'name' => null),
  457. // 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  458. // 'Industry' => array('id' => 2, 'name' => 'Education'),
  459. // )
  460. // );
  461. // $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>';
  462. //
  463. // $xml = new Xml($input, array('tags' => array(
  464. // 'Project' => array('attributes' => array('id')),
  465. // 'style' => array('attributes' => array('id')),
  466. // 'JobType' => array('name' => 'jobtype', 'attributes' => array('id'), 'value' => 'name'),
  467. // 'Industry' => array('attributes' => array('id'))
  468. // )));
  469. // $result = $xml->toString(array('header' => false, 'cdata' => false));
  470. // $this->assertEqual($expected, $result);
  471. // }
  472. /**
  473. * testAllCData method
  474. *
  475. * @access public
  476. * @return void
  477. */
  478. function testAllCData() {
  479. $input = array(
  480. array(
  481. '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),
  482. 'Style' => array('id' => null, 'name' => null),
  483. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  484. 'Industry' => array('id' => 1, 'name' => 'Financial')
  485. ),
  486. array(
  487. '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),
  488. 'Style' => array('id' => null, 'name' => null),
  489. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  490. 'Industry' => array('id' => 2, 'name' => 'Education'),
  491. )
  492. );
  493. $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>';
  494. $xml = new Xml($input, array('format' => 'tags'));
  495. $result = $xml->toString(array('header' => false, 'cdata' => true));
  496. $this->assertEqual($expected, $result);
  497. }
  498. /*
  499. * PHP-native Unicode support pending
  500. */
  501. // function testConvertEntities() {
  502. // $input = array('project' => '&eacute;c&icirc;t');
  503. // $xml = new Xml($input);
  504. //
  505. // $result = $xml->toString(array('header' => false, 'cdata' => false, 'convertEntities' => true));
  506. // $expected = '<project>&#233;c&#238;t</project>';
  507. // $this->assertEqual($result, $expected);
  508. // }
  509. /**
  510. * testWhitespace method
  511. *
  512. * @access public
  513. * @return void
  514. */
  515. function testWhitespace() {
  516. $input = array(
  517. array(
  518. '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),
  519. 'Style' => array('id' => null, 'name' => null),
  520. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  521. 'Industry' => array('id' => 1, 'name' => 'Financial')
  522. ),
  523. array(
  524. '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),
  525. 'Style' => array('id' => null, 'name' => null),
  526. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  527. 'Industry' => array('id' => 2, 'name' => 'Education'),
  528. )
  529. );
  530. $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";
  531. $xml = new Xml($input, array('format' => 'tags'));
  532. $result = $xml->toString(array('header' => false, 'cdata' => false, 'whitespace' => true));
  533. $this->assertEqual($expected, $result);
  534. }
  535. /**
  536. * testSetSerialization method
  537. *
  538. * @access public
  539. * @return void
  540. */
  541. function testSetSerialization() {
  542. $input = array(
  543. array(
  544. '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),
  545. 'Style' => array('id' => null, 'name' => null),
  546. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  547. 'Industry' => array('id' => 1, 'name' => 'Financial')
  548. ),
  549. array(
  550. '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),
  551. 'Style' => array('id' => null, 'name' => null),
  552. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  553. 'Industry' => array('id' => 2, 'name' => 'Education'),
  554. )
  555. );
  556. $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>';
  557. $xml = new Xml(Set::map($input), array('format' => 'tags'));
  558. $result = $xml->toString(array('header' => false, 'cdata' => false));
  559. $this->assertEqual($expected, $result);
  560. }
  561. /**
  562. * testSimpleParsing method
  563. *
  564. * @access public
  565. * @return void
  566. */
  567. function testSimpleParsing() {
  568. $source = '<response><hello><![CDATA[happy world]]></hello><goodbye><![CDATA[cruel world]]></goodbye></response>';
  569. $xml = new Xml($source);
  570. $result = $xml->toString();
  571. $this->assertEqual($source, $result);
  572. }
  573. /**
  574. * testMixedParsing method
  575. *
  576. * @access public
  577. * @return void
  578. */
  579. function testMixedParsing() {
  580. $source = '<response><body><hello><![CDATA[happy world]]></hello><![CDATA[in between]]><goodbye><![CDATA[cruel world]]></goodbye></body></response>';
  581. $xml = new Xml($source);
  582. $result = $xml->toString();
  583. $this->assertEqual($source, $result);
  584. }
  585. /**
  586. * testComplexParsing method
  587. *
  588. * @access public
  589. * @return void
  590. */
  591. function testComplexParsing() {
  592. $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>';
  593. $xml = new Xml($source);
  594. $result = $xml->toString(array('cdata' => false));
  595. $this->assertEqual($source, $result);
  596. }
  597. /**
  598. * testNamespaceParsing method
  599. *
  600. * @access public
  601. * @return void
  602. */
  603. function testNamespaceParsing() {
  604. $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>';
  605. $xml = new Xml($source);
  606. $result = $xml->toString(array('cdata' => false));
  607. $this->assertEqual($source, $result);
  608. $children = $xml->children('container');
  609. $this->assertEqual($children[0]->namespace, 'a');
  610. $children = $children[0]->children('rule');
  611. $this->assertEqual($children[0]->namespace, 'b');
  612. }
  613. /**
  614. * testNamespaces method
  615. *
  616. * @access public
  617. * @return void
  618. */
  619. function testNamespaces() {
  620. $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>';
  621. $xml = new Xml($source);
  622. $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>';
  623. $_xml = XmlManager::getInstance();
  624. $xml->addNamespace('f', 'http://example.com/f');
  625. $result = $xml->toString(array('cdata' => false));
  626. $this->assertEqual($expects, $result);
  627. }
  628. /**
  629. * testEscapeCharSerialization method
  630. *
  631. * @access public
  632. * @return void
  633. */
  634. function testEscapeCharSerialization() {
  635. $xml = new Xml(array('text' => 'JavaScript & DHTML'), array('attributes' => false, 'format' => 'attributes'));
  636. $result = $xml->toString(false);
  637. $expected = '<std_class text="JavaScript &amp; DHTML" />';
  638. $this->assertEqual($expected, $result);
  639. }
  640. /**
  641. * testToArray method
  642. *
  643. * @access public
  644. * @return void
  645. */
  646. function testToArray() {
  647. App::import('Set');
  648. $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  649. <rss version="2.0">
  650. <channel>
  651. <title>Cake PHP Google Group</title>
  652. <link>http://groups.google.com/group/cake-php</link>
  653. <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>
  654. <language>en</language>
  655. <item>
  656. <title>constructng result array when using findall</title>
  657. <link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
  658. <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>
  659. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
  660. <author>bmil...@gmail.com(bpscrugs)</author>
  661. <pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
  662. </item>
  663. <item>
  664. <title>Re: share views between actions?</title>
  665. <link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
  666. <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>
  667. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
  668. <author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
  669. <pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
  670. </item>
  671. </channel>
  672. </rss>';
  673. $xml = new Xml($string);
  674. $result = $xml->toArray();
  675. $expected = array('Rss' => array(
  676. 'version' => '2.0',
  677. 'Channel' => array(
  678. 'title' => 'Cake PHP Google Group',
  679. 'link' => 'http://groups.google.com/group/cake-php',
  680. '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.',
  681. 'language' => 'en',
  682. 'Item' => array(
  683. array(
  684. 'title' => 'constructng result array when using findall',
  685. 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
  686. '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(",
  687. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
  688. 'author' => 'bmil...@gmail.com(bpscrugs)',
  689. 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
  690. ),
  691. array(
  692. 'title' => 'Re: share views between actions?',
  693. 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
  694. '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',
  695. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
  696. 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
  697. 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
  698. )
  699. )
  700. )
  701. ));
  702. $this->assertEqual($result, $expected);
  703. $string ='<data><post title="Title of this post" description="cool"/></data>';
  704. $xml = new Xml($string);
  705. $result = $xml->toArray();
  706. $expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));
  707. $this->assertEqual($result, $expected);
  708. $xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');
  709. $result = Set::reverse($xml);
  710. $expected = array(
  711. 'Example' => array(
  712. 'Item' => array(
  713. 'title' => 'An example of a correctly reversed XMLNode',
  714. 'Desc' => array(),
  715. )
  716. )
  717. );
  718. $this->assertIdentical($result, $expected);
  719. $xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
  720. $result = $xml->toArray();
  721. $expected = array(
  722. 'Example' => array(
  723. 'Item' => array(
  724. 'attr' => '123',
  725. 'Titles' => array(
  726. 'Title' => array('title1', 'title2')
  727. )
  728. )
  729. )
  730. );
  731. $this->assertIdentical($result, $expected);
  732. $xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
  733. $result = $xml->toArray();
  734. $expected = array(
  735. 'Example' => array(
  736. 'attr' => 'ex_attr',
  737. 'Item' => array(
  738. 'attr' => '123',
  739. 'titles' => 'list',
  740. 'value' => 'textforitems'
  741. )
  742. )
  743. );
  744. $this->assertIdentical($result, $expected);
  745. $xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
  746. $example = $xml->child('example');
  747. $item = $example->child('item');
  748. $result = $item->toArray();
  749. $expected = array(
  750. 'attr' => '123',
  751. 'titles' => 'list',
  752. 'value' => 'textforitems'
  753. );
  754. $this->assertIdentical($result, $expected);
  755. $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  756. <rss version="2.0">
  757. <channel>
  758. <title>Cake PHP Google Group</title>
  759. <link>http://groups.google.com/group/cake-php</link>
  760. <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>
  761. <language>en</language>
  762. <item>
  763. <title>constructng result array when using findall</title>
  764. <link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
  765. <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>
  766. <dc:creator>cakephp</dc:creator>
  767. <category><![CDATA[cakephp]]></category>
  768. <category><![CDATA[model]]></category>
  769. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
  770. <author>bmil...@gmail.com(bpscrugs)</author>
  771. <pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
  772. </item>
  773. <item>
  774. <title>Re: share views between actions?</title>
  775. <link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
  776. <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>
  777. <dc:creator>cakephp</dc:creator>
  778. <category><![CDATA[cakephp]]></category>
  779. <category><![CDATA[model]]></category>
  780. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
  781. <author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
  782. <pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
  783. </item>
  784. </channel>
  785. </rss>';
  786. $xml = new Xml($string);
  787. $result = $xml->toArray();
  788. $expected = array('Rss' => array(
  789. 'version' => '2.0',
  790. 'Channel' => array(
  791. 'title' => 'Cake PHP Google Group',
  792. 'link' => 'http://groups.google.com/group/cake-php',
  793. '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.',
  794. 'language' => 'en',
  795. 'Item' => array(
  796. array(
  797. 'title' => 'constructng result array when using findall',
  798. 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
  799. '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(",
  800. 'creator' => 'cakephp',
  801. 'Category' => array('cakephp', 'model'),
  802. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
  803. 'author' => 'bmil...@gmail.com(bpscrugs)',
  804. 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
  805. ),
  806. array(
  807. 'title' => 'Re: share views between actions?',
  808. 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
  809. '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',
  810. 'creator' => 'cakephp',
  811. 'Category' => array('cakephp', 'model'),
  812. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
  813. 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
  814. 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
  815. )
  816. )
  817. )
  818. ));
  819. $this->assertEqual($result, $expected);
  820. }
  821. function testAppend() {
  822. $parentNode = new XmlNode('ourParentNode');
  823. $parentNode->append( new XmlNode('ourChildNode'));
  824. $first =& $parentNode->first();
  825. $this->assertEqual($first->name, 'ourChildNode');
  826. $string = 'ourChildNode';
  827. $parentNode = new XmlNode('ourParentNode');
  828. $parentNode->append($string);
  829. $last =& $parentNode->last();
  830. $this->assertEqual($last->name, 'ourChildNode');
  831. $this->expectError();
  832. $parentNode->append($parentNode);
  833. }
  834. function testNamespacing() {
  835. $node = new Xml('<xml></xml>');
  836. $node->addNamespace('cake', 'http://cakephp.org');
  837. $this->assertEqual($node->toString(), '<xml xmlns:cake="http://cakephp.org" />');
  838. $this->assertTrue($node->removeNamespace('cake'));
  839. $this->assertEqual($node->toString(), '<xml />');
  840. $node = new Xml('<xml xmlns:cake="http://cakephp.org" />');
  841. $this->assertTrue($node->removeNamespace('cake'));
  842. $this->assertEqual($node->toString(), '<xml />');
  843. $node->addNamespace('cake', 'http://cakephp.org');
  844. $this->assertEqual($node->toString(), '<xml xmlns:cake="http://cakephp.org" />');
  845. }
  846. }
  847. ?>