]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/Core/UserFeedParseTest.php
[CORE] Make tests great gain
[quix0rs-gnu-social.git] / tests / Core / UserFeedParseTest.php
1 <?php
2 // This file is part of GNU social - https://www.gnu.org/software/social
3 //
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.
8 //
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.
13 //
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/>.
16
17 namespace Tests\Unit;
18
19 if (!defined('INSTALLDIR')) {
20     define('INSTALLDIR', dirname(dirname(__DIR__)));
21 }
22 if (!defined('GNUSOCIAL')) {
23     define('GNUSOCIAL', true);
24 }
25 if (!defined('STATUSNET')) { // Compatibility
26     define('STATUSNET', true);
27 }
28
29 use Activity;
30 use ActivityObject;
31 use DOMDocument;
32 use PHPUnit\Framework\TestCase;
33
34 require_once INSTALLDIR . '/lib/common.php';
35
36 final class UserFeedParseTests extends TestCase
37 {
38     public function testFeed1()
39     {
40         global $_testfeed1;
41         $dom = new DOMDocument();
42         $dom->loadXML($_testfeed1);
43         $this->assertFalse(empty($dom));
44
45         $entries = $dom->getElementsByTagName('entry');
46
47         $entry1 = $entries->item(0);
48         $this->assertFalse(empty($entry1));
49
50         $feedEl = $dom->getElementsByTagName('feed')->item(0);
51         $this->assertFalse(empty($feedEl));
52
53         // Test actor (from activity:subject)
54
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');
62
63         $avatars = $act1->actor->avatarLinks;
64
65         $this->assertEquals(
66             $avatars[0]->url,
67             'http://localhost/statusnet/theme/default/default-avatar-profile.png'
68         );
69
70         $this->assertEquals(
71             $avatars[1]->url,
72             'http://localhost/statusnet/theme/default/default-avatar-stream.png'
73         );
74
75         $this->assertEquals(
76             $avatars[2]->url,
77             'http://localhost/statusnet/theme/default/default-avatar-mini.png'
78         );
79
80         $this->assertEquals($act1->actor->displayName, 'Zach Copley');
81
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');
89
90         // test the post
91
92         //var_export($act1);
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...');
95
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');
98
99     }
100
101 }
102
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>
111 <author>
112  <name>zach</name>
113  <uri>http://localhost/statusnet/user/1</uri>
114
115 </author>
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"/>
122 <activity:subject>
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"/>
130
131 <poco:preferredUsername>zach</poco:preferredUsername>
132 <poco:displayName>Zach Copley</poco:displayName>
133 <poco:note>Zach Hack Attack</poco:note>
134 <poco:address>
135  <poco:formatted>El Cerrito, CA</poco:formatted>
136 </poco:address>
137 <poco:urls>
138  <poco:type>homepage</poco:type>
139  <poco:value>http://zach.copley.name</poco:value>
140  <poco:primary>true</poco:primary>
141
142 </poco:urls>
143 </activity:subject>
144 <entry>
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>
152 </entry>
153
154 </feed>
155 TESTFEED1;