3 * Copyright 2010 Sébastien Le Callonnec
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * @author: Sébastien Le Callonnec
24 require_once 'lib/AtomParser.php';
25 require_once 'PHPUnit/Autoload.php';
28 extends phpwiki_TestCase
30 function testSimpleAtomFileParsing() {
31 $fake_atom_file = <<<ATOM
32 <?xml version="1.0" encoding="utf-8"?>
33 <feed xmlns="http://www.w3.org/2005/Atom"
34 xmlns:georss="http://www.georss.org/georss" >
35 <link href="http://www.phpwiki.org/fakeurl" rel="self" type="application/atom+xml" />
36 <title>This is a fake feed</title>
37 <updated>2010-05-15T01:00:00Z</updated>
38 <id>http://www.phpwiki.org/fakeurl</id>
39 <subtitle>Cool feed</subtitle>
41 <name>Sébastien Le Callonnec</name>
42 <email>slc_ie@yahoo.ie</email>
46 <title>Foobar Éire</title>
47 <link href="http://maps.google.com/maps?f=q&sll=53.125728,-6.068907&ie=UTF8"/>
48 <content type="xhtml">
49 <div xmlns="http://www.w3.org/1999/xhtml">Millenium Spire, Dublin
50 <div class="geo">Geo coordinates:
51 <abbr class="latitude" title="53.349441">53.349441</abbr>
52 <abbr class="longitude" title="-6.260282">-6.260282</abbr>
56 <updated>2010-05-15T01:00:00Z</updated>
57 <published>2010-05-15T01:00:00Z</published>
58 <georss:box>53.349441 -6.26234 53.35078 -6.260282</georss:box>
59 <id>tag:www.phpwiki.org,2010-05-15:/fakeurl/20100515223621</id>
64 $parser = new AtomParser();
65 $parser->parse($fake_atom_file);
67 $this->assertFalse(count($parser->feed) == 0);
69 $current_feed = $parser->feed[0];
70 $this->assertEquals("This is a fake feed", $current_feed["title"]);
72 $this->assertFalse(count($current_feed["links"]) == 0);
73 $this->assertEquals("http://www.phpwiki.org/fakeurl", $current_feed["links"][0]["href"]);
74 $this->assertEquals("Cool feed", $current_feed["subtitle"]);
75 $this->assertEquals("2010-05-15T01:00:00Z", $current_feed["updated"]);
77 $this->assertFalse(count($current_feed["authors"]) == 0);
79 $current_author = $current_feed["authors"][0];
80 $this->assertEquals("Sébastien Le Callonnec", $current_author["name"]);
81 $this->assertEquals("slc_ie@yahoo.ie", $current_author["email"]);
83 $this->assertFalse(count($parser->entries) == 0);
85 $current_entry = $parser->entries[0];
86 $this->assertEquals("Foobar Éire", $current_entry["title"]);
87 $this->assertEquals("http://maps.google.com/maps?f=q&sll=53.125728,-6.068907&ie=UTF8", $current_entry["links"][0]["href"]);
88 $this->assertEquals("2010-05-15T01:00:00Z", $current_entry["updated"]);
89 $this->assertEquals("2010-05-15T01:00:00Z", $current_entry["published"]);
90 $this->assertEquals("tag:www.phpwiki.org,2010-05-15:/fakeurl/20100515223621", $current_entry["id"]);
93 <div xmlns="http://www.w3.org/1999/xhtml">Millenium Spire, Dublin
94 <div class="geo">Geo coordinates:
95 <abbr class="latitude" title="53.349441">53.349441</abbr>
96 <abbr class="longitude" title="-6.260282">-6.260282</abbr>
100 $this->assertEquals($payload, $current_entry["content"]);
103 function testExtensiveAtomExampleFromRFC4287() {
104 $fake_atom_file = <<<ATOM
105 <?xml version="1.0" encoding="utf-8"?>
107 <feed xmlns="http://www.w3.org/2005/Atom">
108 <title type="text">dive into mark</title>
109 <subtitle type="html">
110 A <em>lot</em> of effort
111 went into making this effortless
114 <updated>2005-07-31T12:29:29Z</updated>
115 <id>tag:example.org,2003:3</id>
116 <link rel="alternate" type="text/html"
117 hreflang="en" href="http://example.org/"/>
118 <link rel="self" type="application/atom+xml"
119 href="http://example.org/feed.atom"/>
120 <rights>Copyright (c) 2003, Mark Pilgrim</rights>
122 <generator uri="http://www.example.com/" version="1.0">
126 <title>Atom draft-07 snapshot</title>
127 <link rel="alternate" type="text/html"
128 href="http://example.org/2005/04/02/atom"/>
130 <link rel="enclosure" type="audio/mpeg" length="1337"
131 href="http://example.org/audio/ph34r_my_podcast.mp3"/>
132 <id>tag:example.org,2003:3.2397</id>
133 <updated>2005-07-31T12:29:29Z</updated>
134 <published>2003-12-13T08:29:29-04:00</published>
137 <name>Mark Pilgrim</name>
138 <uri>http://example.org/</uri>
139 <email>f8dy@example.com</email>
143 <name>Sam Ruby</name>
147 <name>Joe Gregorio</name>
149 <content type="xhtml" xml:lang="en"
150 xml:base="http://diveintomark.org/">
151 <div xmlns="http://www.w3.org/1999/xhtml">
152 <p><i>[Update: The Atom draft is finished.]</i></p>
159 $parser = new AtomParser();
160 $parser->parse($fake_atom_file);
162 $this->assertFalse(count($parser->feed) == 0);
164 $current_feed = $parser->feed[0];
165 $this->assertEquals("dive into mark", $current_feed["title"]);
166 $this->assertEquals("Copyright (c) 2003, Mark Pilgrim", $current_feed["rights"]);
167 $this->assertEquals("A <em>lot</em> of effort\n went into making this effortless", $current_feed["subtitle"]);
168 $this->assertEquals("2005-07-31T12:29:29Z", $current_feed["updated"]);
169 $this->assertEquals("tag:example.org,2003:3", $current_feed["id"]);
170 $this->assertEquals("Example Toolkit", $current_feed["generator"]);
172 $this->assertTrue(count($current_feed["authors"]) == 0);
173 $this->assertTrue(count($current_feed["contributors"]) == 0);
175 $this->assertFalse(count($parser->entries) == 0);
177 $current_entry = $parser->entries[0];
178 $this->assertEquals("Atom draft-07 snapshot", $current_entry["title"]);
179 $this->assertEquals("2005-07-31T12:29:29Z", $current_entry["updated"]);
180 $this->assertEquals("2003-12-13T08:29:29-04:00", $current_entry["published"]);
181 $this->assertEquals("tag:example.org,2003:3.2397", $current_entry["id"]);
182 $this->assertEquals(2, count($current_entry["links"]));
184 $this->assertTrue(count($current_entry["authors"]) == 1);
185 $this->assertTrue(count($current_entry["contributors"]) == 2);
187 $current_author = $current_entry["authors"][0];
188 $this->assertEquals("Mark Pilgrim", $current_author["name"]);
189 $this->assertEquals("f8dy@example.com", $current_author["email"]);
191 $first_contributor = $current_entry["contributors"][0];
192 $second_contributor = $current_entry["contributors"][1];
194 $this->assertEquals("Sam Ruby", $first_contributor["name"]);
195 $this->assertEquals("Joe Gregorio", $second_contributor["name"]);
197 $first_link = $current_entry["links"][0];
198 $this->assertEquals("alternate", $first_link["rel"]);
199 $this->assertEquals("text/html", $first_link["type"]);
200 $this->assertEquals("http://example.org/2005/04/02/atom", $first_link["href"]);
202 $second_link = $current_entry["links"][1];
203 $this->assertEquals("enclosure", $second_link["rel"]);
204 $this->assertEquals("audio/mpeg", $second_link["type"]);
205 $this->assertEquals("1337", $second_link["length"]);
206 $this->assertEquals("http://example.org/audio/ph34r_my_podcast.mp3", $second_link["href"]);
208 $payload = <<<CONTENT
209 <div xmlns="http://www.w3.org/1999/xhtml">
210 <p><i>[Update: The Atom draft is finished.]</i></p>
215 $this->assertEquals($payload, $current_entry["content"]);