]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/ActivityParseTests.php
Fix test to account for new way avatars are stored in ActivityObject
[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
125         $avatars = $act->actor->avatarLinks;
126
127         $this->assertEquals(
128                 $avatars[0]->url,
129                 'http://example.net/mysite/avatar/3-96-20100224004207.jpeg'
130         );
131
132         $this->assertEquals($act->actor->displayName, 'Test User');
133
134         $poco = $act->actor->poco;
135         $this->assertEquals($poco->preferredUsername, 'testuser');
136         $this->assertEquals($poco->address->formatted, 'San Francisco, CA');
137         $this->assertEquals($poco->urls[0]->type, 'homepage');
138         $this->assertEquals($poco->urls[0]->value, 'http://example.com/blog.html');
139         $this->assertEquals($poco->urls[0]->primary, 'true');
140         $this->assertEquals($act->actor->geopoint, '37.7749295 -122.4194155');
141
142     }
143
144 }
145
146 $_example1 = <<<EXAMPLE1
147 <?xml version='1.0' encoding='UTF-8'?>
148 <entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
149   <id>tag:versioncentral.example.org,2009:/commit/1643245</id>
150   <published>2009-06-01T12:54:00Z</published>
151   <title>Geraldine committed a change to yate</title>
152   <content type="xhtml">Geraldine just committed a change to yate on VersionCentral</content>
153   <link rel="alternate" type="text/html"
154         href="http://versioncentral.example.org/geraldine/yate/commit/1643245" />
155   <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
156   <activity:verb>http://versioncentral.example.org/activity/commit</activity:verb>
157   <activity:object>
158     <activity:object-type>http://versioncentral.example.org/activity/changeset</activity:object-type>
159     <id>tag:versioncentral.example.org,2009:/change/1643245</id>
160     <title>Punctuation Changeset</title>
161     <summary>Fixing punctuation because it makes it more readable.</summary>
162     <link rel="alternate" type="text/html" href="..." />
163   </activity:object>
164 </entry>
165 EXAMPLE1;
166
167 $_example2 = <<<EXAMPLE2
168 <?xml version='1.0' encoding='UTF-8'?>
169 <entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
170   <id>tag:photopanic.example.com,2008:activity01</id>
171   <title>Geraldine posted a Photo on PhotoPanic</title>
172   <published>2008-11-02T15:29:00Z</published>
173   <link rel="alternate" type="text/html" href="/geraldine/activities/1" />
174   <activity:verb>
175   http://activitystrea.ms/schema/1.0/post
176   </activity:verb>
177   <activity:object>
178     <id>tag:photopanic.example.com,2008:photo01</id>
179     <title>My Cat</title>
180     <published>2008-11-02T15:29:00Z</published>
181     <link rel="alternate" type="text/html" href="/geraldine/photos/1" />
182     <activity:object-type>
183       tag:atomactivity.example.com,2008:photo
184     </activity:object-type>
185     <source>
186       <title>Geraldine's Photos</title>
187       <link rel="self" type="application/atom+xml" href="/geraldine/photofeed.xml" />
188       <link rel="alternate" type="text/html" href="/geraldine/" />
189     </source>
190   </activity:object>
191   <content type="html">
192      &lt;p&gt;Geraldine posted a Photo on PhotoPanic&lt;/p&gt;
193      &lt;img src="/geraldine/photo1.jpg"&gt;
194   </content>
195 </entry>
196 EXAMPLE2;
197
198 $_example3 = <<<EXAMPLE3
199 <?xml version="1.0" encoding="utf-8"?>
200
201 <feed xmlns="http://www.w3.org/2005/Atom">
202
203     <title>Example Feed</title>
204     <subtitle>A subtitle.</subtitle>
205     <link href="http://example.org/feed/" rel="self" />
206     <link href="http://example.org/" />
207     <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
208     <updated>2003-12-13T18:30:02Z</updated>
209     <author>
210         <name>John Doe</name>
211         <email>johndoe@example.com</email>
212     </author>
213
214     <entry>
215         <title>Atom-Powered Robots Run Amok</title>
216         <link href="http://example.org/2003/12/13/atom03" />
217         <link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>
218         <link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>
219         <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
220         <updated>2003-12-13T18:30:02Z</updated>
221         <summary>Some text.</summary>
222     </entry>
223
224 </feed>
225 EXAMPLE3;
226
227 $_example4 = <<<EXAMPLE4
228 <?xml version='1.0' encoding='UTF-8'?>
229 <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">
230  <title>@evan now is the time for all good men to come to the aid of their country. #thetime</title>
231  <summary>@evan now is the time for all good men to come to the aid of their country. #thetime</summary>
232 <author>
233  <name>spock</name>
234  <uri>http://example.net/user/2</uri>
235 </author>
236 <activity:actor>
237  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
238  <id>http://example.net/user/2</id>
239  <title>spock</title>
240  <link type="image/png" rel="avatar" href="http://example.net/theme/identica/default-avatar-profile.png"></link>
241 </activity:actor>
242  <link rel="alternate" type="text/html" href="http://example.net/notice/14"/>
243  <id>http://example.net/notice/14</id>
244  <published>2010-02-19T02:52:38+00:00</published>
245  <updated>2010-02-19T02:52:38+00:00</updated>
246  <link rel="related" href="http://example.net/notice/12"/>
247  <thr:in-reply-to ref="http://example.net/notice/12" href="http://example.net/notice/12"></thr:in-reply-to>
248  <link rel="ostatus:conversation" href="http://example.net/conversation/11"/>
249  <link rel="ostatus:attention" href="http://example.net/user/1"/>
250  <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>
251  <category term="thetime"></category>
252 </entry>
253 EXAMPLE4;
254
255 $_example5 = <<<EXAMPLE5
256 <?xml version="1.0" encoding="UTF-8"?>
257 <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">
258  <id>3</id>
259  <title>testuser timeline</title>
260  <subtitle>Updates from testuser on Zach Dev!</subtitle>
261  <logo>http://example.net/mysite/avatar/3-96-20100224004207.jpeg</logo>
262  <updated>2010-02-24T06:38:49+00:00</updated>
263 <author>
264  <name>testuser</name>
265  <uri>http://example.net/mysite/user/3</uri>
266
267 </author>
268  <link href="http://example.net/mysite/testuser" rel="alternate" type="text/html"/>
269  <link href="http://example.net/mysite/api/statuses/user_timeline/3.atom" rel="self" type="application/atom+xml"/>
270  <link href="http://example.net/mysite/main/sup#3" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
271  <link href="http://example.net/mysite/main/push/hub" rel="hub"/>
272  <link href="http://example.net/mysite/main/salmon/user/3" rel="salmon"/>
273 <activity:subject>
274  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
275  <id>http://example.net/mysite/user/3</id>
276  <title>Test User</title>
277  <link rel="alternate" type="text/html" href="http://example.net/mysite/testuser"/>
278  <link type="image/jpeg" rel="avatar" href="http://example.net/mysite/avatar/3-96-20100224004207.jpeg"/>
279  <georss:point>37.7749295 -122.4194155</georss:point>
280
281 <poco:preferredUsername>testuser</poco:preferredUsername>
282 <poco:displayName>Test User</poco:displayName>
283 <poco:note>Just another test user.</poco:note>
284 <poco:address>
285  <poco:formatted>San Francisco, CA</poco:formatted>
286 </poco:address>
287 <poco:urls>
288  <poco:type>homepage</poco:type>
289  <poco:value>http://example.com/blog.html</poco:value>
290  <poco:primary>true</poco:primary>
291
292 </poco:urls>
293 </activity:subject>
294 <entry>
295  <title>Hey man, is that Freedom Code?! #freedom #hippy</title>
296  <summary>Hey man, is that Freedom Code?! #freedom #hippy</summary>
297 <author>
298  <name>testuser</name>
299  <uri>http://example.net/mysite/user/3</uri>
300 </author>
301 <activity:actor>
302  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
303  <id>http://example.net/mysite/user/3</id>
304  <title>Test User</title>
305  <link rel="alternate" type="text/html" href="http://example.net/mysite/testuser"/>
306  <link type="image/jpeg" rel="avatar" href="http://example.net/mysite/avatar/3-96-20100224004207.jpeg"/>
307  <georss:point>37.7749295 -122.4194155</georss:point>
308
309 <poco:preferredUsername>testuser</poco:preferredUsername>
310 <poco:displayName>Test User</poco:displayName>
311 <poco:note>Just another test user.</poco:note>
312 <poco:address>
313  <poco:formatted>San Francisco, CA</poco:formatted>
314 </poco:address>
315 <poco:urls>
316  <poco:type>homepage</poco:type>
317  <poco:value>http://example.com/blog.html</poco:value>
318  <poco:primary>true</poco:primary>
319
320 </poco:urls>
321 </activity:actor>
322  <link rel="alternate" type="text/html" href="http://example.net/mysite/notice/7"/>
323  <id>http://example.net/mysite/notice/7</id>
324  <published>2010-02-24T00:53:06+00:00</published>
325  <updated>2010-02-24T00:53:06+00:00</updated>
326  <link rel="ostatus:conversation" href="http://example.net/mysite/conversation/7"/>
327  <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>
328  <georss:point>37.8313160 -122.2852473</georss:point>
329
330 </entry>
331 </feed>
332 EXAMPLE5;