PageRenderTime 74ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://skygames.googlecode.com/
PHP | 1027 lines | 639 code | 67 blank | 321 comment | 0 complexity | 6832ce168787d467cc7b08caa28170ca MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, CC-BY-SA-3.0

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

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

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