#!/usr/bin/env php . */ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..')); $shortoptions = 'n:p:'; $longoptions = array('nickname=', 'password=', 'dry-run'); $helptext = << --nickname= Nickname of account to post as -p --password= Password for account --dry-run Skip tests that modify the site (post, delete) END_OF_HELP; require_once INSTALLDIR.'/scripts/commandline.inc'; $user = get_option_value('n', 'nickname'); $pass = get_option_value('p', 'password'); if (!$user) { die("Must set a user: --nickname=\n"); } if (!$pass) { die("Must set a password: --password=\n"); } // discover the feed... // @fixme will this actually work? $url = common_local_url('ApiTimelineUser', array('format' => 'atom', 'id' => $user)); echo "Collection URL is: $url\n"; $collection = new AtomPubClient($url, $user, $pass); // confirm the feed has edit links ..... ? echo "Posting an empty message (should fail)... "; try { $noticeUrl = $collection->post(''); die("FAILED, succeeded!\n"); } catch (Exception $e) { echo "ok\n"; } echo "Posting an invalid XML message (should fail)... "; try { $noticeUrl = $collection->post('barf'); die("FAILED, succeeded!\n"); } catch (Exception $e) { echo "ok\n"; } echo "Posting a valid XML but non-Atom message (should fail)... "; try { $noticeUrl = $collection->post('arfbarf'); die("FAILED, succeeded!\n"); } catch (Exception $e) { echo "ok\n"; } // post! $rand = mt_rand(0, 99999); $atom = << This is an AtomPub test post title ($rand) This is an AtomPub test post content ($rand) END_ATOM; echo "Posting a new message... "; $noticeUrl = $collection->post($atom); echo "ok, got $noticeUrl\n"; echo "Fetching the new notice... "; $notice = new AtomPubClient($noticeUrl, $user, $pass); $body = $notice->get(); AtomPubClient::validateAtomEntry($body); echo "ok\n"; echo "Getting the notice ID URI... "; $noticeUri = AtomPubClient::entryId($body); echo "ok: $noticeUri\n"; echo "Confirming new entry points to itself right... "; $editUrl = AtomPubClient::entryEditURL($body); if ($editUrl != $noticeUrl) { die("Entry lists edit URL as $editUrl, no match!\n"); } echo "OK\n"; echo "Refetching the collection... "; $feed = $collection->get(); echo "ok\n"; echo "Confirming new entry is in the feed... "; $entry = AtomPubClient::getEntryInFeed($feed, $noticeUri); if (!$entry) { die("missing!\n"); } // edit URL should match echo "ok\n"; echo "Editing notice (should fail)... "; try { $notice->put($target, $atom2); die("ERROR: editing a notice should have failed.\n"); } catch (Exception $e) { echo "ok (failed as expected)\n"; } echo "Deleting notice... "; $notice->delete(); echo "ok\n"; echo "Refetching deleted notice to confirm it's gone... "; try { $body = $notice->get(); var_dump($body); die("ERROR: notice should be gone now.\n"); } catch (Exception $e) { echo "ok\n"; } echo "Refetching the collection.. "; $feed = $collection->get(); echo "ok\n"; echo "Confirming deleted notice is no longer in the feed... "; $entry = AtomPubClient::getEntryInFeed($feed, $noticeUri); if ($entry) { die("still there!\n"); } echo "ok\n"; // make subscriptions // make some posts // make sure the posts go through or not depending on the subs // remove subscriptions // test that they don't go through now // group memberships too // make sure we can't post to someone else's feed! // make sure we can't delete someone else's messages // make sure we can't create/delete someone else's subscriptions // make sure we can't create/delete someone else's group memberships