2 // This file is part of GNU social - https://www.gnu.org/software/social
4 // GNU social is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // GNU social is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
19 if (!defined('INSTALLDIR')) {
20 define('INSTALLDIR', dirname(dirname(__DIR__)));
22 if (!defined('GNUSOCIAL')) {
23 define('GNUSOCIAL', true);
25 if (!defined('STATUSNET')) { // Compatibility
26 define('STATUSNET', true);
32 use PHPUnit\Framework\TestCase;
34 require_once INSTALLDIR . '/lib/common.php';
36 final class UserFeedParseTests extends TestCase
38 public function testFeed1()
41 $dom = new DOMDocument();
42 $dom->loadXML($_testfeed1);
43 $this->assertFalse(empty($dom));
45 $entries = $dom->getElementsByTagName('entry');
47 $entry1 = $entries->item(0);
48 $this->assertFalse(empty($entry1));
50 $feedEl = $dom->getElementsByTagName('feed')->item(0);
51 $this->assertFalse(empty($feedEl));
53 // Test actor (from activity:subject)
55 $act1 = new Activity($entry1, $feedEl);
56 $this->assertFalse(empty($act1));
57 $this->assertFalse(empty($act1->actor));
58 $this->assertEquals($act1->actor->type, ActivityObject::PERSON);
59 $this->assertEquals($act1->actor->title, 'Zach Copley');
60 $this->assertEquals($act1->actor->id, 'http://localhost/statusnet/user/1');
61 $this->assertEquals($act1->actor->link, 'http://localhost/statusnet/zach');
63 $avatars = $act1->actor->avatarLinks;
67 'http://localhost/statusnet/theme/default/default-avatar-profile.png'
72 'http://localhost/statusnet/theme/default/default-avatar-stream.png'
77 'http://localhost/statusnet/theme/default/default-avatar-mini.png'
80 $this->assertEquals($act1->actor->displayName, 'Zach Copley');
82 $poco = $act1->actor->poco;
83 $this->assertEquals($poco->preferredUsername, 'zach');
84 $this->assertEquals($poco->address->formatted, 'El Cerrito, CA');
85 $this->assertEquals($poco->urls[0]->type, 'homepage');
86 $this->assertEquals($poco->urls[0]->value, 'http://zach.copley.name');
87 $this->assertEquals($poco->urls[0]->primary, true);
88 $this->assertEquals($poco->note, 'Zach Hack Attack');
93 $this->assertEquals($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
94 $this->assertEquals($act1->objects[0]->title, 'And now for something completely insane...');
96 $this->assertEquals($act1->objects[0]->content, 'And now for something completely insane...');
97 $this->assertEquals($act1->objects[0]->id, 'http://localhost/statusnet/notice/3');
103 $_testfeed1 = <<<TESTFEED1
104 <?xml version="1.0" encoding="UTF-8"?>
105 <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">
106 <id>http://localhost/statusnet/api/statuses/user_timeline/1.atom</id>
107 <title>zach timeline</title>
108 <subtitle>Updates from zach on Zach Dev!</subtitle>
109 <logo>http://localhost/statusnet/theme/default/default-avatar-profile.png</logo>
110 <updated>2010-03-04T01:41:14+00:00</updated>
113 <uri>http://localhost/statusnet/user/1</uri>
116 <link href="http://localhost/statusnet/zach" rel="alternate" type="text/html"/>
117 <link href="http://localhost/statusnet/main/sup#1" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
118 <link href="http://localhost/statusnet/main/push/hub" rel="hub"/>
119 <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-replies"/>
120 <link href="http://localhost/statusnet/main/salmon/user/1" rel="http://salmon-protocol.org/ns/salmon-mention"/>
121 <link href="http://localhost/statusnet/api/statuses/user_timeline/1.atom" rel="self" type="application/atom+xml"/>
123 <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
124 <id>http://localhost/statusnet/user/1</id>
125 <title>Zach Copley</title>
126 <link rel="alternate" type="text/html" href="http://localhost/statusnet/zach"/>
127 <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://localhost/statusnet/theme/default/default-avatar-profile.png"/>
128 <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://localhost/statusnet/theme/default/default-avatar-stream.png"/>
129 <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://localhost/statusnet/theme/default/default-avatar-mini.png"/>
131 <poco:preferredUsername>zach</poco:preferredUsername>
132 <poco:displayName>Zach Copley</poco:displayName>
133 <poco:note>Zach Hack Attack</poco:note>
135 <poco:formatted>El Cerrito, CA</poco:formatted>
138 <poco:type>homepage</poco:type>
139 <poco:value>http://zach.copley.name</poco:value>
140 <poco:primary>true</poco:primary>
145 <title>And now for something completely insane...</title>
146 <link rel="alternate" type="text/html" href="http://localhost/statusnet/notice/3"/>
147 <id>http://localhost/statusnet/notice/3</id>
148 <published>2010-03-04T01:41:07+00:00</published>
149 <updated>2010-03-04T01:41:07+00:00</updated>
150 <link rel="ostatus:conversation" href="http://localhost/statusnet/conversation/3"/>
151 <content type="html">And now for something completely insane...</content>