die('not for web');
}
+define('HTTP_TIMEOUT', 60); // ssslllloowwwww salmon if queues are off
+
define('INSTALLDIR', dirname(dirname(dirname(dirname(__FILE__)))));
set_include_path(INSTALLDIR . '/extlib' . PATH_SEPARATOR . get_include_path());
/**
* @param string $a base URL of test site A (eg http://localhost/mublog)
* @param string $b base URL of test site B (eg http://localhost/mublog2)
+ * @param int $timeout HTTP timeout value (needs to be long if Salmon is slow)
*/
- function __construct($a, $b) {
+ function __construct($a, $b, $timeout=60) {
$this->a = $a;
$this->b = $b;
$base = 'test' . mt_rand(1, 1000000);
- $this->pub = new SNTestClient($this->a, 'pub' . $base, 'pw-' . mt_rand(1, 1000000));
- $this->sub = new SNTestClient($this->b, 'sub' . $base, 'pw-' . mt_rand(1, 1000000));
+ $this->pub = new SNTestClient($this->a, 'pub' . $base, 'pw-' . mt_rand(1, 1000000), $timeout);
+ $this->sub = new SNTestClient($this->b, 'sub' . $base, 'pw-' . mt_rand(1, 1000000), $timeout);
+
+ $this->group = 'group' . $base;
}
function run()
{
$this->setup();
- $this->testLocalPost();
- $this->testMentionUrl();
- $this->testSubscribe();
- $this->testUnsubscribe();
+ $methods = get_class_methods($this);
+ foreach ($methods as $method) {
+ if (strtolower(substr($method, 0, 4)) == 'test') {
+ print "\n";
+ print "== $method ==\n";
+ call_user_func(array($this, $method));
+ }
+ }
+ print "\n";
$this->log("DONE!");
}
$this->assertTrue($this->pub->hasSubscriber($this->sub->getProfileUri()));
}
+ function testPush()
+ {
+ $this->assertTrue($this->sub->hasSubscription($this->pub->getProfileUri()));
+ $this->assertTrue($this->pub->hasSubscriber($this->sub->getProfileUri()));
+
+ $name = $this->sub->username;
+ $post = $this->pub->post("Regular post, which $name should get via PuSH");
+ $this->sub->assertReceived($post);
+ }
+
+ function testMentionSubscribee()
+ {
+ $this->assertTrue($this->sub->hasSubscription($this->pub->getProfileUri()));
+ $this->assertFalse($this->pub->hasSubscription($this->sub->getProfileUri()));
+
+ $name = $this->pub->username;
+ $post = $this->sub->post("Just a quick note back to my remote subscribee @$name");
+ $this->pub->assertReceived($post);
+ }
+
function testUnsubscribe()
{
$this->assertTrue($this->sub->hasSubscription($this->pub->getProfileUri()));
$this->assertFalse($this->pub->hasSubscriber($this->sub->getProfileUri()));
}
+ function testCreateGroup()
+ {
+ $this->groupUrl = $this->pub->createGroup($this->group);
+ $this->assertTrue(!empty($this->groupUrl));
+ }
+
+ function testJoinGroup()
+ {
+ #$this->assertFalse($this->sub->inGroup($this->groupUrl));
+ $this->sub->joinGroup($this->groupUrl);
+ #$this->assertTrue($this->sub->inGroup($this->groupUrl));
+ }
+
+ function testLocalGroupPost()
+ {
+ $post = $this->pub->post("Group post from local to !{$this->group}, should go out over push.");
+ $this->assertNotEqual('', $post);
+ $this->sub->assertReceived($post);
+ }
+
+ function testRemoteGroupPost()
+ {
+ $post = $this->sub->post("Group post from remote to !{$this->group}, should come in over salmon.");
+ $this->assertNotEqual('', $post);
+ $this->pub->assertReceived($post);
+ }
+
+ function testLeaveGroup()
+ {
+ #$this->assertTrue($this->sub->inGroup($this->groupUrl));
+ $this->sub->leaveGroup($this->groupUrl);
+ #$this->assertFalse($this->sub->inGroup($this->groupUrl));
+ }
}
class SNTestClient extends TestBase
{
- function __construct($base, $username, $password)
+ function __construct($base, $username, $password, $timeout=60)
{
$this->basepath = $base;
$this->username = $username;
$this->password = $password;
+ $this->timeout = $timeout;
$this->fullname = ucfirst($username) . ' Smith';
$this->homepage = 'http://example.org/' . $username;
{
$url = $this->basepath . '/' . $path;
- $http = new HTTP_Request2($url, 'POST');
+ $http = new HTTP_Request2($url, 'POST', array('timeout' => $this->timeout));
if ($auth) {
$http->setAuth($this->username, $this->password, HTTP_Request2::AUTH_BASIC);
}
protected function web($path, $form, $params=array())
{
$url = $this->basepath . '/' . $path;
- $http = new HTTP_Request2($url, 'GET');
+ $http = new HTTP_Request2($url, 'GET', array('timeout' => $this->timeout));
$response = $http->send();
$dom = $this->checkWeb($url, 'GET', $response);
$this->assertEqual($this->fullname, $data['name']);
$this->assertEqual($this->homepage, $data['url']);
$this->assertEqual($this->bio, $data['description']);
+ $this->log(" looks good!");
}
/**
}
$tries--;
if ($tries) {
- $this->log("Didn't see it yet, waiting $timeout seconds");
+ $this->log(" didn't see it yet, waiting $timeout seconds");
sleep($timeout);
}
}
- throw new Exception("Message $notice_uri not received by $this->username");
+ throw new Exception(" message $notice_uri not received by $this->username");
}
/**
}
foreach ($entries as $entry) {
if ($entry->id == $notice_uri) {
- $this->log("found it $notice_uri");
+ $this->log(" found it $notice_uri");
return true;
}
- //$this->log("nope... " . $entry->id);
}
return false;
}
$me = $this->getProfileUri();
return $this->checkSubscription($profile_uri, $me);
}
-
+
protected function checkSubscription($subscriber, $subscribed)
{
// Using FOAF as the API methods for checking the social graph
foreach ($follows as $follow) {
$target = $follow->getAttributeNS($ns_rdf, 'resource');
if ($target == ($subscribed . '#acct')) {
- $this->log("Confirmed $subscriber subscribed to $subscribed");
+ $this->log(" confirmed $subscriber subscribed to $subscribed");
return true;
}
}
- $this->log("We found $subscriber but they don't follow $subscribed");
+ $this->log(" we found $subscriber but they don't follow $subscribed");
return false;
}
}
- $this->log("Can't find $subscriber in {$this->username}'s social graph.");
+ $this->log(" can't find $subscriber in {$this->username}'s social graph.");
return false;
}
+ /**
+ * Create a group on this site.
+ *
+ * @param string $nickname
+ * @param array $options
+ * @return string: profile URL for the group
+ */
+ function createGroup($nickname, $options=array()) {
+ $this->log("Creating group as %s on %s: %s",
+ $this->username,
+ $this->basepath,
+ $nickname);
+
+ $data = $this->api('statusnet/groups/create', 'json',
+ array_merge(array('nickname' => $nickname), $options));
+ $url = $data['url'];
+
+ if ($url) {
+ $this->log(' created as %s', $url);
+ } else {
+ $this->log(' failed? %s', var_export($data, true));
+ }
+ return $url;
+ }
+
+ function groupInfo($nickname) {
+ $data = $this->api('statusnet/groups/show', 'json', array(
+ 'id' => $nickname
+ ));
+ }
+
+ /**
+ * Join a group.
+ *
+ * @param string $group nickname or URL
+ */
+ function joinGroup($group) {
+ $this->post('join ' . $group);
+ }
+
+ /**
+ * Leave a group.
+ *
+ * @param string $group nickname or URL
+ */
+ function leaveGroup($group) {
+ $this->post('drop ' . $group);
+ }
+
+ /**
+ *
+ * @param string $nickname
+ * @return
+ */
+ function inGroup($nickname) {
+ // @todo
+ }
}
-$args = array_slice($_SERVER['argv'], 1);
+// @fixme switch to commandline.inc?
+$timeout = HTTP_TIMEOUT;
+
+$args = array();
+$options = array();
+foreach (array_slice($_SERVER['argv'], 1) as $arg) {
+ if (substr($arg, 0, 2) == '--') {
+ $bits = explode('=', substr($arg, 2), 2);
+ if (count($bits == 2)) {
+ list($key, $val) = $bits;
+ $options[$key] = $val;
+ } else {
+ list($key) = $bits;
+ $options[$key] = true;
+ }
+ } else {
+ $args[] = $arg;
+ }
+}
if (count($args) < 2) {
print <<<END_HELP
-remote-tests.php <url1> <url2>
+remote-tests.php [options] <url1> <url2>
+ --timeout=## change HTTP timeout from default {$timeout}s
url1: base URL of a StatusNet instance
url2: base URL of another StatusNet instance
$a = $args[0];
$b = $args[1];
+if (isset($options['timeout'])) {
+ $timeout = intval($options['timeout']);
+}
-$tester = new OStatusTester($a, $b);
+$tester = new OStatusTester($a, $b, $timeout);
$tester->run();
-