PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/PHPFrame/Document/RSSDocumentTest.php

https://github.com/chrismcband/PHPFrame
PHP | 287 lines | 258 code | 27 blank | 2 comment | 0 complexity | 0e8da8f6f2c77ac0d05942c47c82db70 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. // Include framework if not inculded yet
  3. require_once preg_replace("/tests\/.*/", "src/PHPFrame.php", __FILE__);
  4. class PHPFrame_RSSDocumentTest extends PHPUnit_Framework_TestCase
  5. {
  6. private $_rss;
  7. public function setUp()
  8. {
  9. PHPFrame::testMode(true);
  10. $this->_rss = new PHPFrame_RSSDocument();
  11. }
  12. public function tearDown()
  13. {
  14. //...
  15. }
  16. public function test_toString()
  17. {
  18. $this->_rss->title("My RSS Feed");
  19. $this->_rss->link("http://www.lupomontero.com/feed");
  20. $this->_rss->description("Some really cool news feed...");
  21. $this->_rss->image("http://www.xul.fr/xul.gif", "http://www.xul.fr/en/index.php");
  22. $this->_rss->addItem(
  23. "Hello world",
  24. "http://www.lupomontero.com/hello-world",
  25. "Blah blah blah...",
  26. "2010-02-20",
  27. "Lupo Montero"
  28. );
  29. $expected = "<?xml version=\"1.0\"?>\n"
  30. ."<rss version=\"2.0\"><channel><title>My RSS Feed</title><link>"
  31. ."http://www.lupomontero.com/feed</link><description>Some really cool "
  32. ."news feed...</description><image><url>http://www.xul.fr/xul.gif"
  33. ."</url><link>http://www.xul.fr/en/index.php</link></image><item>"
  34. ."<title>Hello world</title><link>http://www.lupomontero.com/hello-"
  35. ."world</link><description>Blah blah blah...</description><pubDate>"
  36. ."2010-02-20</pubDate><author>Lupo Montero</author></item></channel>"
  37. ."</rss>\n";
  38. $this->assertEquals($expected, (string) $this->_rss);
  39. }
  40. public function test_link()
  41. {
  42. $link = "http://www.lupomontero.com/feed";
  43. $this->_rss->link($link);
  44. $this->assertEquals($link, $this->_rss->link());
  45. }
  46. public function test_description()
  47. {
  48. $description = "Blah blah blah";
  49. $this->_rss->description($description);
  50. $this->assertEquals($description, $this->_rss->description());
  51. }
  52. public function test_image()
  53. {
  54. $url = "http://www.phpframe.org/themes/phpframe.org/images/tree.jpg";
  55. $link = "http://www.e-noise.com";
  56. $this->_rss->image($url, $link);
  57. $this->assertEquals(array("url"=>$url, "link"=>$link), $this->_rss->image());
  58. }
  59. public function test_imageFailure()
  60. {
  61. $this->setExpectedException("InvalidArgumentException");
  62. $this->_rss->image("Blah");
  63. }
  64. public function test_items()
  65. {
  66. $item = array(
  67. "title" => "The item title",
  68. "link" => "http://link/to/the/item",
  69. "description" => "A really cool description...",
  70. "pub_date" => "2010-02-20",
  71. "author" => "Lupo Montero"
  72. );
  73. $this->_rss->items(array($item, $item));
  74. $this->assertEquals(
  75. array(
  76. array(
  77. "title" => "The item title",
  78. "link" => "http://link/to/the/item",
  79. "description" => "A really cool description...",
  80. "pub_date" => "2010-02-20",
  81. "author" => "Lupo Montero"
  82. ),
  83. array(
  84. "title" => "The item title",
  85. "link" => "http://link/to/the/item",
  86. "description" => "A really cool description...",
  87. "pub_date" => "2010-02-20",
  88. "author" => "Lupo Montero"
  89. )
  90. ),
  91. $this->_rss->items()
  92. );
  93. }
  94. public function test_addItem()
  95. {
  96. $this->_rss->addItem(
  97. "The item title",
  98. "http://link/to/the/item",
  99. "A really cool description...",
  100. "2010-02-20",
  101. "Lupo Montero"
  102. );
  103. $this->assertEquals(
  104. array(array(
  105. "title" => "The item title",
  106. "link" => "http://link/to/the/item",
  107. "description" => "A really cool description...",
  108. "pub_date" => "2010-02-20",
  109. "author" => "Lupo Montero"
  110. )),
  111. $this->_rss->items()
  112. );
  113. }
  114. public function test_loadAtom()
  115. {
  116. $str = '<?xml version="1.0" encoding="UTF-8"?>
  117. <feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  118. <id>tag:github.com,2008:/PHPFrame/PHPFrame/commits/master</id>
  119. <link type="text/html" href="http://github.com/PHPFrame/PHPFrame/commits/master/" rel="alternate"/>
  120. <link type="application/atom+xml" href="http://github.com/PHPFrame/PHPFrame/commits/master.atom" rel="self"/>
  121. <title>Recent Commits to PHPFrame:master</title>
  122. <updated>2010-04-19T12:53:40-07:00</updated>
  123. <entry>
  124. <id>tag:github.com,2008:Grit::Commit/6c0fbb8aa25890ddbf114a451e32dd3dadd5b6aa</id>
  125. <link type="text/html" href="http://github.com/PHPFrame/PHPFrame/commit/6c0fbb8aa25890ddbf114a451e32dd3dadd5b6aa" rel="alternate"/>
  126. <title>Fixed minor bug in DateFilter class.</title>
  127. <updated>2010-04-19T12:53:40-07:00</updated>
  128. <content type="html">&lt;pre&gt;m src/PHPFrame/Filter/DateFilter.php
  129. Fixed minor bug in DateFilter class.&lt;/pre&gt;</content>
  130. <author>
  131. <name>Lupo Montero</name>
  132. </author>
  133. </entry>
  134. <entry>
  135. <id>tag:github.com,2008:Grit::Commit/40595ea0931542e88fc6250cb4938a9b4d48cdf5</id>
  136. <link type="text/html" href="http://github.com/PHPFrame/PHPFrame/commit/40595ea0931542e88fc6250cb4938a9b4d48cdf5" rel="alternate"/>
  137. <title>Standarising whitespace...</title>
  138. <updated>2010-04-19T12:42:10-07:00</updated>
  139. <content type="html">&lt;pre&gt;m LICENSE
  140. m build/makedoc.xml
  141. Standarising whitespace...&lt;/pre&gt;</content>
  142. <author>
  143. <name>Lupo Montero</name>
  144. </author>
  145. </entry>
  146. <entry>
  147. <id>tag:github.com,2008:Grit::Commit/fea39f1aea4f6e2c08ffb564c04f0b91c4046dee</id>
  148. <link type="text/html" href="http://github.com/PHPFrame/PHPFrame/commit/fea39f1aea4f6e2c08ffb564c04f0b91c4046dee" rel="alternate"/>
  149. <title>Updated CLIs action controller template class with new constructor signature</title>
  150. <updated>2010-04-19T05:12:59-07:00</updated>
  151. <content type="html">&lt;pre&gt;m data/CLI_Tool/data/class-templates/ActionController.php
  152. Updated CLIs action controller template class with new constructor signature&lt;/pre&gt;</content>
  153. <author>
  154. <name>Lupo Montero</name>
  155. </author>
  156. </entry>
  157. <entry>
  158. <id>tag:github.com,2008:Grit::Commit/bad31217ffaaf1c27cd59617985935e842db90d7</id>
  159. <link type="text/html" href="http://github.com/PHPFrame/PHPFrame/commit/bad31217ffaaf1c27cd59617985935e842db90d7" rel="alternate"/>
  160. <title>Fixed order in which obesrvers are attached to exception handler in application class</title>
  161. <updated>2010-04-19T05:12:07-07:00</updated>
  162. <content type="html">&lt;pre&gt;m src/PHPFrame/Application/Application.php
  163. m tests/PHPFrame/Application/ApplicationTest.php
  164. Fixed order in which obesrvers are attached to exception handler in application class&lt;/pre&gt;</content>
  165. <author>
  166. <name>Lupo Montero</name>
  167. </author>
  168. </entry>
  169. <entry>
  170. <id>tag:github.com,2008:Grit::Commit/fd7aa55c33b30804ecc236ffaf54cb3e3c28b077</id>
  171. <link type="text/html" href="http://github.com/PHPFrame/PHPFrame/commit/fd7aa55c33b30804ecc236ffaf54cb3e3c28b077" rel="alternate"/>
  172. <title>Changed ActionController constructor to take instance of app as argument to increase flexibility in controllers. This change will break the API si please check the mailing list for a topic I will post explaining how to change your action controllers after you update to 1.0 build.113 or higher.</title>
  173. <updated>2010-04-17T08:48:49-07:00</updated>
  174. <content type="html">&lt;pre&gt;m README.md
  175. m build/build.xml
  176. m data/CLI_Tool/src/controllers/app.php
  177. m data/CLI_Tool/src/controllers/config.php
  178. m data/CLI_Tool/src/controllers/man.php
  179. m data/CLI_Tool/src/controllers/scaffold.php
  180. m data/CLI_Tool/src/models/apptemplate.php
  181. m src/PHPFrame/Application/Application.php
  182. m src/PHPFrame/MVC/ActionController.php
  183. m src/PHPFrame/MVC/MVCFactory.php
  184. m tests/PHPFrame/Application/SyseventsTest.php
  185. m tests/PHPFrame/Debug/InformerTest.php
  186. m tests/PHPFrame/MVC/ActionControllerTest.php
  187. Changed ActionController constructor to take instance of app as argument to increase flexibility in controllers. This change will break the API si please check the mailing list for a topic I will post explaining how to change your action controllers after you update to 1.0 build.113 or higher.&lt;/pre&gt;</content>
  188. <author>
  189. <name>Lupo Montero</name>
  190. </author>
  191. </entry>
  192. </feed>
  193. ';
  194. $this->_rss->loadXML($str);
  195. $this->assertEquals(
  196. "http://github.com/PHPFrame/PHPFrame/commits/master.atom",
  197. $this->_rss->link()
  198. );
  199. $this->assertEquals(5, count($this->_rss->items()));
  200. }
  201. public function test_loadRSS2()
  202. {
  203. $str = '<?xml version="1.0" encoding="UTF-8"?>
  204. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:georss="http://www.georss.org/georss">
  205. <channel>
  206. <title>Twitter / PHPFrame</title>
  207. <link>http://twitter.com/PHPFrame</link>
  208. <atom:link type="application/rss+xml" href="http://twitter.com/statuses/user_timeline/69732903.rss" rel="self"/>
  209. <description>Twitter updates from PHPFrame / PHPFrame.</description>
  210. <language>en-us</language>
  211. <ttl>40</ttl>
  212. <item>
  213. <title>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 1 commits</title>
  214. <description>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 1 commits</description>
  215. <pubDate>Mon, 19 Apr 2010 19:44:33 +0000</pubDate>
  216. <guid>http://twitter.com/PHPFrame/statuses/12472512646</guid>
  217. <link>http://twitter.com/PHPFrame/statuses/12472512646</link>
  218. </item>
  219. <item>
  220. <title>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 2 commits</title>
  221. <description>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 2 commits</description>
  222. <pubDate>Mon, 19 Apr 2010 12:15:21 +0000</pubDate>
  223. <guid>http://twitter.com/PHPFrame/statuses/12452339459</guid>
  224. <link>http://twitter.com/PHPFrame/statuses/12452339459</link>
  225. </item>
  226. <item>
  227. <title>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 1 commits</title>
  228. <description>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 1 commits</description>
  229. <pubDate>Sat, 17 Apr 2010 15:54:04 +0000</pubDate>
  230. <guid>http://twitter.com/PHPFrame/statuses/12347889736</guid>
  231. <link>http://twitter.com/PHPFrame/statuses/12347889736</link>
  232. </item>
  233. <item>
  234. <title>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 2 commits</title>
  235. <description>PHPFrame: [PHPFrame] http://bit.ly/cE39PC Lupo Montero - 2 commits</description>
  236. <pubDate>Fri, 16 Apr 2010 20:06:49 +0000</pubDate>
  237. <guid>http://twitter.com/PHPFrame/statuses/12301989398</guid>
  238. <link>http://twitter.com/PHPFrame/statuses/12301989398</link>
  239. </item>
  240. <item>
  241. <title>PHPFrame: [PHPFrame] http://bit.ly/cK7xwz Lupo Montero - 1 commits</title>
  242. <description>PHPFrame: [PHPFrame] http://bit.ly/cK7xwz Lupo Montero - 1 commits</description>
  243. <pubDate>Fri, 16 Apr 2010 16:51:39 +0000</pubDate>
  244. <guid>http://twitter.com/PHPFrame/statuses/12293177832</guid>
  245. <link>http://twitter.com/PHPFrame/statuses/12293177832</link>
  246. </item>
  247. </channel>
  248. </rss>
  249. ';
  250. $this->_rss->loadXML($str);
  251. $this->assertEquals("http://twitter.com/PHPFrame", $this->_rss->link());
  252. $this->assertEquals(5, count($this->_rss->items()));
  253. }
  254. }