]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/ActivityParseTests.php
Merge branch 'master' of gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / tests / ActivityParseTests.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 // XXX: we should probably have some common source for this stuff
9
10 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
11 define('STATUSNET', true);
12
13 require_once INSTALLDIR . '/lib/common.php';
14
15 class ActivityParseTests extends PHPUnit_Framework_TestCase
16 {
17     public function testExample1()
18     {
19         global $_example1;
20         $dom = DOMDocument::loadXML($_example1);
21         $act = new Activity($dom->documentElement);
22
23         $this->assertFalse(empty($act));
24
25         $this->assertEquals($act->time, 1243860840);
26         $this->assertEquals($act->verb, ActivityVerb::POST);
27
28         $this->assertFalse(empty($act->object));
29         $this->assertEquals($act->object->title, 'Punctuation Changeset');
30         $this->assertEquals($act->object->type, 'http://versioncentral.example.org/activity/changeset');
31         $this->assertEquals($act->object->summary, 'Fixing punctuation because it makes it more readable.');
32         $this->assertEquals($act->object->id, 'tag:versioncentral.example.org,2009:/change/1643245');
33     }
34
35     public function testExample3()
36     {
37         global $_example3;
38         $dom = DOMDocument::loadXML($_example3);
39
40         $feed = $dom->documentElement;
41
42         $entries = $feed->getElementsByTagName('entry');
43
44         $entry = $entries->item(0);
45
46         $act = new Activity($entry, $feed);
47
48         $this->assertFalse(empty($act));
49         $this->assertEquals($act->time, 1071340202);
50         $this->assertEquals($act->link, 'http://example.org/2003/12/13/atom03.html');
51
52         $this->assertEquals($act->verb, ActivityVerb::POST);
53
54         $this->assertFalse(empty($act->actor));
55         $this->assertEquals($act->actor->type, ActivityObject::PERSON);
56         $this->assertEquals($act->actor->title, 'John Doe');
57         $this->assertEquals($act->actor->id, 'mailto:johndoe@example.com');
58
59         $this->assertFalse(empty($act->object));
60         $this->assertEquals($act->object->type, ActivityObject::NOTE);
61         $this->assertEquals($act->object->id, 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a');
62         $this->assertEquals($act->object->title, 'Atom-Powered Robots Run Amok');
63         $this->assertEquals($act->object->summary, 'Some text.');
64         $this->assertEquals($act->object->link, 'http://example.org/2003/12/13/atom03.html');
65
66         $this->assertFalse(empty($act->context));
67
68         $this->assertTrue(empty($act->target));
69
70         $this->assertEquals($act->entry, $entry);
71         $this->assertEquals($act->feed, $feed);
72     }
73
74     public function testExample4()
75     {
76         global $_example4;
77         $dom = DOMDocument::loadXML($_example4);
78
79         $entry = $dom->documentElement;
80
81         $act = new Activity($entry);
82
83         $this->assertFalse(empty($act));
84         $this->assertEquals(1266547958, $act->time);
85         $this->assertEquals('http://example.net/notice/14', $act->link);
86
87         $this->assertFalse(empty($act->context));
88         $this->assertEquals('http://example.net/notice/12', $act->context->replyToID);
89         $this->assertEquals('http://example.net/notice/12', $act->context->replyToUrl);
90         $this->assertEquals('http://example.net/conversation/11', $act->context->conversation);
91         $this->assertEquals(array('http://example.net/user/1'), $act->context->attention);
92
93         $this->assertFalse(empty($act->object));
94         $this->assertEquals($act->object->content,
95                             '@<span class="vcard"><a href="http://example.net/user/1" class="url"><span class="fn nickname">evan</span></a></span> now is the time for all good men to come to the aid of their country. #<span class="tag"><a href="http://example.net/tag/thetime" rel="tag">thetime</a></span>');
96
97         $this->assertFalse(empty($act->actor));
98     }
99
100     public function testExample5()
101     {
102         global $_example5;
103         $dom = DOMDocument::loadXML($_example5);
104
105         $feed = $dom->documentElement;
106
107         // @todo Test feed elements
108
109         $entries = $feed->getElementsByTagName('entry');
110         $entry = $entries->item(0);
111
112         $act = new Activity($entry, $feed);
113
114         // Post
115         $this->assertEquals($act->verb, ActivityVerb::POST);
116         $this->assertFalse(empty($act->context));
117
118         // Actor w/Portable Contacts stuff
119         $this->assertFalse(empty($act->actor));
120         $this->assertEquals($act->actor->type, ActivityObject::PERSON);
121         $this->assertEquals($act->actor->title, 'Test User');
122         $this->assertEquals($act->actor->id, 'http://example.net/mysite/user/3');
123         $this->assertEquals($act->actor->link, 'http://example.net/mysite/testuser');
124         $this->assertEquals(
125             $act->actor->avatar,
126             'http://example.net/mysite/avatar/3-96-20100224004207.jpeg'
127         );
128         $this->assertEquals($act->actor->displayName, 'Test User');
129
130         $poco = $act->actor->poco;
131         $this->assertEquals($poco->preferredUsername, 'testuser');
132         $this->assertEquals($poco->address->formatted, 'San Francisco, CA');
133         $this->assertEquals($poco->urls[0]->type, 'homepage');
134         $this->assertEquals($poco->urls[0]->value, 'http://example.com/blog.html');
135         $this->assertEquals($poco->urls[0]->primary, 'true');
136         $this->assertEquals($act->actor->geopoint, '37.7749295 -122.4194155');
137
138     }
139
140 }
141
142 $_example1 = <<<EXAMPLE1
143 <?xml version='1.0' encoding='UTF-8'?>
144 <entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
145   <id>tag:versioncentral.example.org,2009:/commit/1643245</id>
146   <published>2009-06-01T12:54:00Z</published>
147   <title>Geraldine committed a change to yate</title>
148   <content type="xhtml">Geraldine just committed a change to yate on VersionCentral</content>
149   <link rel="alternate" type="text/html"
150         href="http://versioncentral.example.org/geraldine/yate/commit/1643245" />
151   <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
152   <activity:verb>http://versioncentral.example.org/activity/commit</activity:verb>
153   <activity:object>
154     <activity:object-type>http://versioncentral.example.org/activity/changeset</activity:object-type>
155     <id>tag:versioncentral.example.org,2009:/change/1643245</id>
156     <title>Punctuation Changeset</title>
157     <summary>Fixing punctuation because it makes it more readable.</summary>
158     <link rel="alternate" type="text/html" href="..." />
159   </activity:object>
160 </entry>
161 EXAMPLE1;
162
163 $_example2 = <<<EXAMPLE2
164 <?xml version='1.0' encoding='UTF-8'?>
165 <entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
166   <id>tag:photopanic.example.com,2008:activity01</id>
167   <title>Geraldine posted a Photo on PhotoPanic</title>
168   <published>2008-11-02T15:29:00Z</published>
169   <link rel="alternate" type="text/html" href="/geraldine/activities/1" />
170   <activity:verb>
171   http://activitystrea.ms/schema/1.0/post
172   </activity:verb>
173   <activity:object>
174     <id>tag:photopanic.example.com,2008:photo01</id>
175     <title>My Cat</title>
176     <published>2008-11-02T15:29:00Z</published>
177     <link rel="alternate" type="text/html" href="/geraldine/photos/1" />
178     <activity:object-type>
179       tag:atomactivity.example.com,2008:photo
180     </activity:object-type>
181     <source>
182       <title>Geraldine's Photos</title>
183       <link rel="self" type="application/atom+xml" href="/geraldine/photofeed.xml" />
184       <link rel="alternate" type="text/html" href="/geraldine/" />
185     </source>
186   </activity:object>
187   <content type="html">
188      &lt;p&gt;Geraldine posted a Photo on PhotoPanic&lt;/p&gt;
189      &lt;img src="/geraldine/photo1.jpg"&gt;
190   </content>
191 </entry>
192 EXAMPLE2;
193
194 $_example3 = <<<EXAMPLE3
195 <?xml version="1.0" encoding="utf-8"?>
196
197 <feed xmlns="http://www.w3.org/2005/Atom">
198
199     <title>Example Feed</title>
200     <subtitle>A subtitle.</subtitle>
201     <link href="http://example.org/feed/" rel="self" />
202     <link href="http://example.org/" />
203     <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
204     <updated>2003-12-13T18:30:02Z</updated>
205     <author>
206         <name>John Doe</name>
207         <email>johndoe@example.com</email>
208     </author>
209
210     <entry>
211         <title>Atom-Powered Robots Run Amok</title>
212         <link href="http://example.org/2003/12/13/atom03" />
213         <link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>
214         <link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>
215         <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
216         <updated>2003-12-13T18:30:02Z</updated>
217         <summary>Some text.</summary>
218     </entry>
219
220 </feed>
221 EXAMPLE3;
222
223 $_example4 = <<<EXAMPLE4
224 <?xml version='1.0' encoding='UTF-8'?>
225 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:ostatus="http://ostatus.org/schema/1.0">
226  <title>@evan now is the time for all good men to come to the aid of their country. #thetime</title>
227  <summary>@evan now is the time for all good men to come to the aid of their country. #thetime</summary>
228 <author>
229  <name>spock</name>
230  <uri>http://example.net/user/2</uri>
231 </author>
232 <activity:actor>
233  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
234  <id>http://example.net/user/2</id>
235  <title>spock</title>
236  <link type="image/png" rel="avatar" href="http://example.net/theme/identica/default-avatar-profile.png"></link>
237 </activity:actor>
238  <link rel="alternate" type="text/html" href="http://example.net/notice/14"/>
239  <id>http://example.net/notice/14</id>
240  <published>2010-02-19T02:52:38+00:00</published>
241  <updated>2010-02-19T02:52:38+00:00</updated>
242  <link rel="related" href="http://example.net/notice/12"/>
243  <thr:in-reply-to ref="http://example.net/notice/12" href="http://example.net/notice/12"></thr:in-reply-to>
244  <link rel="ostatus:conversation" href="http://example.net/conversation/11"/>
245  <link rel="ostatus:attention" href="http://example.net/user/1"/>
246  <content type="html">@&lt;span class=&quot;vcard&quot;&gt;&lt;a href=&quot;http://example.net/user/1&quot; class=&quot;url&quot;&gt;&lt;span class=&quot;fn nickname&quot;&gt;evan&lt;/span&gt;&lt;/a&gt;&lt;/span&gt; now is the time for all good men to come to the aid of their country. #&lt;span class=&quot;tag&quot;&gt;&lt;a href=&quot;http://example.net/tag/thetime&quot; rel=&quot;tag&quot;&gt;thetime&lt;/a&gt;&lt;/span&gt;</content>
247  <category term="thetime"></category>
248 </entry>
249 EXAMPLE4;
250
251 $_example5 = <<<EXAMPLE5
252 <?xml version="1.0" encoding="UTF-8"?>
253 <feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
254  <id>3</id>
255  <title>testuser timeline</title>
256  <subtitle>Updates from testuser on Zach Dev!</subtitle>
257  <logo>http://example.net/mysite/avatar/3-96-20100224004207.jpeg</logo>
258  <updated>2010-02-24T06:38:49+00:00</updated>
259 <author>
260  <name>testuser</name>
261  <uri>http://example.net/mysite/user/3</uri>
262
263 </author>
264  <link href="http://example.net/mysite/testuser" rel="alternate" type="text/html"/>
265  <link href="http://example.net/mysite/api/statuses/user_timeline/3.atom" rel="self" type="application/atom+xml"/>
266  <link href="http://example.net/mysite/main/sup#3" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
267  <link href="http://example.net/mysite/main/push/hub" rel="hub"/>
268  <link href="http://example.net/mysite/main/salmon/user/3" rel="salmon"/>
269 <activity:subject>
270  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
271  <id>http://example.net/mysite/user/3</id>
272  <title>Test User</title>
273  <link rel="alternate" type="text/html" href="http://example.net/mysite/testuser"/>
274  <link type="image/jpeg" rel="avatar" href="http://example.net/mysite/avatar/3-96-20100224004207.jpeg"/>
275  <georss:point>37.7749295 -122.4194155</georss:point>
276
277 <poco:preferredUsername>testuser</poco:preferredUsername>
278 <poco:displayName>Test User</poco:displayName>
279 <poco:note>Just another test user.</poco:note>
280 <poco:address>
281  <poco:formatted>San Francisco, CA</poco:formatted>
282 </poco:address>
283 <poco:urls>
284  <poco:type>homepage</poco:type>
285  <poco:value>http://example.com/blog.html</poco:value>
286  <poco:primary>true</poco:primary>
287
288 </poco:urls>
289 </activity:subject>
290 <entry>
291  <title>Hey man, is that Freedom Code?! #freedom #hippy</title>
292  <summary>Hey man, is that Freedom Code?! #freedom #hippy</summary>
293 <author>
294  <name>testuser</name>
295  <uri>http://example.net/mysite/user/3</uri>
296 </author>
297 <activity:actor>
298  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
299  <id>http://example.net/mysite/user/3</id>
300  <title>Test User</title>
301  <link rel="alternate" type="text/html" href="http://example.net/mysite/testuser"/>
302  <link type="image/jpeg" rel="avatar" href="http://example.net/mysite/avatar/3-96-20100224004207.jpeg"/>
303  <georss:point>37.7749295 -122.4194155</georss:point>
304
305 <poco:preferredUsername>testuser</poco:preferredUsername>
306 <poco:displayName>Test User</poco:displayName>
307 <poco:note>Just another test user.</poco:note>
308 <poco:address>
309  <poco:formatted>San Francisco, CA</poco:formatted>
310 </poco:address>
311 <poco:urls>
312  <poco:type>homepage</poco:type>
313  <poco:value>http://example.com/blog.html</poco:value>
314  <poco:primary>true</poco:primary>
315
316 </poco:urls>
317 </activity:actor>
318  <link rel="alternate" type="text/html" href="http://example.net/mysite/notice/7"/>
319  <id>http://example.net/mysite/notice/7</id>
320  <published>2010-02-24T00:53:06+00:00</published>
321  <updated>2010-02-24T00:53:06+00:00</updated>
322  <link rel="ostatus:conversation" href="http://example.net/mysite/conversation/7"/>
323  <content type="html">Hey man, is that Freedom Code?! #&lt;span class=&quot;tag&quot;&gt;&lt;a href=&quot;http://example.net/mysite/tag/freedom&quot; rel=&quot;tag&quot;&gt;freedom&lt;/a&gt;&lt;/span&gt; #&lt;span class=&quot;tag&quot;&gt;&lt;a href=&quot;http://example.net/mysite/tag/hippy&quot; rel=&quot;tag&quot;&gt;hippy&lt;/a&gt;&lt;/span&gt;</content>
324  <georss:point>37.8313160 -122.2852473</georss:point>
325
326 </entry>
327 </feed>
328 EXAMPLE5;