PageRenderTime 63ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/hardsshah/bookmarks
PHP | 1060 lines | 657 code | 60 blank | 343 comment | 0 complexity | cdbd28e116b3dd7c03c09bd6c9655eeb MD5 | raw file

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

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

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