PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/cases/libs/view/helpers/rss.test.php

https://github.com/hack521/contenidopago
PHP | 593 lines | 469 code | 34 blank | 90 comment | 0 complexity | 6eb025475a1295cbe245b5bae68c7efe MD5 | raw file
  1. <?php
  2. /**
  3. * RssHelperTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package cake
  16. * @subpackage cake.tests.cases.libs.view.helpers
  17. * @since CakePHP(tm) v 1.2.0.4206
  18. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  19. */
  20. App::import('Helper', array('Rss', 'Time'));
  21. /**
  22. * RssHelperTest class
  23. *
  24. * @package cake
  25. * @subpackage cake.tests.cases.libs.view.helpers
  26. */
  27. class RssHelperTest extends CakeTestCase {
  28. /**
  29. * setUp method
  30. *
  31. * @access public
  32. * @return void
  33. */
  34. function setUp() {
  35. $this->Rss =& new RssHelper();
  36. $this->Rss->Time =& new TimeHelper();
  37. $this->Rss->beforeRender();
  38. $manager =& XmlManager::getInstance();
  39. $manager->namespaces = array();
  40. }
  41. /**
  42. * tearDown method
  43. *
  44. * @access public
  45. * @return void
  46. */
  47. function tearDown() {
  48. unset($this->Rss);
  49. }
  50. /**
  51. * testAddNamespace method
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. function testAddNamespace() {
  57. $this->Rss->addNs('custom', 'http://example.com/dtd.xml');
  58. $manager =& XmlManager::getInstance();
  59. $expected = array('custom' => 'http://example.com/dtd.xml');
  60. $this->assertEqual($manager->namespaces, $expected);
  61. $this->Rss->removeNs('custom');
  62. $this->Rss->addNs('dummy', 'http://dummy.com/1.0/');
  63. $result = $this->Rss->document();
  64. $expected = array(
  65. 'rss' => array(
  66. 'xmlns:dummy' => 'http://dummy.com/1.0/',
  67. 'version' => '2.0'
  68. )
  69. );
  70. $this->assertTags($result, $expected);
  71. $this->Rss->removeNs('dummy');
  72. }
  73. /**
  74. * testRemoveNamespace method
  75. *
  76. * @access public
  77. * @return void
  78. */
  79. function testRemoveNamespace() {
  80. $this->Rss->addNs('custom', 'http://example.com/dtd.xml');
  81. $this->Rss->addNs('custom2', 'http://example.com/dtd2.xml');
  82. $manager =& XmlManager::getInstance();
  83. $expected = array('custom' => 'http://example.com/dtd.xml', 'custom2' => 'http://example.com/dtd2.xml');
  84. $this->assertEqual($manager->namespaces, $expected);
  85. $this->Rss->removeNs('custom');
  86. $expected = array('custom2' => 'http://example.com/dtd2.xml');
  87. $this->assertEqual($manager->namespaces, $expected);
  88. }
  89. /**
  90. * testDocument method
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function testDocument() {
  96. $result = $this->Rss->document();
  97. $expected = array(
  98. 'rss' => array(
  99. 'version' => '2.0'
  100. )
  101. );
  102. $this->assertTags($result, $expected);
  103. $result = $this->Rss->document(array('contrived' => 'parameter'));
  104. $expected = array(
  105. 'rss' => array(
  106. 'version' => '2.0'
  107. ),
  108. '<parameter'
  109. );
  110. $this->assertTags($result, $expected);
  111. $result = $this->Rss->document(null, 'content');
  112. $expected = array(
  113. 'rss' => array(
  114. 'version' => '2.0'
  115. ),
  116. 'content'
  117. );
  118. $this->assertTags($result, $expected);
  119. $result = $this->Rss->document(array('contrived' => 'parameter'), 'content');
  120. $expected = array(
  121. 'rss' => array(
  122. 'contrived' => 'parameter',
  123. 'version' => '2.0'
  124. ),
  125. 'content'
  126. );
  127. $this->assertTags($result, $expected);
  128. }
  129. /**
  130. * testChannel method
  131. *
  132. * @access public
  133. * @return void
  134. */
  135. function testChannel() {
  136. $attrib = array('a' => '1', 'b' => '2');
  137. $elements = array('title' => 'title');
  138. $content = 'content';
  139. $result = $this->Rss->channel($attrib, $elements, $content);
  140. $expected = array(
  141. 'channel' => array(
  142. 'a' => '1',
  143. 'b' => '2'
  144. ),
  145. '<title',
  146. 'title',
  147. '/title',
  148. '<link',
  149. RssHelper::url('/', true),
  150. '/link',
  151. '<description',
  152. 'content',
  153. '/channel'
  154. );
  155. $this->assertTags($result, $expected);
  156. }
  157. /**
  158. * test correct creation of channel sub elements.
  159. *
  160. * @access public
  161. * @return void
  162. */
  163. function testChannelElements() {
  164. $attrib = array();
  165. $elements = array(
  166. 'title' => 'Title of RSS Feed',
  167. 'link' => 'http://example.com',
  168. 'description' => 'Description of RSS Feed',
  169. 'image' => array(
  170. 'title' => 'Title of image',
  171. 'url' => 'http://example.com/example.png',
  172. 'link' => 'http://example.com'
  173. ),
  174. 'cloud' => array(
  175. 'domain' => "rpc.sys.com",
  176. 'port' => "80",
  177. 'path' =>"/RPC2",
  178. 'registerProcedure' => "myCloud.rssPleaseNotify",
  179. 'protocol' => "xml-rpc"
  180. )
  181. );
  182. $content = 'content-here';
  183. $result = $this->Rss->channel($attrib, $elements, $content);
  184. $expected = array(
  185. '<channel',
  186. '<title', 'Title of RSS Feed', '/title',
  187. '<link', 'http://example.com', '/link',
  188. '<description', 'Description of RSS Feed', '/description',
  189. '<image',
  190. '<title', 'Title of image', '/title',
  191. '<url', 'http://example.com/example.png', '/url',
  192. '<link', 'http://example.com', '/link',
  193. '/image',
  194. 'cloud' => array(
  195. 'domain' => "rpc.sys.com",
  196. 'port' => "80",
  197. 'path' =>"/RPC2",
  198. 'registerProcedure' => "myCloud.rssPleaseNotify",
  199. 'protocol' => "xml-rpc"
  200. ),
  201. 'content-here',
  202. '/channel',
  203. );
  204. $this->assertTags($result, $expected);
  205. }
  206. function testChannelElementAttributes() {
  207. $attrib = array();
  208. $elements = array(
  209. 'title' => 'Title of RSS Feed',
  210. 'link' => 'http://example.com',
  211. 'description' => 'Description of RSS Feed',
  212. 'image' => array(
  213. 'title' => 'Title of image',
  214. 'url' => 'http://example.com/example.png',
  215. 'link' => 'http://example.com'
  216. ),
  217. 'atom:link' => array(
  218. 'attrib' => array(
  219. 'href' => 'http://www.example.com/rss.xml',
  220. 'rel' => 'self',
  221. 'type' => 'application/rss+xml')
  222. )
  223. );
  224. $content = 'content-here';
  225. $result = $this->Rss->channel($attrib, $elements, $content);
  226. $expected = array(
  227. '<channel',
  228. '<title', 'Title of RSS Feed', '/title',
  229. '<link', 'http://example.com', '/link',
  230. '<description', 'Description of RSS Feed', '/description',
  231. '<image',
  232. '<title', 'Title of image', '/title',
  233. '<url', 'http://example.com/example.png', '/url',
  234. '<link', 'http://example.com', '/link',
  235. '/image',
  236. 'atom:link' => array(
  237. 'href' => "http://www.example.com/rss.xml",
  238. 'rel' => "self",
  239. 'type' =>"application/rss+xml"
  240. ),
  241. 'content-here',
  242. '/channel',
  243. );
  244. $this->assertTags($result, $expected);
  245. }
  246. /**
  247. * testItems method
  248. *
  249. * @access public
  250. * @return void
  251. */
  252. function testItems() {
  253. $items = array(
  254. array('title' => 'title1', 'guid' => 'http://www.example.com/guid1', 'link' => 'http://www.example.com/link1', 'description' => 'description1'),
  255. array('title' => 'title2', 'guid' => 'http://www.example.com/guid2', 'link' => 'http://www.example.com/link2', 'description' => 'description2'),
  256. array('title' => 'title3', 'guid' => 'http://www.example.com/guid3', 'link' => 'http://www.example.com/link3', 'description' => 'description3')
  257. );
  258. $result = $this->Rss->items($items);
  259. $expected = array(
  260. '<item',
  261. '<title', 'title1', '/title',
  262. '<guid', 'http://www.example.com/guid1', '/guid',
  263. '<link', 'http://www.example.com/link1', '/link',
  264. '<description', 'description1', '/description',
  265. '/item',
  266. '<item',
  267. '<title', 'title2', '/title',
  268. '<guid', 'http://www.example.com/guid2', '/guid',
  269. '<link', 'http://www.example.com/link2', '/link',
  270. '<description', 'description2', '/description',
  271. '/item',
  272. '<item',
  273. '<title', 'title3', '/title',
  274. '<guid', 'http://www.example.com/guid3', '/guid',
  275. '<link', 'http://www.example.com/link3', '/link',
  276. '<description', 'description3', '/description',
  277. '/item'
  278. );
  279. $this->assertTags($result, $expected);
  280. $result = $this->Rss->items(array());
  281. $expected = '';
  282. $this->assertEqual($result, $expected);
  283. }
  284. /**
  285. * testItem method
  286. *
  287. * @access public
  288. * @return void
  289. */
  290. function testItem() {
  291. $item = array(
  292. 'title' => 'My title',
  293. 'description' => 'My description',
  294. 'link' => 'http://www.google.com/'
  295. );
  296. $result = $this->Rss->item(null, $item);
  297. $expected = array(
  298. '<item',
  299. '<title',
  300. 'My title',
  301. '/title',
  302. '<description',
  303. 'My description',
  304. '/description',
  305. '<link',
  306. 'http://www.google.com/',
  307. '/link',
  308. '<guid',
  309. 'http://www.google.com/',
  310. '/guid',
  311. '/item'
  312. );
  313. $this->assertTags($result, $expected);
  314. $item = array(
  315. 'title' => array(
  316. 'value' => 'My Title',
  317. 'cdata' => true,
  318. ),
  319. 'link' => 'http://www.example.com/1',
  320. 'description' => array(
  321. 'value' => 'descriptive words',
  322. 'cdata' => true,
  323. ),
  324. 'pubDate' => '2008-05-31 12:00:00',
  325. 'guid' => 'http://www.example.com/1'
  326. );
  327. $result = $this->Rss->item(null, $item);
  328. $expected = array(
  329. '<item',
  330. '<title',
  331. '<![CDATA[My Title]]',
  332. '/title',
  333. '<link',
  334. 'http://www.example.com/1',
  335. '/link',
  336. '<description',
  337. '<![CDATA[descriptive words]]',
  338. '/description',
  339. '<pubDate',
  340. date('r', strtotime('2008-05-31 12:00:00')),
  341. '/pubDate',
  342. '<guid',
  343. 'http://www.example.com/1',
  344. '/guid',
  345. '/item'
  346. );
  347. $this->assertTags($result, $expected);
  348. $item = array(
  349. 'title' => array(
  350. 'value' => 'My Title & more',
  351. 'cdata' => true
  352. )
  353. );
  354. $result = $this->Rss->item(null, $item);
  355. $expected = array(
  356. '<item',
  357. '<title',
  358. '<![CDATA[My Title &amp; more]]',
  359. '/title',
  360. '/item'
  361. );
  362. $this->assertTags($result, $expected);
  363. $item = array(
  364. 'title' => array(
  365. 'value' => 'My Title & more',
  366. 'convertEntities' => false
  367. )
  368. );
  369. $result = $this->Rss->item(null, $item);
  370. $expected = array(
  371. '<item',
  372. '<title',
  373. 'My Title & more',
  374. '/title',
  375. '/item'
  376. );
  377. $this->assertTags($result, $expected);
  378. $item = array(
  379. 'title' => array(
  380. 'value' => 'My Title & more',
  381. 'cdata' => true,
  382. 'convertEntities' => false,
  383. )
  384. );
  385. $result = $this->Rss->item(null, $item);
  386. $expected = array(
  387. '<item',
  388. '<title',
  389. '<![CDATA[My Title & more]]',
  390. '/title',
  391. '/item'
  392. );
  393. $this->assertTags($result, $expected);
  394. $item = array(
  395. 'category' => array(
  396. 'value' => 'CakePHP',
  397. 'cdata' => true,
  398. 'domain' => 'http://www.cakephp.org'
  399. )
  400. );
  401. $result = $this->Rss->item(null, $item);
  402. $expected = array(
  403. '<item',
  404. 'category' => array('domain' => 'http://www.cakephp.org'),
  405. '<![CDATA[CakePHP]]',
  406. '/category',
  407. '/item'
  408. );
  409. $this->assertTags($result, $expected);
  410. $item = array(
  411. 'category' => array(
  412. array(
  413. 'value' => 'CakePHP',
  414. 'cdata' => true,
  415. 'domain' => 'http://www.cakephp.org'
  416. ),
  417. array(
  418. 'value' => 'Bakery',
  419. 'cdata' => true
  420. )
  421. )
  422. );
  423. $result = $this->Rss->item(null, $item);
  424. $expected = array(
  425. '<item',
  426. 'category' => array('domain' => 'http://www.cakephp.org'),
  427. '<![CDATA[CakePHP]]',
  428. '/category',
  429. '<category',
  430. '<![CDATA[Bakery]]',
  431. '/category',
  432. '/item'
  433. );
  434. $this->assertTags($result, $expected);
  435. $item = array(
  436. 'title' => array(
  437. 'value' => 'My Title',
  438. 'cdata' => true,
  439. ),
  440. 'link' => 'http://www.example.com/1',
  441. 'description' => array(
  442. 'value' => 'descriptive words',
  443. 'cdata' => true,
  444. ),
  445. 'enclosure' => array(
  446. 'url' => '/test.flv'
  447. ),
  448. 'pubDate' => '2008-05-31 12:00:00',
  449. 'guid' => 'http://www.example.com/1',
  450. 'category' => array(
  451. array(
  452. 'value' => 'CakePHP',
  453. 'cdata' => true,
  454. 'domain' => 'http://www.cakephp.org'
  455. ),
  456. array(
  457. 'value' => 'Bakery',
  458. 'cdata' => true
  459. )
  460. )
  461. );
  462. $result = $this->Rss->item(null, $item);
  463. $expected = array(
  464. '<item',
  465. '<title',
  466. '<![CDATA[My Title]]',
  467. '/title',
  468. '<link',
  469. 'http://www.example.com/1',
  470. '/link',
  471. '<description',
  472. '<![CDATA[descriptive words]]',
  473. '/description',
  474. 'enclosure' => array('url' => RssHelper::url('/test.flv', true)),
  475. '<pubDate',
  476. date('r', strtotime('2008-05-31 12:00:00')),
  477. '/pubDate',
  478. '<guid',
  479. 'http://www.example.com/1',
  480. '/guid',
  481. 'category' => array('domain' => 'http://www.cakephp.org'),
  482. '<![CDATA[CakePHP]]',
  483. '/category',
  484. '<category',
  485. '<![CDATA[Bakery]]',
  486. '/category',
  487. '/item'
  488. );
  489. $this->assertTags($result, $expected);
  490. $item = array(
  491. 'title' => 'Foo bar',
  492. 'link' => array(
  493. 'url' => 'http://example.com/foo?a=1&b=2',
  494. 'convertEntities' => false
  495. ),
  496. 'description' => array(
  497. 'value' => 'descriptive words',
  498. 'cdata' => true,
  499. ),
  500. 'pubDate' => '2008-05-31 12:00:00'
  501. );
  502. $result = $this->Rss->item(null, $item);
  503. $expected = array(
  504. '<item',
  505. '<title',
  506. 'Foo bar',
  507. '/title',
  508. '<link',
  509. 'http://example.com/foo?a=1&amp;b=2',
  510. '/link',
  511. '<description',
  512. '<![CDATA[descriptive words]]',
  513. '/description',
  514. '<pubDate',
  515. date('r', strtotime('2008-05-31 12:00:00')),
  516. '/pubDate',
  517. '<guid',
  518. 'http://example.com/foo?a=1&amp;b=2',
  519. '/guid',
  520. '/item'
  521. );
  522. $this->assertTags($result, $expected);
  523. }
  524. /**
  525. * testTime method
  526. *
  527. * @access public
  528. * @return void
  529. */
  530. function testTime() {
  531. }
  532. /**
  533. * testElementAttrNotInParent method
  534. *
  535. * @access public
  536. * @return void
  537. */
  538. function testElementAttrNotInParent() {
  539. $attributes = array(
  540. 'title' => 'Some Title',
  541. 'link' => 'http://link.com',
  542. 'description' => 'description'
  543. );
  544. $elements = array('enclosure' => array('url' => 'http://test.com'));
  545. $result = $this->Rss->item($attributes, $elements);
  546. $expected = array(
  547. 'item' => array(
  548. 'title' => 'Some Title',
  549. 'link' => 'http://link.com',
  550. 'description' => 'description'
  551. ),
  552. 'enclosure' => array(
  553. 'url' => 'http://test.com'
  554. ),
  555. '/item'
  556. );
  557. $this->assertTags($result, $expected);
  558. }
  559. }