PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/d1rk/CakePHP-including-Capistrano
PHP | 1104 lines | 681 code | 66 blank | 357 comment | 0 complexity | 7ccaba61484280741a5c445ba7288b2b MD5 | raw file
Possible License(s): LGPL-2.1

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

  1. <?php
  2. /* SVN FILE: $Id: xml.test.php 8158 2009-04-28 13:23:37Z nate $ */
  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: 8158 $
  23. * @modifiedby $LastChangedBy: nate $
  24. * @lastmodified $Date: 2009-04-28 15:23:37 +0200 (Di, 28. Apr 2009) $
  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. * Prove that serialization with a given root node works
  251. * as expected.
  252. *
  253. * @access public
  254. * @return void
  255. * @link https://trac.cakephp.org/ticket/6294
  256. */
  257. function testArraySerializationWithRoot() {
  258. $input = array(
  259. array('Shirt' => array('id' => 1, 'color' => 'green')),
  260. array('Shirt' => array('id' => 2, 'color' => 'blue')),
  261. );
  262. $expected = '<collection><shirt id="1" color="green" />';
  263. $expected .= '<shirt id="2" color="blue" /></collection>';
  264. $Xml = new Xml($input, array('root' => 'collection'));
  265. $result = $Xml->toString(array('header' => false));
  266. $this->assertEqual($expected, $result);
  267. }
  268. /**
  269. * testCloneNode
  270. *
  271. * @access public
  272. * @return void
  273. */
  274. function testCloneNode() {
  275. $node =& new XmlNode('element', 'myValue');
  276. $twin =& $node->cloneNode();
  277. $this->assertEqual($node, $twin);
  278. }
  279. /**
  280. * testNextSibling
  281. *
  282. * @access public
  283. * @return void
  284. */
  285. function testNextSibling() {
  286. $input = array(
  287. array(
  288. '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),
  289. 'Style' => array('id' => null, 'name' => null),
  290. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  291. 'Industry' => array('id' => 1, 'name' => 'Financial')
  292. ),
  293. array(
  294. '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),
  295. 'Style' => array('id' => null, 'name' => null),
  296. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  297. 'Industry' => array('id' => 2, 'name' => 'Education'),
  298. )
  299. );
  300. $xml =& new Xml($input, array('format' => 'tags'));
  301. $node =& $xml->children[0]->children[0];
  302. $nextSibling =& $node->nextSibling();
  303. $this->assertEqual($nextSibling, $xml->children[0]->children[1]);
  304. $nextSibling2 =& $nextSibling->nextSibling();
  305. $this->assertEqual($nextSibling2, $xml->children[0]->children[2]);
  306. $noFriends =& $xml->children[0]->children[12];
  307. $this->assertNull($noFriends->nextSibling());
  308. }
  309. /**
  310. * testPreviousSibling
  311. *
  312. * @access public
  313. * @return void
  314. */
  315. function testPreviousSibling() {
  316. $input = array(
  317. array(
  318. '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),
  319. 'Style' => array('id' => null, 'name' => null),
  320. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  321. 'Industry' => array('id' => 1, 'name' => 'Financial')
  322. ),
  323. array(
  324. '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),
  325. 'Style' => array('id' => null, 'name' => null),
  326. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  327. 'Industry' => array('id' => 2, 'name' => 'Education'),
  328. )
  329. );
  330. $xml =& new Xml($input, array('format' => 'tags'));
  331. $node =& $xml->children[0]->children[1];
  332. $prevSibling =& $node->previousSibling();
  333. $this->assertEqual($prevSibling, $xml->children[0]->children[0]);
  334. $this->assertNull($prevSibling->previousSibling());
  335. }
  336. /**
  337. * testAddAndRemoveAttributes
  338. *
  339. * @access public
  340. * @return void
  341. */
  342. function testAddAndRemoveAttributes() {
  343. $node =& new XmlElement('myElement', 'superValue');
  344. $this->assertTrue(empty($node->attributes));
  345. $attrs = array(
  346. 'id' => 'test',
  347. 'show' => 1,
  348. 'is_spotlight' => 1,
  349. );
  350. $node->addAttribute($attrs);
  351. $this->assertEqual($node->attributes, $attrs);
  352. $node =& new XmlElement('myElement', 'superValue');
  353. $node->addAttribute('test', 'value');
  354. $this->assertTrue(isset($node->attributes['test']));
  355. $node =& new XmlElement('myElement', 'superValue');
  356. $obj =& new StdClass();
  357. $obj->class = 'info';
  358. $obj->id = 'primaryInfoBox';
  359. $node->addAttribute($obj);
  360. $expected = array(
  361. 'class' => 'info',
  362. 'id' => 'primaryInfoBox',
  363. );
  364. $this->assertEqual($node->attributes, $expected);
  365. $result = $node->removeAttribute('class');
  366. $this->assertTrue($result);
  367. $this->assertFalse(isset($node->attributes['class']));
  368. $result = $node->removeAttribute('missing');
  369. $this->assertFalse($result);
  370. }
  371. /**
  372. * Tests that XML documents with non-standard spacing (i.e. leading whitespace, whole document
  373. * on one line) still parse properly.
  374. *
  375. * @return void
  376. */
  377. function testParsingWithNonStandardWhitespace() {
  378. $raw = '<?xml version="1.0" encoding="ISO-8859-1" ?><prices><price>1.0</price></prices>';
  379. $array = array('Prices' => array('price' => 1.0));
  380. $xml = new Xml($raw);
  381. $this->assertEqual($xml->toArray(), $array);
  382. $this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
  383. $xml = new Xml(' ' . $raw);
  384. $this->assertEqual($xml->toArray(), $array);
  385. $this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
  386. $xml = new Xml("\n" . $raw);
  387. $this->assertEqual($xml->toArray(), $array);
  388. $this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
  389. }
  390. /* Not implemented yet */
  391. /* function testChildFilter() {
  392. $input = array(
  393. array(
  394. '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),
  395. 'Style' => array('id' => null, 'name' => null),
  396. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  397. 'Industry' => array('id' => 1, 'name' => 'Financial'),
  398. 'BusinessSolution' => array(array('id' => 6, 'name' => 'Convert Sales')),
  399. 'MediaType' => array(
  400. array('id' => 15, 'name' => 'Print'),
  401. array('id' => 7, 'name' => 'Web Demo'),
  402. array('id' => 6, 'name' => 'CD-ROM')
  403. )
  404. ),
  405. array(
  406. '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),
  407. 'Style' => array('id' => null, 'name' => null),
  408. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  409. 'Industry' => array('id' => 2, 'name' => 'Education'),
  410. 'BusinessSolution' => array(
  411. array('id' => 4, 'name' => 'Build Relationship'),
  412. array('id' => 6, 'name' => 'Convert Sales')
  413. ),
  414. 'MediaType' => array(
  415. array('id' => 17, 'name' => 'Web'),
  416. array('id' => 6, 'name' => 'CD-ROM')
  417. )
  418. )
  419. );
  420. $xml = new Xml($input, array('format' => 'tags', 'tags' => array(
  421. 'MediaType' => array('value' => 'id', 'children' => false),
  422. 'JobType' => array('children' => array()),
  423. 'Industry' => array('children' => array('name')),
  424. 'show' => false
  425. )));
  426. $result = $xml->toString(array('header' => false, 'cdata' => false));
  427. $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>';
  428. $this->assertEqual($expected, $result);
  429. } */
  430. /* Broken due to a Set class issue */
  431. /* function testMixedArray() {
  432. $input = array('OptionGroup' => array(
  433. array('name' => 'OptA', 'id' => 12, 'OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6'),
  434. array('name' => 'OptB', 'id' => 12, 'OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
  435. ));
  436. $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>';
  437. $xml = new Xml($input, array('format' => 'tags'));
  438. $result = $xml->toString(array('header' => false, 'cdata' => false));
  439. $this->assertEqual($expected, $result);
  440. } */
  441. /* function testMixedNestedArray() {
  442. $input = array(
  443. 'OptionA' => array(
  444. 'name' => 'OptA',
  445. 'id' => 12,
  446. 'opt' => array('OptA 1', 'OptA 2', 'OptA 3', 'OptA 4', 'OptA 5', 'OptA 6')
  447. ),
  448. 'OptionB' => array(
  449. 'name' => 'OptB',
  450. 'id' => 12,
  451. 'opt' => array('OptB 1', 'OptB 2', 'OptB 3', 'OptB 4', 'OptB 5', 'OptB 6')
  452. )
  453. );
  454. $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>';
  455. $xml = new Xml($input, array('format' => 'tags'));
  456. $result = $xml->toString(array('header' => false, 'cdata' => false));
  457. $this->assertEqual($expected, $result);
  458. } */
  459. /* function testMixedArrayAttributes() {
  460. $input = array('OptionGroup' => array(
  461. array(
  462. 'name' => 'OptA',
  463. 'id' => 12,
  464. array('opt' => 'OptA 1'),
  465. array('opt' => 'OptA 2'),
  466. array('opt' => 'OptA 3'),
  467. array('opt' => 'OptA 4'),
  468. array('opt' => 'OptA 5'),
  469. array('opt' => 'OptA 6')
  470. ),
  471. array(
  472. 'name' => 'OptB',
  473. 'id' => 12,
  474. array('opt' => 'OptB 1'),
  475. array('opt' => 'OptB 2'),
  476. array('opt' => 'OptB 3'),
  477. array('opt' => 'OptB 4'),
  478. array('opt' => 'OptB 5'),
  479. array('opt' => 'OptB 6')
  480. )
  481. ));
  482. $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>';
  483. $options = array('tags' => array('option_group' => array('attributes' => array('id', 'name'))));
  484. $xml = new Xml($input, $options);
  485. $result = $xml->toString(false);
  486. $this->assertEqual($expected, $result);
  487. } */
  488. /* Not implemented yet */
  489. /* function testTagMap() {
  490. $input = array(
  491. array(
  492. '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),
  493. 'Style' => array('id' => null, 'name' => null),
  494. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  495. 'Industry' => array('id' => 1, 'name' => 'Financial')
  496. ),
  497. array(
  498. '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),
  499. 'Style' => array('id' => null, 'name' => null),
  500. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  501. 'Industry' => array('id' => 2, 'name' => 'Education'),
  502. )
  503. );
  504. $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>';
  505. $xml = new Xml($input, array('tags' => array(
  506. 'Project' => array('attributes' => array('id')),
  507. 'style' => array('attributes' => array('id')),
  508. 'JobType' => array('name' => 'jobtype', 'attributes' => array('id'), 'value' => 'name'),
  509. 'Industry' => array('attributes' => array('id'))
  510. )));
  511. $result = $xml->toString(array('header' => false, 'cdata' => false));
  512. $this->assertEqual($expected, $result);
  513. } */
  514. /**
  515. * testAllCData method
  516. *
  517. * @access public
  518. * @return void
  519. */
  520. function testAllCData() {
  521. $input = array(
  522. array(
  523. '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),
  524. 'Style' => array('id' => null, 'name' => null),
  525. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  526. 'Industry' => array('id' => 1, 'name' => 'Financial')
  527. ),
  528. array(
  529. '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),
  530. 'Style' => array('id' => null, 'name' => null),
  531. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  532. 'Industry' => array('id' => 2, 'name' => 'Education'),
  533. )
  534. );
  535. $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>';
  536. $xml = new Xml($input, array('format' => 'tags'));
  537. $result = $xml->toString(array('header' => false, 'cdata' => true));
  538. $this->assertEqual($expected, $result);
  539. }
  540. /* PHP-native Unicode support pending */
  541. /* function testConvertEntities() {
  542. $input = array('project' => '&eacute;c&icirc;t');
  543. $xml = new Xml($input);
  544. $result = $xml->toString(array('header' => false, 'cdata' => false, 'convertEntities' => true));
  545. $expected = '<project>&#233;c&#238;t</project>';
  546. $this->assertEqual($result, $expected);
  547. } */
  548. /**
  549. * testWhitespace method
  550. *
  551. * @access public
  552. * @return void
  553. */
  554. function testWhitespace() {
  555. $input = array(
  556. array(
  557. '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),
  558. 'Style' => array('id' => null, 'name' => null),
  559. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  560. 'Industry' => array('id' => 1, 'name' => 'Financial')
  561. ),
  562. array(
  563. '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),
  564. 'Style' => array('id' => null, 'name' => null),
  565. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  566. 'Industry' => array('id' => 2, 'name' => 'Education'),
  567. )
  568. );
  569. $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";
  570. $xml = new Xml($input, array('format' => 'tags'));
  571. $result = $xml->toString(array('header' => false, 'cdata' => false, 'whitespace' => true));
  572. $this->assertEqual($expected, $result);
  573. }
  574. /**
  575. * testSetSerialization method
  576. *
  577. * @access public
  578. * @return void
  579. */
  580. function testSetSerialization() {
  581. $input = array(
  582. array(
  583. '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),
  584. 'Style' => array('id' => null, 'name' => null),
  585. 'JobType' => array('id' => 1, 'name' => 'Touch Screen Kiosk'),
  586. 'Industry' => array('id' => 1, 'name' => 'Financial')
  587. ),
  588. array(
  589. '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),
  590. 'Style' => array('id' => null, 'name' => null),
  591. 'JobType' => array('id' => 2, 'name' => 'Awareness Campaign'),
  592. 'Industry' => array('id' => 2, 'name' => 'Education'),
  593. )
  594. );
  595. $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>';
  596. $xml = new Xml(Set::map($input), array('format' => 'tags'));
  597. $result = $xml->toString(array('header' => false, 'cdata' => false));
  598. $this->assertEqual($expected, $result);
  599. }
  600. /**
  601. * testSimpleParsing method
  602. *
  603. * @access public
  604. * @return void
  605. */
  606. function testSimpleParsing() {
  607. $source = '<response><hello><![CDATA[happy world]]></hello><goodbye><![CDATA[cruel world]]></goodbye></response>';
  608. $xml = new Xml($source);
  609. $result = $xml->toString();
  610. $this->assertEqual($source, $result);
  611. }
  612. /**
  613. * testMixedParsing method
  614. *
  615. * @access public
  616. * @return void
  617. */
  618. function testMixedParsing() {
  619. $source = '<response><body><hello><![CDATA[happy world]]></hello><![CDATA[in between]]><goodbye><![CDATA[cruel world]]></goodbye></body></response>';
  620. $xml = new Xml($source);
  621. $result = $xml->toString();
  622. $this->assertEqual($source, $result);
  623. }
  624. /**
  625. * testComplexParsing method
  626. *
  627. * @access public
  628. * @return void
  629. */
  630. function testComplexParsing() {
  631. $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>';
  632. $xml = new Xml($source);
  633. $result = $xml->toString(array('cdata' => false));
  634. $this->assertEqual($source, $result);
  635. }
  636. /**
  637. * testNamespaceParsing method
  638. *
  639. * @access public
  640. * @return void
  641. */
  642. function testNamespaceParsing() {
  643. $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>';
  644. $xml = new Xml($source);
  645. $result = $xml->toString(array('cdata' => false));
  646. $this->assertEqual($source, $result);
  647. $children = $xml->children('container');
  648. $this->assertEqual($children[0]->namespace, 'a');
  649. $children = $children[0]->children('rule');
  650. $this->assertEqual($children[0]->namespace, 'b');
  651. }
  652. /**
  653. * testNamespaces method
  654. *
  655. * @access public
  656. * @return void
  657. */
  658. function testNamespaces() {
  659. $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>';
  660. $xml = new Xml($source);
  661. $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>';
  662. $_xml = XmlManager::getInstance();
  663. $xml->addNamespace('f', 'http://example.com/f');
  664. $result = $xml->toString(array('cdata' => false));
  665. $this->assertEqual($expects, $result);
  666. }
  667. /**
  668. * testEscapeCharSerialization method
  669. *
  670. * @access public
  671. * @return void
  672. */
  673. function testEscapeCharSerialization() {
  674. $xml = new Xml(array('text' => 'JavaScript & DHTML'), array('attributes' => false, 'format' => 'attributes'));
  675. $result = $xml->toString(false);
  676. $expected = '<std_class text="JavaScript &amp; DHTML" />';
  677. $this->assertEqual($expected, $result);
  678. }
  679. /**
  680. * testCompleteEscapeCharSerialization method
  681. *
  682. * @access public
  683. * @return void
  684. */
  685. function testCompleteEscapeCharSerialization() {
  686. $xml = new Xml(array('text' => '<>&"\''), array('attributes' => false, 'format' => 'attributes'));
  687. $result = $xml->toString(false);
  688. $expected = '<std_class text="&lt;&gt;&amp;&quot;&#039;" />';
  689. $this->assertEqual($expected, $result);
  690. }
  691. /**
  692. * testToArray method
  693. *
  694. * @access public
  695. * @return void
  696. */
  697. function testToArray() {
  698. App::import('Set');
  699. $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  700. <rss version="2.0">
  701. <channel>
  702. <title>Cake PHP Google Group</title>
  703. <link>http://groups.google.com/group/cake-php</link>
  704. <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>
  705. <language>en</language>
  706. <item>
  707. <title>constructng result array when using findall</title>
  708. <link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
  709. <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>
  710. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
  711. <author>bmil...@gmail.com(bpscrugs)</author>
  712. <pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
  713. </item>
  714. <item>
  715. <title>Re: share views between actions?</title>
  716. <link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
  717. <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>
  718. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
  719. <author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
  720. <pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
  721. </item>
  722. </channel>
  723. </rss>';
  724. $xml = new Xml($string);
  725. $result = $xml->toArray();
  726. $expected = array('Rss' => array(
  727. 'version' => '2.0',
  728. 'Channel' => array(
  729. 'title' => 'Cake PHP Google Group',
  730. 'link' => 'http://groups.google.com/group/cake-php',
  731. '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.',
  732. 'language' => 'en',
  733. 'Item' => array(
  734. array(
  735. 'title' => 'constructng result array when using findall',
  736. 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
  737. '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(",
  738. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
  739. 'author' => 'bmil...@gmail.com(bpscrugs)',
  740. 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
  741. ),
  742. array(
  743. 'title' => 'Re: share views between actions?',
  744. 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
  745. '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',
  746. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
  747. 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
  748. 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
  749. )
  750. )
  751. )
  752. ));
  753. $this->assertEqual($result, $expected);
  754. $string ='<data><post title="Title of this post" description="cool"/></data>';
  755. $xml = new Xml($string);
  756. $result = $xml->toArray();
  757. $expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));
  758. $this->assertEqual($result, $expected);
  759. $xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');
  760. $result = Set::reverse($xml);
  761. $expected = array(
  762. 'Example' => array(
  763. 'Item' => array(
  764. 'title' => 'An example of a correctly reversed XMLNode',
  765. 'Desc' => array(),
  766. )
  767. )
  768. );
  769. $this->assertIdentical($result, $expected);
  770. $xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
  771. $result = $xml->toArray();
  772. $expected = array(
  773. 'Example' => array(
  774. 'Item' => array(
  775. 'attr' => '123',
  776. 'Titles' => array(
  777. 'Title' => array('title1', 'title2')
  778. )
  779. )
  780. )
  781. );
  782. $this->assertIdentical($result, $expected);
  783. $xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
  784. $result = $xml->toArray();
  785. $expected = array(
  786. 'Example' => array(
  787. 'attr' => 'ex_attr',
  788. 'Item' => array(
  789. 'attr' => '123',
  790. 'titles' => 'list',
  791. 'value' => 'textforitems'
  792. )
  793. )
  794. );
  795. $this->assertIdentical($result, $expected);
  796. $xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
  797. $example = $xml->child('example');
  798. $item = $example->child('item');
  799. $result = $item->toArray();
  800. $expected = array(
  801. 'attr' => '123',
  802. 'titles' => 'list',
  803. 'value' => 'textforitems'
  804. );
  805. $this->assertIdentical($result, $expected);
  806. $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  807. <rss version="2.0">
  808. <channel>
  809. <title>Cake PHP Google Group</title>
  810. <link>http://groups.google.com/group/cake-php</link>
  811. <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>
  812. <language>en</language>
  813. <item>
  814. <title>constructng result array when using findall</title>
  815. <link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
  816. <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>
  817. <dc:creator>cakephp</dc:creator>
  818. <category><![CDATA[cakephp]]></category>
  819. <category><![CDATA[model]]></category>
  820. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
  821. <author>bmil...@gmail.com(bpscrugs)</author>
  822. <pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
  823. </item>
  824. <item>
  825. <title>Re: share views between actions?</title>
  826. <link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
  827. <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>
  828. <dc:creator>cakephp</dc:creator>
  829. <category><![CDATA[cakephp]]></category>
  830. <category><![CDATA[model]]></category>
  831. <guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
  832. <author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
  833. <pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
  834. </item>
  835. </channel>
  836. </rss>';
  837. $xml = new Xml($string);
  838. $result = $xml->toArray();
  839. $expected = array('Rss' => array(
  840. 'version' => '2.0',
  841. 'Channel' => array(
  842. 'title' => 'Cake PHP Google Group',
  843. 'link' => 'http://groups.google.com/group/cake-php',
  844. '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.',
  845. 'language' => 'en',
  846. 'Item' => array(
  847. array(
  848. 'title' => 'constructng result array when using findall',
  849. 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f',
  850. '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(",
  851. 'creator' => 'cakephp',
  852. 'Category' => array('cakephp', 'model'),
  853. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'),
  854. 'author' => 'bmil...@gmail.com(bpscrugs)',
  855. 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT',
  856. ),
  857. array(
  858. 'title' => 'Re: share views between actions?',
  859. 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8',
  860. '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',
  861. 'creator' => 'cakephp',
  862. 'Category' => array('cakephp', 'model'),
  863. 'guid' => array('isPermaLink' => 'true', 'value' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'),
  864. 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)',
  865. 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT'
  866. )
  867. )
  868. )
  869. ));
  870. $this->assertEqual($result, $expected);
  871. $text = "<?xml version='1.0' encoding='utf-8'?>
  872. <course>
  873. <comps>
  874. <comp>1</comp>
  875. <comp>2</comp>
  876. <comp>3</comp>
  877. <comp>4</comp>
  878. </comps>
  879. </course>";
  880. $xml = new Xml($text);
  881. $result = $xml->toArray();
  882. $expected = array('Course' => array(
  883. 'Comps' => array(
  884. 'Comp' => array(
  885. 1, 2, 3, 4
  886. )
  887. )
  888. ));
  889. $this->assertEqual($result, $expected);
  890. $text = '<?xml version="1.0" encoding="UTF-8"?>
  891. <XRDS xmlns="xri://$xrds">
  892. <XRD xml:id="oauth" xmlns="xri://$XRD*($v*2.0)" version="2.0">
  893. <Type>xri://$xrds*simple</Type>
  894. <Expires>2008-04-13T07:34:58Z</Expires>
  895. <Service>
  896. <Type>http://oauth.net/core/1.0/endpoint/authorize</Type>
  897. <Type>http://oauth.net/core/1.0/parameters/auth-header</Type>
  898. <Type>http://oauth.net/core/1.0/parameters/uri-query</Type>
  899. <URI priority="10">https://ma.gnolia.com/oauth/authorize</URI>
  900. <URI priority="20">http://ma.gnolia.com/oauth/authorize</URI>
  901. </Service>
  902. </XRD>
  903. <XRD xmlns="xri://$XRD*($v*2.0)" version="2.0">
  904. <Type>xri://$xrds*simple</Type>
  905. <Service priority="10">
  906. <Type>http://oauth.net/discovery/1.0</Type>
  907. <URI>#oauth</URI>
  908. </Service>
  909. </XRD>
  910. </XRDS>';
  911. $xml = new Xml($text);
  912. $result = $xml->toArray();
  913. $expected = array('XRDS' => array(
  914. 'xmlns' => 'xri://$xrds',
  915. 'XRD' => array(
  916. array(
  917. 'xml:id' => 'oauth',
  918. 'xmlns' => 'xri://$XRD*($v*2.0)',
  919. 'version' => '2.0',
  920. 'Type' => 'xri://$xrds*simple',
  921. 'Expires' => '2008-04-13T07:34:58Z',
  922. 'Service' => array(
  923. 'Type' => array(
  924. 'http://oauth.net/core/1.0/endpoint/authorize',
  925. 'http://oauth.net/core/1.0/parameters/auth-header',
  926. 'http://oauth.net/core/1.0/parameters/uri-query'
  927. ),
  928. 'URI' => array(
  929. array(
  930. 'value' => 'https://ma.gnolia.com/oauth/authorize',
  931. 'priority' => '10',
  932. ),
  933. array(
  934. 'value' => 'http://ma.gnolia.com/oauth/authorize',
  935. 'priority' => '20'
  936. )
  937. )
  938. )
  939. ),
  940. array(
  941. 'xmlns' => 'xri://$XRD*($v*2.0)',
  942. 'version' => '2.0',
  943. 'Type' => 'xri://$xrds*simple',
  944. 'Service' => array(
  945. 'priority' => '10',
  946. 'Type' => 'http://oauth.net/discovery/1.0',
  947. 'URI' => '#oauth'
  948. )
  949. )
  950. )
  951. ));
  952. $this->assertEqual($result, $expected);
  953. }
  954. /**
  955. * testAppend method
  956. *
  957. * @access public
  958. * @return void
  959. */
  960. function testAppend() {
  961. $parentNode = new XmlNode('ourParentNode');
  962. $parentNode->append( new XmlNode('ourChildNode'));
  963. $first =& $parentNode->first();
  964. $this->assertEqual($first->name, 'ourChildNode');
  965. $string = 'ourChildNode';
  966. $parentNode = new XmlNode('ourParentNode');
  967. $parentNode->append($string);
  968. $last =& $parentNode->last();
  969. $this->assertEqual($last->name, 'ourChildNode');
  970. $this->expectError();
  971. $parentNode->append($parentNode);
  972. }
  973. /**
  974. * testNamespacing method
  975. *
  976. * @access public
  977. * @return void
  978. */
  979. function testNamespacing() {
  980. $node = new Xml('<xml></xml>');
  981. $node->addNamespace('cake', 'h…

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