]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/tests/ActivityParseTests.php
generate keypairs for users, and put them in the XRD for discovery
[quix0rs-gnu-social.git] / plugins / OStatus / 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 require_once INSTALLDIR . '/plugins/OStatus/lib/activity.php';
15
16 class ActivityParseTests extends PHPUnit_Framework_TestCase
17 {
18     public function testExample1()
19     {
20         global $_example1;
21         $dom = DOMDocument::loadXML($_example1);
22         $act = new Activity($dom->documentElement);
23
24         $this->assertFalse(empty($act));
25
26         $this->assertEquals($act->time, 1243860840);
27         $this->assertEquals($act->verb, ActivityVerb::POST);
28
29         $this->assertFalse(empty($act->object));
30         $this->assertEquals($act->object->title, 'Punctuation Changeset');
31         $this->assertEquals($act->object->type, 'http://versioncentral.example.org/activity/changeset');
32         $this->assertEquals($act->object->summary, 'Fixing punctuation because it makes it more readable.');
33         $this->assertEquals($act->object->id, 'tag:versioncentral.example.org,2009:/change/1643245');
34     }
35
36     public function testExample3()
37     {
38         global $_example3;
39         $dom = DOMDocument::loadXML($_example3);
40
41         $feed = $dom->documentElement;
42
43         $entries = $feed->getElementsByTagName('entry');
44
45         $entry = $entries->item(0);
46
47         $act = new Activity($entry, $feed);
48
49         $this->assertFalse(empty($act));
50         $this->assertEquals($act->time, 1071340202);
51         $this->assertEquals($act->link, 'http://example.org/2003/12/13/atom03.html');
52
53         $this->assertEquals($act->verb, ActivityVerb::POST);
54
55         $this->assertFalse(empty($act->actor));
56         $this->assertEquals($act->actor->type, ActivityObject::PERSON);
57         $this->assertEquals($act->actor->title, 'John Doe');
58         $this->assertEquals($act->actor->id, 'mailto:johndoe@example.com');
59
60         $this->assertFalse(empty($act->object));
61         $this->assertEquals($act->object->type, ActivityObject::NOTE);
62         $this->assertEquals($act->object->id, 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a');
63         $this->assertEquals($act->object->title, 'Atom-Powered Robots Run Amok');
64         $this->assertEquals($act->object->summary, 'Some text.');
65         $this->assertEquals($act->object->link, 'http://example.org/2003/12/13/atom03.html');
66
67         $this->assertFalse(empty($act->context));
68
69         $this->assertTrue(empty($act->target));
70
71         $this->assertEquals($act->entry, $entry);
72         $this->assertEquals($act->feed, $feed);
73     }
74
75     public function testExample4()
76     {
77         global $_example4;
78         $dom = DOMDocument::loadXML($_example4);
79
80         $entry = $dom->documentElement;
81
82         $act = new Activity($entry);
83
84         $this->assertFalse(empty($act));
85         $this->assertEquals(1266547958, $act->time);
86         $this->assertEquals('http://example.net/notice/14', $act->link);
87
88         $this->assertFalse(empty($act->context));
89         $this->assertEquals('http://example.net/notice/12', $act->context->replyToID);
90         $this->assertEquals('http://example.net/notice/12', $act->context->replyToUrl);
91         $this->assertEquals('http://example.net/conversation/11', $act->context->conversation);
92         $this->assertEquals(array('http://example.net/user/1'), $act->context->attention);
93
94         $this->assertFalse(empty($act->object));
95         $this->assertEquals($act->object->content,
96                             '@<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>');
97
98         $this->assertFalse(empty($act->actor));
99     }
100 }
101
102 $_example1 = <<<EXAMPLE1
103 <?xml version='1.0' encoding='UTF-8'?>
104 <entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
105   <id>tag:versioncentral.example.org,2009:/commit/1643245</id>
106   <published>2009-06-01T12:54:00Z</published>
107   <title>Geraldine committed a change to yate</title>
108   <content type="xhtml">Geraldine just committed a change to yate on VersionCentral</content>
109   <link rel="alternate" type="text/html"
110         href="http://versioncentral.example.org/geraldine/yate/commit/1643245" />
111   <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
112   <activity:verb>http://versioncentral.example.org/activity/commit</activity:verb>
113   <activity:object>
114     <activity:object-type>http://versioncentral.example.org/activity/changeset</activity:object-type>
115     <id>tag:versioncentral.example.org,2009:/change/1643245</id>
116     <title>Punctuation Changeset</title>
117     <summary>Fixing punctuation because it makes it more readable.</summary>
118     <link rel="alternate" type="text/html" href="..." />
119   </activity:object>
120 </entry>
121 EXAMPLE1;
122
123 $_example2 = <<<EXAMPLE2
124 <?xml version='1.0' encoding='UTF-8'?>
125 <entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
126   <id>tag:photopanic.example.com,2008:activity01</id>
127   <title>Geraldine posted a Photo on PhotoPanic</title>
128   <published>2008-11-02T15:29:00Z</published>
129   <link rel="alternate" type="text/html" href="/geraldine/activities/1" />
130   <activity:verb>
131   http://activitystrea.ms/schema/1.0/post
132   </activity:verb>
133   <activity:object>
134     <id>tag:photopanic.example.com,2008:photo01</id>
135     <title>My Cat</title>
136     <published>2008-11-02T15:29:00Z</published>
137     <link rel="alternate" type="text/html" href="/geraldine/photos/1" />
138     <activity:object-type>
139       tag:atomactivity.example.com,2008:photo
140     </activity:object-type>
141     <source>
142       <title>Geraldine's Photos</title>
143       <link rel="self" type="application/atom+xml" href="/geraldine/photofeed.xml" />
144       <link rel="alternate" type="text/html" href="/geraldine/" />
145     </source>
146   </activity:object>
147   <content type="html">
148      &lt;p&gt;Geraldine posted a Photo on PhotoPanic&lt;/p&gt;
149      &lt;img src="/geraldine/photo1.jpg"&gt;
150   </content>
151 </entry>
152 EXAMPLE2;
153
154 $_example3 = <<<EXAMPLE3
155 <?xml version="1.0" encoding="utf-8"?>
156
157 <feed xmlns="http://www.w3.org/2005/Atom">
158
159         <title>Example Feed</title>
160         <subtitle>A subtitle.</subtitle>
161         <link href="http://example.org/feed/" rel="self" />
162         <link href="http://example.org/" />
163         <id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
164         <updated>2003-12-13T18:30:02Z</updated>
165         <author>
166                 <name>John Doe</name>
167                 <email>johndoe@example.com</email>
168         </author>
169
170         <entry>
171                 <title>Atom-Powered Robots Run Amok</title>
172                 <link href="http://example.org/2003/12/13/atom03" />
173                 <link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>
174                 <link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>
175                 <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
176                 <updated>2003-12-13T18:30:02Z</updated>
177                 <summary>Some text.</summary>
178         </entry>
179
180 </feed>
181 EXAMPLE3;
182
183 $_example4 = <<<EXAMPLE4
184 <?xml version='1.0' encoding='UTF-8'?>
185 <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">
186  <title>@evan now is the time for all good men to come to the aid of their country. #thetime</title>
187  <summary>@evan now is the time for all good men to come to the aid of their country. #thetime</summary>
188 <author>
189  <name>spock</name>
190  <uri>http://example.net/user/2</uri>
191 </author>
192 <activity:actor>
193  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
194  <id>http://example.net/user/2</id>
195  <title>spock</title>
196  <link type="image/png" rel="avatar" href="http://example.net/theme/identica/default-avatar-profile.png"></link>
197 </activity:actor>
198  <link rel="alternate" type="text/html" href="http://example.net/notice/14"/>
199  <id>http://example.net/notice/14</id>
200  <published>2010-02-19T02:52:38+00:00</published>
201  <updated>2010-02-19T02:52:38+00:00</updated>
202  <link rel="related" href="http://example.net/notice/12"/>
203  <thr:in-reply-to ref="http://example.net/notice/12" href="http://example.net/notice/12"></thr:in-reply-to>
204  <link rel="ostatus:conversation" href="http://example.net/conversation/11"/>
205  <link rel="ostatus:attention" href="http://example.net/user/1"/>
206  <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>
207  <category term="thetime"></category>
208 </entry>
209 EXAMPLE4;