3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4 print "This script must be run from the command line\n";
8 // XXX: we should probably have some common source for this stuff
10 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
11 define('STATUSNET', true);
13 require_once INSTALLDIR . '/lib/common.php';
14 require_once INSTALLDIR . '/plugins/OStatus/lib/activity.php';
16 class ActivityParseTests extends PHPUnit_Framework_TestCase
18 public function testExample1()
21 $dom = DOMDocument::loadXML($_example1);
22 $act = new Activity($dom->documentElement);
24 $this->assertFalse(empty($act));
26 $this->assertEquals($act->time, 1243860840);
27 $this->assertEquals($act->verb, ActivityVerb::POST);
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');
36 public function testExample3()
39 $dom = DOMDocument::loadXML($_example3);
41 $feed = $dom->documentElement;
43 $entries = $feed->getElementsByTagName('entry');
45 $entry = $entries->item(0);
47 $act = new Activity($entry, $feed);
49 $this->assertFalse(empty($act));
50 $this->assertEquals($act->time, 1071340202);
51 $this->assertEquals($act->link, 'http://example.org/2003/12/13/atom03.html');
53 $this->assertEquals($act->verb, ActivityVerb::POST);
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');
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');
67 $this->assertFalse(empty($act->context));
69 $this->assertTrue(empty($act->target));
71 $this->assertEquals($act->entry, $entry);
72 $this->assertEquals($act->feed, $feed);
75 public function testExample4()
78 $dom = DOMDocument::loadXML($_example4);
80 $entry = $dom->documentElement;
82 $act = new Activity($entry);
84 $this->assertFalse(empty($act));
85 $this->assertEquals(1266547958, $act->time);
86 $this->assertEquals('http://example.net/notice/14', $act->link);
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);
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>');
98 $this->assertFalse(empty($act->actor));
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>
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="..." />
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" />
131 http://activitystrea.ms/schema/1.0/post
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>
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/" />
147 <content type="html">
148 <p>Geraldine posted a Photo on PhotoPanic</p>
149 <img src="/geraldine/photo1.jpg">
154 $_example3 = <<<EXAMPLE3
155 <?xml version="1.0" encoding="utf-8"?>
157 <feed xmlns="http://www.w3.org/2005/Atom">
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>
166 <name>John Doe</name>
167 <email>johndoe@example.com</email>
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>
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>
190 <uri>http://example.net/user/2</uri>
193 <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
194 <id>http://example.net/user/2</id>
196 <link type="image/png" rel="avatar" href="http://example.net/theme/identica/default-avatar-profile.png"></link>
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">@<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></content>
207 <category term="thetime"></category>