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