PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

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