]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/UserFeedParseTest.php
Merge branch 'master' of git@gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / tests / UserFeedParseTest.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 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('STATUSNET', true);
10
11 require_once INSTALLDIR . '/lib/common.php';
12
13 class UserFeedParseTests extends PHPUnit_Framework_TestCase
14 {
15     public function testFeed1()
16     {
17         global $_testfeed1;
18         $dom = DOMDocument::loadXML($_testfeed1);
19         $this->assertFalse(empty($dom));
20
21         $entries = $dom->getElementsByTagName('entry');
22
23         $entry1 = $entries->item(0);
24         $this->assertFalse(empty($entry1));
25
26         $feedEl = $dom->getElementsByTagName('feed')->item(0);
27         $this->assertFalse(empty($feedEl));
28
29         // Test actor (from activity:subject)
30
31         $act1 = new Activity($entry1, $feedEl);
32         $this->assertFalse(empty($act1));
33         $this->assertFalse(empty($act1->actor));
34         $this->assertEquals($act1->actor->type, ActivityObject::PERSON);
35         $this->assertEquals($act1->actor->title, 'Zach Copley');
36         $this->assertEquals($act1->actor->id, 'http://localhost/statusnet/user/1');
37         $this->assertEquals($act1->actor->link, 'http://localhost/statusnet/zach');
38
39         $avatars = $act1->actor->avatarLinks;
40
41         $this->assertEquals(
42                 $avatars[0]->url,
43                 'http://localhost/statusnet/theme/default/default-avatar-profile.png'
44         );
45
46         $this->assertEquals(
47                 $avatars[1]->url,
48                 'http://localhost/statusnet/theme/default/default-avatar-stream.png'
49         );
50
51         $this->assertEquals(
52                 $avatars[2]->url,
53                 'http://localhost/statusnet/theme/default/default-avatar-mini.png'
54         );
55
56         $this->assertEquals($act1->actor->displayName, 'Zach Copley');
57
58         $poco = $act1->actor->poco;
59         $this->assertEquals($poco->preferredUsername, 'zach');
60         $this->assertEquals($poco->address->formatted, 'El Cerrito, CA');
61         $this->assertEquals($poco->urls[0]->type, 'homepage');
62         $this->assertEquals($poco->urls[0]->value, 'http://zach.copley.name');
63         $this->assertEquals($poco->urls[0]->primary, 'true');
64         $this->assertEquals($poco->note, 'Zach Hack Attack');
65
66         // test the post
67
68         //var_export($act1);
69         $this->assertEquals($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
70         $this->assertEquals($act1->objects[0]->title, 'And now for something completely insane...');
71
72         $this->assertEquals($act1->objects[0]->content, 'And now for something completely insane...');
73         $this->assertEquals($act1->objects[0]->id, 'http://localhost/statusnet/notice/3');
74
75     }
76
77 }
78
79 $_testfeed1 = <<<TESTFEED1
80 <?xml version="1.0" encoding="UTF-8"?>
81 <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:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
82  <id>http://localhost/statusnet/api/statuses/user_timeline/1.atom</id>
83  <title>zach timeline</title>
84  <subtitle>Updates from zach on Zach Dev!</subtitle>
85  <logo>http://localhost/statusnet/theme/default/default-avatar-profile.png</logo>
86  <updated>2010-03-04T01:41:14+00:00</updated>
87 <author>
88  <name>zach</name>
89  <uri>http://localhost/statusnet/user/1</uri>
90
91 </author>
92  <link href="http://localhost/statusnet/zach" rel="alternate" type="text/html"/>
93  <link href="http://localhost/statusnet/main/sup#1" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
94  <link href="http://localhost/statusnet/main/push/hub" rel="hub"/>
95  <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-replies"/>
96  <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-mention"/>
97  <link href="http://localhost/statusnet/api/statuses/user_timeline/1.atom" rel="self" type="application/atom+xml"/>
98 <activity:subject>
99  <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
100  <id>http://localhost/statusnet/user/1</id>
101  <title>Zach Copley</title>
102  <link rel="alternate" type="text/html" href="http://localhost/statusnet/zach"/>
103  <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://localhost/statusnet/theme/default/default-avatar-profile.png"/>
104  <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://localhost/statusnet/theme/default/default-avatar-stream.png"/>
105  <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://localhost/statusnet/theme/default/default-avatar-mini.png"/>
106
107 <poco:preferredUsername>zach</poco:preferredUsername>
108 <poco:displayName>Zach Copley</poco:displayName>
109 <poco:note>Zach Hack Attack</poco:note>
110 <poco:address>
111  <poco:formatted>El Cerrito, CA</poco:formatted>
112 </poco:address>
113 <poco:urls>
114  <poco:type>homepage</poco:type>
115  <poco:value>http://zach.copley.name</poco:value>
116  <poco:primary>true</poco:primary>
117
118 </poco:urls>
119 </activity:subject>
120 <entry>
121  <title>And now for something completely insane...</title>
122  <link rel="alternate" type="text/html" href="http://localhost/statusnet/notice/3"/>
123  <id>http://localhost/statusnet/notice/3</id>
124  <published>2010-03-04T01:41:07+00:00</published>
125  <updated>2010-03-04T01:41:07+00:00</updated>
126  <link rel="ostatus:conversation" href="http://localhost/statusnet/conversation/3"/>
127  <content type="html">And now for something completely insane...</content>
128 </entry>
129
130 </feed>
131 TESTFEED1;