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