PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

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