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