]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/atompub/atompub_test.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / tests / atompub / atompub_test.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - the distributed open-source microblogging tool
5  * Copyright (C) 2010, StatusNet, Inc.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
22
23 $shortoptions = 'n:p:';
24 $longoptions = array('nickname=', 'password=', 'dry-run');
25
26 $helptext = <<<END_OF_HELP
27 USAGE: atompub_test.php [options]
28
29 Runs some tests on the AtomPub interface for the site. You must provide
30 a user account to authenticate as; it will be used to make some test
31 posts on the site.
32
33 Options:
34   -n<user>  --nickname=<user>  Nickname of account to post as
35   -p<pass>  --password=<pass>  Password for account
36   --dry-run                    Skip tests that modify the site (post, delete)
37
38 END_OF_HELP;
39
40 require_once INSTALLDIR.'/scripts/commandline.inc.php';
41
42 $user = get_option_value('n', 'nickname');
43 $pass = get_option_value('p', 'password');
44
45 if (!$user) {
46     die("Must set a user: --nickname=<username>\n");
47 }
48 if (!$pass) {
49     die("Must set a password: --password=<username>\n");
50 }
51
52 // discover the feed...
53 // @fixme will this actually work?
54 $url = common_local_url('ApiTimelineUser', array('format' => 'atom', 'id' => $user));
55
56 echo "Collection URL is: $url\n";
57
58 $collection = new AtomPubClient($url, $user, $pass);
59
60 // confirm the feed has edit links ..... ?
61
62 echo "Posting an empty message (should fail)... ";
63 try {
64     $noticeUrl = $collection->post('');
65     die("FAILED, succeeded!\n");
66 } catch (Exception $e) {
67     echo "ok\n";
68 }
69
70 echo "Posting an invalid XML message (should fail)... ";
71 try {
72     $noticeUrl = $collection->post('<feed<entry>barf</yomomma>');
73     die("FAILED, succeeded!\n");
74 } catch (Exception $e) {
75     echo "ok\n";
76 }
77
78 echo "Posting a valid XML but non-Atom message (should fail)... ";
79 try {
80     $noticeUrl = $collection->post('<feed xmlns="http://notatom.com"><id>arf</id><entry><id>barf</id></entry></feed>');
81     die("FAILED, succeeded!\n");
82 } catch (Exception $e) {
83     echo "ok\n";
84 }
85
86 // post!
87 $rand = mt_rand(0, 99999);
88 $atom = <<<END_ATOM
89 <entry xmlns="http://www.w3.org/2005/Atom">
90     <title>This is an AtomPub test post title ($rand)</title>
91     <content>This is an AtomPub test post content ($rand)</content>
92 </entry>
93 END_ATOM;
94
95 echo "Posting a new message... ";
96 $noticeUrl = $collection->post($atom);
97 echo "ok, got $noticeUrl\n";
98
99 echo "Fetching the new notice... ";
100 $notice = new AtomPubClient($noticeUrl, $user, $pass);
101 $body = $notice->get();
102 AtomPubClient::validateAtomEntry($body);
103 echo "ok\n";
104
105 echo "Getting the notice ID URI... ";
106 $noticeUri = AtomPubClient::entryId($body);
107 echo "ok: $noticeUri\n";
108
109 echo "Confirming new entry points to itself right... ";
110 $editUrl = AtomPubClient::entryEditURL($body);
111 if ($editUrl != $noticeUrl) {
112     die("Entry lists edit URL as $editUrl, no match!\n");
113 }
114 echo "OK\n";
115
116 echo "Refetching the collection... ";
117 $feed = $collection->get();
118 echo "ok\n";
119
120 echo "Confirming new entry is in the feed... ";
121 $entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
122 if (!$entry) {
123     die("missing!\n");
124 }
125 //  edit URL should match
126 echo "ok\n";
127
128 echo "Editing notice (should fail)... ";
129 try {
130     $notice->put($target, $atom2);
131     die("ERROR: editing a notice should have failed.\n");
132 } catch (Exception $e) {
133     echo "ok (failed as expected)\n";
134 }
135
136 echo "Deleting notice... ";
137 $notice->delete();
138 echo "ok\n";
139
140 echo "Refetching deleted notice to confirm it's gone... ";
141 try {
142     $body = $notice->get();
143     var_dump($body);
144     die("ERROR: notice should be gone now.\n");
145 } catch (Exception $e) {
146     echo "ok\n";
147 }
148
149 echo "Refetching the collection.. ";
150 $feed = $collection->get();
151 echo "ok\n";
152
153 echo "Confirming deleted notice is no longer in the feed... ";
154 $entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
155 if ($entry) {
156     die("still there!\n");
157 }
158 echo "ok\n";
159
160 // make subscriptions
161 // make some posts
162 // make sure the posts go through or not depending on the subs
163 // remove subscriptions
164 // test that they don't go through now
165
166 // group memberships too
167
168
169
170
171 // make sure we can't post to someone else's feed!
172 // make sure we can't delete someone else's messages
173 // make sure we can't create/delete someone else's subscriptions
174 // make sure we can't create/delete someone else's group memberships
175