4 * StatusNet - the distributed open-source microblogging tool
5 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
23 $shortoptions = 'n:p:';
24 $longoptions = array('nickname=', 'password=', 'dry-run');
26 $helptext = <<<END_OF_HELP
27 USAGE: atompub_test.php [options]
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
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)
40 require_once INSTALLDIR.'/scripts/commandline.inc';
42 $user = get_option_value('n', 'nickname');
43 $pass = get_option_value('p', 'password');
46 die("Must set a user: --nickname=<username>\n");
49 die("Must set a password: --password=<username>\n");
52 // discover the feed...
53 // @fixme will this actually work?
54 $url = common_local_url('ApiTimelineUser', array('format' => 'atom', 'id' => $user));
56 echo "Collection URL is: $url\n";
58 $collection = new AtomPubClient($url, $user, $pass);
60 // confirm the feed has edit links ..... ?
62 echo "Posting an empty message (should fail)... ";
64 $noticeUrl = $collection->post('');
65 die("FAILED, succeeded!\n");
66 } catch (Exception $e) {
70 echo "Posting an invalid XML message (should fail)... ";
72 $noticeUrl = $collection->post('<feed<entry>barf</yomomma>');
73 die("FAILED, succeeded!\n");
74 } catch (Exception $e) {
78 echo "Posting a valid XML but non-Atom message (should fail)... ";
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) {
87 $rand = mt_rand(0, 99999);
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>
95 echo "Posting a new message... ";
96 $noticeUrl = $collection->post($atom);
97 echo "ok, got $noticeUrl\n";
99 echo "Fetching the new notice... ";
100 $notice = new AtomPubClient($noticeUrl, $user, $pass);
101 $body = $notice->get();
102 AtomPubClient::validateAtomEntry($body);
105 echo "Getting the notice ID URI... ";
106 $noticeUri = AtomPubClient::entryId($body);
107 echo "ok: $noticeUri\n";
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");
116 echo "Refetching the collection... ";
117 $feed = $collection->get();
120 echo "Confirming new entry is in the feed... ";
121 $entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
125 // edit URL should match
128 echo "Editing notice (should fail)... ";
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";
136 echo "Deleting notice... ";
140 echo "Refetching deleted notice to confirm it's gone... ";
142 $body = $notice->get();
144 die("ERROR: notice should be gone now.\n");
145 } catch (Exception $e) {
149 echo "Refetching the collection.. ";
150 $feed = $collection->get();
153 echo "Confirming deleted notice is no longer in the feed... ";
154 $entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
156 die("still there!\n");
160 // make subscriptions
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
166 // group memberships too
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