]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit/lib/AtomParserTest.php
trailing_spaces
[SourceForge/phpwiki.git] / tests / unit / lib / AtomParserTest.php
1 <?php
2 // $Id$
3 /*
4  * Copyright 2010 Sébastien Le Callonnec
5  *
6  * This file is part of PhpWiki.
7  *
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.
12  *
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.
17  *
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.
21  */
22 /**
23  * @author: Sébastien Le Callonnec
24  */
25 require_once('lib/AtomParser.php');
26 require_once('PHPUnit/Autoload.php');
27
28 class AtomParserTest
29 extends phpwiki_TestCase
30 {
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>
41     <author>
42         <name>Sébastien Le Callonnec</name>
43         <email>slc_ie@yahoo.ie</email>
44     </author>
45
46     <entry>
47       <title>Foobar Éire</title>
48       <link href="http://maps.google.com/maps?f=q&amp;sll=53.125728,-6.068907&amp;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>
54           </div>
55         </div>
56       </content>
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>
61     </entry>
62
63 </feed>
64 ATOM;
65         $parser = new AtomParser();
66         $parser->parse($fake_atom_file);
67
68         $this->assertFalse(count($parser->feed) == 0);
69
70         $current_feed = $parser->feed[0];
71         $this->assertEquals("This is a fake feed", $current_feed["title"]);
72
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"]);
77
78         $this->assertFalse(count($current_feed["authors"]) == 0);
79
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"]);
83
84         $this->assertFalse(count($parser->entries) == 0);
85
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"]);
92
93         $payload =<<<CONTENT
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>
98           </div>
99         </div>
100 CONTENT;
101         $this->assertEquals($payload, $current_entry["content"]);
102     }
103
104     function testExtensiveAtomExampleFromRFC4287() {
105         $fake_atom_file = <<<ATOM
106 <?xml version="1.0" encoding="utf-8"?>
107
108 <feed xmlns="http://www.w3.org/2005/Atom">
109   <title type="text">dive into mark</title>
110   <subtitle type="html">
111     A &lt;em&gt;lot&lt;/em&gt; of effort
112     went into making this effortless
113   </subtitle>
114
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>
122
123   <generator uri="http://www.example.com/" version="1.0">
124     Example Toolkit
125   </generator>
126   <entry>
127     <title>Atom draft-07 snapshot</title>
128     <link rel="alternate" type="text/html"
129      href="http://example.org/2005/04/02/atom"/>
130
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>
136
137     <author>
138       <name>Mark Pilgrim</name>
139       <uri>http://example.org/</uri>
140       <email>f8dy@example.com</email>
141
142     </author>
143     <contributor>
144       <name>Sam Ruby</name>
145     </contributor>
146     <contributor>
147
148       <name>Joe Gregorio</name>
149     </contributor>
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>
154
155       </div>
156     </content>
157   </entry>
158 </feed>
159 ATOM;
160         $parser = new AtomParser();
161         $parser->parse($fake_atom_file);
162
163         $this->assertFalse(count($parser->feed) == 0);
164
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"]);
172
173         $this->assertTrue(count($current_feed["authors"]) == 0);
174         $this->assertTrue(count($current_feed["contributors"]) == 0);
175
176
177         $this->assertFalse(count($parser->entries) == 0);
178
179         $current_entry = $parser->entries[0];
180         $this->assertEquals("Atom draft-07 snapshot", $current_entry["title"]);
181         $this->assertEquals("2005-07-31T12:29:29Z", $current_entry["updated"]);
182         $this->assertEquals("2003-12-13T08:29:29-04:00", $current_entry["published"]);
183         $this->assertEquals("tag:example.org,2003:3.2397", $current_entry["id"]);
184         $this->assertEquals(2, count($current_entry["links"]));
185
186         $this->assertTrue(count($current_entry["authors"]) == 1);
187         $this->assertTrue(count($current_entry["contributors"]) == 2);
188
189         $current_author = $current_entry["authors"][0];
190         $this->assertEquals("Mark Pilgrim", $current_author["name"]);
191         $this->assertEquals("f8dy@example.com", $current_author["email"]);
192
193         $first_contributor = $current_entry["contributors"][0];
194         $second_contributor = $current_entry["contributors"][1];
195
196         $this->assertEquals("Sam Ruby", $first_contributor["name"]);
197         $this->assertEquals("Joe Gregorio", $second_contributor["name"]);
198
199         $first_link = $current_entry["links"][0];
200         $this->assertEquals("alternate", $first_link["rel"]);
201         $this->assertEquals("text/html", $first_link["type"]);
202         $this->assertEquals("http://example.org/2005/04/02/atom", $first_link["href"]);
203
204         $second_link = $current_entry["links"][1];
205         $this->assertEquals("enclosure", $second_link["rel"]);
206         $this->assertEquals("audio/mpeg", $second_link["type"]);
207         $this->assertEquals("1337", $second_link["length"]);
208         $this->assertEquals("http://example.org/audio/ph34r_my_podcast.mp3", $second_link["href"]);
209
210         $payload = <<<CONTENT
211 <div xmlns="http://www.w3.org/1999/xhtml">
212         <p><i>[Update: The Atom draft is finished.]</i></p>
213
214       </div>
215 CONTENT;
216
217         $this->assertEquals($payload, $current_entry["content"]);
218     }
219 }
220 ?>