2010-08-04 05:41:44 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
|
|
|
print "This script must be run from the command line\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: we should probably have some common source for this stuff
|
|
|
|
|
|
|
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
|
2013-09-28 22:20:10 +09:00
|
|
|
define('GNUSOCIAL', true);
|
|
|
|
define('STATUSNET', true); // compatibility
|
2010-08-04 05:41:44 +09:00
|
|
|
|
|
|
|
require_once INSTALLDIR . '/lib/common.php';
|
|
|
|
|
|
|
|
class ActivityGenerationTests extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
var $author1 = null;
|
|
|
|
var $author2 = null;
|
|
|
|
|
|
|
|
var $targetUser1 = null;
|
|
|
|
var $targetUser2 = null;
|
|
|
|
|
|
|
|
var $targetGroup1 = null;
|
|
|
|
var $targetGroup2 = null;
|
|
|
|
|
2010-08-04 06:17:36 +09:00
|
|
|
function __construct()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2010-08-04 06:17:36 +09:00
|
|
|
parent::__construct();
|
2010-08-04 05:41:44 +09:00
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$authorNick1 = 'activitygenerationtestsuser' . common_random_hexstr(4);
|
|
|
|
$authorNick2 = 'activitygenerationtestsuser' . common_random_hexstr(4);
|
2010-08-04 05:41:44 +09:00
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$targetNick1 = 'activitygenerationteststarget' . common_random_hexstr(4);
|
|
|
|
$targetNick2 = 'activitygenerationteststarget' . common_random_hexstr(4);
|
2010-08-04 06:17:36 +09:00
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$groupNick1 = 'activitygenerationtestsgroup' . common_random_hexstr(4);
|
|
|
|
$groupNick2 = 'activitygenerationtestsgroup' . common_random_hexstr(4);
|
2010-08-04 05:41:44 +09:00
|
|
|
|
|
|
|
$this->author1 = User::register(array('nickname' => $authorNick1,
|
|
|
|
'email' => $authorNick1 . '@example.net',
|
|
|
|
'email_confirmed' => true));
|
|
|
|
|
|
|
|
$this->author2 = User::register(array('nickname' => $authorNick2,
|
|
|
|
'email' => $authorNick2 . '@example.net',
|
|
|
|
'email_confirmed' => true));
|
|
|
|
|
|
|
|
$this->targetUser1 = User::register(array('nickname' => $targetNick1,
|
|
|
|
'email' => $targetNick1 . '@example.net',
|
|
|
|
'email_confirmed' => true));
|
|
|
|
|
|
|
|
$this->targetUser2 = User::register(array('nickname' => $targetNick2,
|
|
|
|
'email' => $targetNick2 . '@example.net',
|
|
|
|
'email_confirmed' => true));
|
|
|
|
|
2010-08-04 06:17:36 +09:00
|
|
|
$this->targetGroup1 = User_group::register(array('nickname' => $groupNick1,
|
|
|
|
'userid' => $this->author1->id,
|
|
|
|
'aliases' => array(),
|
|
|
|
'local' => true,
|
|
|
|
'location' => null,
|
|
|
|
'description' => null,
|
|
|
|
'fullname' => null,
|
|
|
|
'homepage' => null,
|
|
|
|
'mainpage' => null));
|
|
|
|
$this->targetGroup2 = User_group::register(array('nickname' => $groupNick2,
|
|
|
|
'userid' => $this->author1->id,
|
|
|
|
'aliases' => array(),
|
|
|
|
'local' => true,
|
|
|
|
'location' => null,
|
|
|
|
'description' => null,
|
|
|
|
'fullname' => null,
|
|
|
|
'homepage' => null,
|
|
|
|
'mainpage' => null));
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicNoticeActivity()
|
|
|
|
{
|
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(true);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, false);
|
|
|
|
|
|
|
|
$this->assertEquals($notice->uri, ActivityUtils::childContent($element, 'id'));
|
|
|
|
$this->assertEquals($notice->content, ActivityUtils::childContent($element, 'title'));
|
|
|
|
$this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content'));
|
|
|
|
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published')));
|
|
|
|
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated')));
|
|
|
|
$this->assertEquals(ActivityVerb::POST, ActivityUtils::childContent($element, 'verb', Activity::SPEC));
|
|
|
|
$this->assertEquals(ActivityObject::NOTE, ActivityUtils::childContent($element, 'object-type', Activity::SPEC));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNamespaceFlag()
|
|
|
|
{
|
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(true);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, false);
|
|
|
|
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns'));
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns:thr'));
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns:georss'));
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns:activity'));
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns:media'));
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns:poco'));
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns:ostatus'));
|
|
|
|
$this->assertTrue($element->hasAttribute('xmlns:statusnet'));
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns'));
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns:thr'));
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns:georss'));
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns:activity'));
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns:media'));
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns:poco'));
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns:ostatus'));
|
|
|
|
$this->assertFalse($element->hasAttribute('xmlns:statusnet'));
|
|
|
|
}
|
|
|
|
|
2010-08-04 06:17:36 +09:00
|
|
|
public function testSourceFlag()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2010-08-04 06:17:36 +09:00
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
// Test with no source
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$source = ActivityUtils::child($element, 'source');
|
|
|
|
|
|
|
|
$this->assertNull($source);
|
|
|
|
|
|
|
|
// Test with source
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, true);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$source = ActivityUtils::child($element, 'source');
|
|
|
|
|
|
|
|
$this->assertNotNull($source);
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
2010-08-04 06:17:36 +09:00
|
|
|
public function testSourceContent()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2010-08-04 06:17:36 +09:00
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
// make a time difference!
|
|
|
|
sleep(2);
|
|
|
|
$notice2 = $this->_fakeNotice();
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, true);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$source = ActivityUtils::child($element, 'source');
|
|
|
|
|
|
|
|
$atomUrl = common_local_url('ApiTimelineUser', array('id' => $this->author1->id, 'format' => 'atom'));
|
|
|
|
|
|
|
|
$profile = $this->author1->getProfile();
|
|
|
|
|
|
|
|
$this->assertEquals($atomUrl, ActivityUtils::childContent($source, 'id'));
|
|
|
|
$this->assertEquals($atomUrl, ActivityUtils::getLink($source, 'self', 'application/atom+xml'));
|
|
|
|
$this->assertEquals($profile->profileurl, ActivityUtils::getPermalink($source));
|
2010-08-04 07:49:49 +09:00
|
|
|
$this->assertEquals(strtotime($notice2->created), strtotime(ActivityUtils::childContent($source, 'updated')));
|
2010-08-04 06:17:36 +09:00
|
|
|
// XXX: do we care here?
|
|
|
|
$this->assertFalse(is_null(ActivityUtils::childContent($source, 'title')));
|
|
|
|
$this->assertEquals(common_config('license', 'url'), ActivityUtils::getLink($source, 'license'));
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
2010-08-04 06:17:36 +09:00
|
|
|
public function testAuthorFlag()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2010-08-04 06:17:36 +09:00
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
// Test with no author
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, false);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$this->assertNull(ActivityUtils::child($element, 'author'));
|
|
|
|
$this->assertNull(ActivityUtils::child($element, 'actor', Activity::SPEC));
|
|
|
|
|
|
|
|
// Test with source
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, true);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$author = ActivityUtils::child($element, 'author');
|
|
|
|
$actor = ActivityUtils::child($element, 'actor', Activity::SPEC);
|
|
|
|
|
|
|
|
$this->assertFalse(is_null($author));
|
2010-12-31 06:21:59 +09:00
|
|
|
$this->assertTrue(is_null($actor)); // <activity:actor> is obsolete, no longer added
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
2010-08-04 07:26:19 +09:00
|
|
|
public function testAuthorContent()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2010-08-04 07:26:19 +09:00
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
// Test with author
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, true);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$author = ActivityUtils::child($element, 'author');
|
|
|
|
|
|
|
|
$this->assertEquals($this->author1->nickname, ActivityUtils::childContent($author, 'name'));
|
|
|
|
$this->assertEquals($this->author1->uri, ActivityUtils::childContent($author, 'uri'));
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
2010-12-31 06:21:59 +09:00
|
|
|
/**
|
|
|
|
* We no longer create <activity:actor> entries, they have merged to <atom:author>
|
|
|
|
*/
|
2010-08-04 07:49:49 +09:00
|
|
|
public function testActorContent()
|
|
|
|
{
|
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
// Test with author
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, true);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$actor = ActivityUtils::child($element, 'actor', Activity::SPEC);
|
|
|
|
|
2010-12-31 06:21:59 +09:00
|
|
|
$this->assertEquals($actor, null);
|
2010-08-04 07:49:49 +09:00
|
|
|
}
|
|
|
|
|
2010-08-04 06:17:36 +09:00
|
|
|
public function testReplyLink()
|
|
|
|
{
|
|
|
|
$orig = $this->_fakeNotice($this->targetUser1);
|
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$reply = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
|
|
|
|
|
|
|
$entry = $reply->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$irt = ActivityUtils::child($element, 'in-reply-to', 'http://purl.org/syndication/thread/1.0');
|
|
|
|
|
|
|
|
$this->assertNotNull($irt);
|
|
|
|
$this->assertEquals($orig->uri, $irt->getAttribute('ref'));
|
|
|
|
$this->assertEquals($orig->bestUrl(), $irt->getAttribute('href'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReplyAttention()
|
|
|
|
{
|
|
|
|
$orig = $this->_fakeNotice($this->targetUser1);
|
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$reply = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
|
|
|
|
|
|
|
$entry = $reply->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
2010-08-04 08:04:19 +09:00
|
|
|
$this->assertEquals($this->targetUser1->uri, ActivityUtils::getLink($element, 'mentioned'));
|
2010-08-04 06:17:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMultipleReplyAttention()
|
|
|
|
{
|
|
|
|
$orig = $this->_fakeNotice($this->targetUser1);
|
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$reply = Notice::saveNew($this->targetUser2->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "@" . $this->targetUser1->nickname . " @" . $this->targetUser2->nickname . " reply text " . common_random_hexstr(4);
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$reply2 = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $reply->id));
|
|
|
|
|
|
|
|
$entry = $reply2->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
2013-10-22 01:42:15 +09:00
|
|
|
$links = ActivityUtils::getLinks($element, 'mentioned');
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$this->assertEquals(2, count($links));
|
|
|
|
|
|
|
|
$hrefs = array();
|
|
|
|
|
|
|
|
foreach ($links as $link) {
|
|
|
|
$hrefs[] = $link->getAttribute('href');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue(in_array($this->targetUser1->uri, $hrefs));
|
|
|
|
$this->assertTrue(in_array($this->targetUser2->uri, $hrefs));
|
2010-08-04 08:04:19 +09:00
|
|
|
|
|
|
|
$links = ActivityUtils::getLinks($element, 'mentioned');
|
|
|
|
|
|
|
|
$this->assertEquals(2, count($links));
|
|
|
|
|
|
|
|
$hrefs = array();
|
|
|
|
|
|
|
|
foreach ($links as $link) {
|
|
|
|
$hrefs[] = $link->getAttribute('href');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue(in_array($this->targetUser1->uri, $hrefs));
|
|
|
|
$this->assertTrue(in_array($this->targetUser2->uri, $hrefs));
|
2010-08-04 06:17:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGroupPostAttention()
|
|
|
|
{
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "!" . $this->targetGroup1->nickname . " reply text " . common_random_hexstr(4);
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$notice = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null));
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
2010-08-04 08:04:19 +09:00
|
|
|
$this->assertEquals($this->targetGroup1->uri, ActivityUtils::getLink($element, 'mentioned'));
|
2010-08-04 06:17:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMultipleGroupPostAttention()
|
|
|
|
{
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "!" . $this->targetGroup1->nickname . " !" . $this->targetGroup2->nickname . " reply text " . common_random_hexstr(4);
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$notice = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null));
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
2013-10-22 01:42:15 +09:00
|
|
|
$links = ActivityUtils::getLinks($element, 'mentioned');
|
2010-08-04 06:17:36 +09:00
|
|
|
|
|
|
|
$this->assertEquals(2, count($links));
|
|
|
|
|
|
|
|
$hrefs = array();
|
|
|
|
|
|
|
|
foreach ($links as $link) {
|
|
|
|
$hrefs[] = $link->getAttribute('href');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue(in_array($this->targetGroup1->uri, $hrefs));
|
|
|
|
$this->assertTrue(in_array($this->targetGroup2->uri, $hrefs));
|
2010-08-04 08:04:19 +09:00
|
|
|
|
|
|
|
$links = ActivityUtils::getLinks($element, 'mentioned');
|
|
|
|
|
|
|
|
$this->assertEquals(2, count($links));
|
|
|
|
|
|
|
|
$hrefs = array();
|
|
|
|
|
|
|
|
foreach ($links as $link) {
|
|
|
|
$hrefs[] = $link->getAttribute('href');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue(in_array($this->targetGroup1->uri, $hrefs));
|
|
|
|
$this->assertTrue(in_array($this->targetGroup2->uri, $hrefs));
|
2010-08-04 06:17:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRepeatLink()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2010-08-04 07:26:19 +09:00
|
|
|
$notice = $this->_fakeNotice($this->author1);
|
|
|
|
$repeat = $notice->repeat($this->author2->id, 'test');
|
|
|
|
|
|
|
|
$entry = $repeat->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$forward = ActivityUtils::child($element, 'forward', "http://ostatus.org/schema/1.0");
|
|
|
|
|
|
|
|
$this->assertNotNull($forward);
|
|
|
|
$this->assertEquals($notice->uri, $forward->getAttribute('ref'));
|
|
|
|
$this->assertEquals($notice->bestUrl(), $forward->getAttribute('href'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTag()
|
|
|
|
{
|
2013-10-21 20:20:30 +09:00
|
|
|
$tag1 = common_random_hexstr(4);
|
2010-08-04 07:26:19 +09:00
|
|
|
|
|
|
|
$notice = $this->_fakeNotice($this->author1, '#' . $tag1);
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$category = ActivityUtils::child($element, 'category');
|
|
|
|
|
|
|
|
$this->assertNotNull($category);
|
|
|
|
$this->assertEquals($tag1, $category->getAttribute('term'));
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
2010-08-04 07:26:19 +09:00
|
|
|
public function testMultiTag()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2013-10-21 20:20:30 +09:00
|
|
|
$tag1 = common_random_hexstr(4);
|
|
|
|
$tag2 = common_random_hexstr(4);
|
2010-08-04 07:26:19 +09:00
|
|
|
|
|
|
|
$notice = $this->_fakeNotice($this->author1, '#' . $tag1 . ' #' . $tag2);
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$categories = $element->getElementsByTagName('category');
|
|
|
|
|
|
|
|
$this->assertNotNull($categories);
|
|
|
|
$this->assertEquals(2, $categories->length);
|
|
|
|
|
|
|
|
$terms = array();
|
|
|
|
|
|
|
|
for ($i = 0; $i < $categories->length; $i++) {
|
|
|
|
$cat = $categories->item($i);
|
|
|
|
$terms[] = $cat->getAttribute('term');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue(in_array($tag1, $terms));
|
|
|
|
$this->assertTrue(in_array($tag2, $terms));
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGeotaggedActivity()
|
|
|
|
{
|
2013-10-21 20:20:30 +09:00
|
|
|
$notice = Notice::saveNew($this->author1->id, common_random_hexstr(4), 'test', array('uri' => null, 'lat' => 45.5, 'lon' => -73.6));
|
2010-08-04 07:26:19 +09:00
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$this->assertEquals('45.5 -73.6', ActivityUtils::childContent($element, 'point', "http://www.georss.org/georss"));
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
2010-08-04 06:17:36 +09:00
|
|
|
public function testNoticeInfo()
|
2010-08-04 05:41:44 +09:00
|
|
|
{
|
2010-08-04 07:26:19 +09:00
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
|
|
|
|
|
|
|
$this->assertEquals($notice->id, $noticeInfo->getAttribute('local_id'));
|
|
|
|
$this->assertEquals($notice->source, $noticeInfo->getAttribute('source'));
|
|
|
|
$this->assertEquals('', $noticeInfo->getAttribute('repeat_of'));
|
|
|
|
$this->assertEquals('', $noticeInfo->getAttribute('repeated'));
|
|
|
|
$this->assertEquals('', $noticeInfo->getAttribute('favorite'));
|
|
|
|
$this->assertEquals('', $noticeInfo->getAttribute('source_link'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoticeInfoRepeatOf()
|
|
|
|
{
|
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
$repeat = $notice->repeat($this->author2->id, 'test');
|
|
|
|
|
|
|
|
$entry = $repeat->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
|
|
|
|
|
|
|
$this->assertEquals($notice->id, $noticeInfo->getAttribute('repeat_of'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoticeInfoRepeated()
|
|
|
|
{
|
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
$repeat = $notice->repeat($this->author2->id, 'test');
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, false, $this->author2);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
|
|
|
|
|
|
|
$this->assertEquals('true', $noticeInfo->getAttribute('repeated'));
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, false, $this->targetUser1);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
|
|
|
|
|
|
|
$this->assertEquals('false', $noticeInfo->getAttribute('repeated'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoticeInfoFave()
|
|
|
|
{
|
|
|
|
$notice = $this->_fakeNotice();
|
|
|
|
|
|
|
|
$fave = Fave::addNew($this->author2->getProfile(), $notice);
|
|
|
|
|
|
|
|
// Should be set if user has faved
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, false, $this->author2);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
|
|
|
|
|
|
|
$this->assertEquals('true', $noticeInfo->getAttribute('favorite'));
|
|
|
|
|
|
|
|
// Shouldn't be set if user has not faved
|
|
|
|
|
|
|
|
$entry = $notice->asAtomEntry(false, false, false, $this->targetUser1);
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
|
|
|
|
|
|
|
$this->assertEquals('false', $noticeInfo->getAttribute('favorite'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConversationLink()
|
|
|
|
{
|
|
|
|
$orig = $this->_fakeNotice($this->targetUser1);
|
|
|
|
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "@" . $this->targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
2010-08-04 07:26:19 +09:00
|
|
|
|
|
|
|
$reply = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$conv = Conversation::getKV('id', $reply->conversation);
|
2010-08-04 07:26:19 +09:00
|
|
|
|
|
|
|
$entry = $reply->asAtomEntry();
|
|
|
|
|
|
|
|
$element = $this->_entryToElement($entry, true);
|
|
|
|
|
|
|
|
$this->assertEquals($conv->uri, ActivityUtils::getLink($element, 'ostatus:conversation'));
|
2010-08-04 06:17:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function __destruct()
|
|
|
|
{
|
|
|
|
if (!is_null($this->author1)) {
|
|
|
|
$this->author1->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($this->author2)) {
|
|
|
|
$this->author2->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($this->targetUser1)) {
|
|
|
|
$this->targetUser1->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($this->targetUser2)) {
|
|
|
|
$this->targetUser2->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($this->targetGroup1)) {
|
|
|
|
$this->targetGroup1->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($this->targetGroup2)) {
|
|
|
|
$this->targetGroup2->delete();
|
|
|
|
}
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _fakeNotice($user = null, $text = null)
|
|
|
|
{
|
|
|
|
if (empty($user)) {
|
|
|
|
$user = $this->author1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($text)) {
|
2013-10-21 20:20:30 +09:00
|
|
|
$text = "fake-o text-o " . common_random_hexstr(32);
|
2010-08-04 05:41:44 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return Notice::saveNew($user->id, $text, 'test', array('uri' => null));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _entryToElement($entry, $namespace = false)
|
|
|
|
{
|
|
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>'."\n\n";
|
|
|
|
$xml .= '<feed';
|
|
|
|
if ($namespace) {
|
|
|
|
$xml .= ' xmlns="http://www.w3.org/2005/Atom"';
|
|
|
|
$xml .= ' xmlns:thr="http://purl.org/syndication/thread/1.0"';
|
|
|
|
$xml .= ' xmlns:georss="http://www.georss.org/georss"';
|
|
|
|
$xml .= ' xmlns:activity="http://activitystrea.ms/spec/1.0/"';
|
|
|
|
$xml .= ' xmlns:media="http://purl.org/syndication/atommedia"';
|
|
|
|
$xml .= ' xmlns:poco="http://portablecontacts.net/spec/1.0"';
|
|
|
|
$xml .= ' xmlns:ostatus="http://ostatus.org/schema/1.0"';
|
|
|
|
$xml .= ' xmlns:statusnet="http://status.net/schema/api/1/"';
|
|
|
|
}
|
|
|
|
$xml .= '>' . "\n" . $entry . "\n" . '</feed>' . "\n";
|
|
|
|
$doc = DOMDocument::loadXML($xml);
|
|
|
|
$feed = $doc->documentElement;
|
|
|
|
$entries = $feed->getElementsByTagName('entry');
|
|
|
|
|
|
|
|
return $entries->item(0);
|
|
|
|
}
|
|
|
|
}
|