[FORMAT] Run php-cs-fixer on tests/
This commit is contained in:
parent
aa7aff3f6b
commit
324b7f38a9
@ -45,14 +45,14 @@ require_once INSTALLDIR . '/lib/util/common.php';
|
|||||||
|
|
||||||
final class ActivityGenerationTests extends TestCase
|
final class ActivityGenerationTests extends TestCase
|
||||||
{
|
{
|
||||||
static $author1 = null;
|
public static $author1 = null;
|
||||||
static $author2 = null;
|
public static $author2 = null;
|
||||||
|
|
||||||
static $targetUser1 = null;
|
public static $targetUser1 = null;
|
||||||
static $targetUser2 = null;
|
public static $targetUser2 = null;
|
||||||
|
|
||||||
static $targetGroup1 = null;
|
public static $targetGroup1 = null;
|
||||||
static $targetGroup2 = null;
|
public static $targetGroup2 = null;
|
||||||
|
|
||||||
public static function setUpBeforeClass(): void
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
@ -66,42 +66,42 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
$groupNick2 = 'activitygenerationtestsgroup' . common_random_hexstr(4);
|
$groupNick2 = 'activitygenerationtestsgroup' . common_random_hexstr(4);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::$author1 = User::register(array('nickname' => $authorNick1,
|
self::$author1 = User::register(['nickname' => $authorNick1,
|
||||||
'email' => $authorNick1 . '@example.net',
|
'email' => $authorNick1 . '@example.net',
|
||||||
'email_confirmed' => true));
|
'email_confirmed' => true,]);
|
||||||
|
|
||||||
self::$author2 = User::register(array('nickname' => $authorNick2,
|
self::$author2 = User::register(['nickname' => $authorNick2,
|
||||||
'email' => $authorNick2 . '@example.net',
|
'email' => $authorNick2 . '@example.net',
|
||||||
'email_confirmed' => true));
|
'email_confirmed' => true,]);
|
||||||
|
|
||||||
self::$targetUser1 = User::register(array('nickname' => $targetNick1,
|
self::$targetUser1 = User::register(['nickname' => $targetNick1,
|
||||||
'email' => $targetNick1 . '@example.net',
|
'email' => $targetNick1 . '@example.net',
|
||||||
'email_confirmed' => true));
|
'email_confirmed' => true,]);
|
||||||
|
|
||||||
self::$targetUser2 = User::register(array('nickname' => $targetNick2,
|
self::$targetUser2 = User::register(['nickname' => $targetNick2,
|
||||||
'email' => $targetNick2 . '@example.net',
|
'email' => $targetNick2 . '@example.net',
|
||||||
'email_confirmed' => true));
|
'email_confirmed' => true,]);
|
||||||
|
|
||||||
self::$targetGroup1 = User_group::register(array('nickname' => $groupNick1,
|
self::$targetGroup1 = User_group::register(['nickname' => $groupNick1,
|
||||||
'userid' => self::$author1->id,
|
'userid' => self::$author1->id,
|
||||||
'aliases' => array(),
|
'aliases' => [],
|
||||||
'local' => true,
|
'local' => true,
|
||||||
'location' => null,
|
'location' => null,
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'fullname' => null,
|
'fullname' => null,
|
||||||
'homepage' => null,
|
'homepage' => null,
|
||||||
'mainpage' => null));
|
'mainpage' => null,]);
|
||||||
self::$targetGroup2 = User_group::register(array('nickname' => $groupNick2,
|
self::$targetGroup2 = User_group::register(['nickname' => $groupNick2,
|
||||||
'userid' => self::$author1->id,
|
'userid' => self::$author1->id,
|
||||||
'aliases' => array(),
|
'aliases' => [],
|
||||||
'local' => true,
|
'local' => true,
|
||||||
'location' => null,
|
'location' => null,
|
||||||
'description' => null,
|
'description' => null,
|
||||||
'fullname' => null,
|
'fullname' => null,
|
||||||
'homepage' => null,
|
'homepage' => null,
|
||||||
'mainpage' => null));
|
'mainpage' => null,]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
self::tearDownAfterClass();
|
static::tearDownAfterClass();
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,13 +114,13 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$element = $this->_entryToElement($entry, false);
|
$element = $this->_entryToElement($entry, false);
|
||||||
|
|
||||||
$this->assertEquals($notice->getUri(), ActivityUtils::childContent($element, 'id'));
|
static::assertSame($notice->getUri(), ActivityUtils::childContent($element, 'id'));
|
||||||
$this->assertEquals('New note by ' . self::$author1->nickname, ActivityUtils::childContent($element, 'title'));
|
static::assertSame('New note by ' . self::$author1->nickname, ActivityUtils::childContent($element, 'title'));
|
||||||
$this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content'));
|
static::assertSame($notice->rendered, ActivityUtils::childContent($element, 'content'));
|
||||||
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published')));
|
static::assertSame(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published')));
|
||||||
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated')));
|
static::assertSame(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated')));
|
||||||
$this->assertEquals(ActivityVerb::POST, ActivityUtils::childContent($element, 'verb', Activity::SPEC));
|
static::assertSame(ActivityVerb::POST, ActivityUtils::childContent($element, 'verb', Activity::SPEC));
|
||||||
$this->assertEquals(ActivityObject::NOTE, ActivityUtils::childContent($element, 'object-type', Activity::SPEC));
|
static::assertSame(ActivityObject::NOTE, ActivityUtils::childContent($element, 'object-type', Activity::SPEC));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNamespaceFlag()
|
public function testNamespaceFlag()
|
||||||
@ -131,27 +131,27 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$element = $this->_entryToElement($entry, false);
|
$element = $this->_entryToElement($entry, false);
|
||||||
|
|
||||||
$this->assertTrue($element->hasAttribute('xmlns'));
|
static::assertTrue($element->hasAttribute('xmlns'));
|
||||||
$this->assertTrue($element->hasAttribute('xmlns:thr'));
|
static::assertTrue($element->hasAttribute('xmlns:thr'));
|
||||||
$this->assertTrue($element->hasAttribute('xmlns:georss'));
|
static::assertTrue($element->hasAttribute('xmlns:georss'));
|
||||||
$this->assertTrue($element->hasAttribute('xmlns:activity'));
|
static::assertTrue($element->hasAttribute('xmlns:activity'));
|
||||||
$this->assertTrue($element->hasAttribute('xmlns:media'));
|
static::assertTrue($element->hasAttribute('xmlns:media'));
|
||||||
$this->assertTrue($element->hasAttribute('xmlns:poco'));
|
static::assertTrue($element->hasAttribute('xmlns:poco'));
|
||||||
$this->assertTrue($element->hasAttribute('xmlns:ostatus'));
|
static::assertTrue($element->hasAttribute('xmlns:ostatus'));
|
||||||
$this->assertTrue($element->hasAttribute('xmlns:statusnet'));
|
static::assertTrue($element->hasAttribute('xmlns:statusnet'));
|
||||||
|
|
||||||
$entry = $notice->asAtomEntry(false);
|
$entry = $notice->asAtomEntry(false);
|
||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$this->assertFalse($element->hasAttribute('xmlns'));
|
static::assertFalse($element->hasAttribute('xmlns'));
|
||||||
$this->assertFalse($element->hasAttribute('xmlns:thr'));
|
static::assertFalse($element->hasAttribute('xmlns:thr'));
|
||||||
$this->assertFalse($element->hasAttribute('xmlns:georss'));
|
static::assertFalse($element->hasAttribute('xmlns:georss'));
|
||||||
$this->assertFalse($element->hasAttribute('xmlns:activity'));
|
static::assertFalse($element->hasAttribute('xmlns:activity'));
|
||||||
$this->assertFalse($element->hasAttribute('xmlns:media'));
|
static::assertFalse($element->hasAttribute('xmlns:media'));
|
||||||
$this->assertFalse($element->hasAttribute('xmlns:poco'));
|
static::assertFalse($element->hasAttribute('xmlns:poco'));
|
||||||
$this->assertFalse($element->hasAttribute('xmlns:ostatus'));
|
static::assertFalse($element->hasAttribute('xmlns:ostatus'));
|
||||||
$this->assertFalse($element->hasAttribute('xmlns:statusnet'));
|
static::assertFalse($element->hasAttribute('xmlns:statusnet'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSourceFlag()
|
public function testSourceFlag()
|
||||||
@ -166,7 +166,7 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$source = ActivityUtils::child($element, 'source');
|
$source = ActivityUtils::child($element, 'source');
|
||||||
|
|
||||||
$this->assertNull($source);
|
static::assertNull($source);
|
||||||
|
|
||||||
// Test with source
|
// Test with source
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$source = ActivityUtils::child($element, 'source');
|
$source = ActivityUtils::child($element, 'source');
|
||||||
|
|
||||||
$this->assertNotNull($source);
|
static::assertNotNull($source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSourceContent()
|
public function testSourceContent()
|
||||||
@ -192,17 +192,17 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$source = ActivityUtils::child($element, 'source');
|
$source = ActivityUtils::child($element, 'source');
|
||||||
|
|
||||||
$atomUrl = common_local_url('ApiTimelineUser', array('id' => self::$author1->id, 'format' => 'atom'));
|
$atomUrl = common_local_url('ApiTimelineUser', ['id' => self::$author1->id, 'format' => 'atom']);
|
||||||
|
|
||||||
$profile = self::$author1->getProfile();
|
$profile = self::$author1->getProfile();
|
||||||
|
|
||||||
$this->assertEquals($atomUrl, ActivityUtils::childContent($source, 'id'));
|
static::assertSame($atomUrl, ActivityUtils::childContent($source, 'id'));
|
||||||
$this->assertEquals($atomUrl, ActivityUtils::getLink($source, 'self', 'application/atom+xml'));
|
static::assertSame($atomUrl, ActivityUtils::getLink($source, 'self', 'application/atom+xml'));
|
||||||
$this->assertEquals($profile->profileurl, ActivityUtils::getPermalink($source));
|
static::assertSame($profile->profileurl, ActivityUtils::getPermalink($source));
|
||||||
$this->assertEquals(strtotime($notice2->created), strtotime(ActivityUtils::childContent($source, 'updated')));
|
static::assertSame(strtotime($notice2->created), strtotime(ActivityUtils::childContent($source, 'updated')));
|
||||||
// XXX: do we care here?
|
// XXX: do we care here?
|
||||||
$this->assertFalse(is_null(ActivityUtils::childContent($source, 'title')));
|
static::assertFalse(is_null(ActivityUtils::childContent($source, 'title')));
|
||||||
$this->assertEquals(common_config('license', 'url'), ActivityUtils::getLink($source, 'license'));
|
static::assertSame(common_config('license', 'url'), ActivityUtils::getLink($source, 'license'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAuthorFlag()
|
public function testAuthorFlag()
|
||||||
@ -215,8 +215,8 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$this->assertNull(ActivityUtils::child($element, 'author'));
|
static::assertNull(ActivityUtils::child($element, 'author'));
|
||||||
$this->assertNull(ActivityUtils::child($element, 'actor', Activity::SPEC));
|
static::assertNull(ActivityUtils::child($element, 'actor', Activity::SPEC));
|
||||||
|
|
||||||
// Test with source
|
// Test with source
|
||||||
|
|
||||||
@ -227,8 +227,8 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
$author = ActivityUtils::child($element, 'author');
|
$author = ActivityUtils::child($element, 'author');
|
||||||
$actor = ActivityUtils::child($element, 'actor', Activity::SPEC);
|
$actor = ActivityUtils::child($element, 'actor', Activity::SPEC);
|
||||||
|
|
||||||
$this->assertFalse(is_null($author));
|
static::assertFalse(is_null($author));
|
||||||
$this->assertTrue(is_null($actor)); // <activity:actor> is obsolete, no longer added
|
static::assertTrue(is_null($actor)); // <activity:actor> is obsolete, no longer added
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAuthorContent()
|
public function testAuthorContent()
|
||||||
@ -243,8 +243,8 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$author = ActivityUtils::child($element, 'author');
|
$author = ActivityUtils::child($element, 'author');
|
||||||
|
|
||||||
$this->assertEquals(self::$author1->getNickname(), ActivityUtils::childContent($author, 'name'));
|
static::assertSame(self::$author1->getNickname(), ActivityUtils::childContent($author, 'name'));
|
||||||
$this->assertEquals(self::$author1->getUri(), ActivityUtils::childContent($author, 'uri'));
|
static::assertSame(self::$author1->getUri(), ActivityUtils::childContent($author, 'uri'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,16 +262,16 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$actor = ActivityUtils::child($element, 'actor', Activity::SPEC);
|
$actor = ActivityUtils::child($element, 'actor', Activity::SPEC);
|
||||||
|
|
||||||
$this->assertEquals($actor, null);
|
static::assertSame($actor, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReplyLink()
|
public function testReplyLink()
|
||||||
{
|
{
|
||||||
$orig = $this->_fakeNotice(self::$targetUser1);
|
$orig = $this->_fakeNotice(self::$targetUser1);
|
||||||
|
|
||||||
$text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
$text = '@' . self::$targetUser1->nickname . ' reply text ' . common_random_hexstr(4);
|
||||||
|
|
||||||
$reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
$reply = Notice::saveNew(self::$author1->id, $text, 'test', ['uri' => null, 'reply_to' => $orig->id]);
|
||||||
|
|
||||||
$entry = $reply->asAtomEntry();
|
$entry = $reply->asAtomEntry();
|
||||||
|
|
||||||
@ -279,37 +279,37 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$irt = ActivityUtils::child($element, 'in-reply-to', 'http://purl.org/syndication/thread/1.0');
|
$irt = ActivityUtils::child($element, 'in-reply-to', 'http://purl.org/syndication/thread/1.0');
|
||||||
|
|
||||||
$this->assertNotNull($irt);
|
static::assertNotNull($irt);
|
||||||
$this->assertEquals($orig->getUri(), $irt->getAttribute('ref'));
|
static::assertSame($orig->getUri(), $irt->getAttribute('ref'));
|
||||||
$this->assertEquals($orig->getUrl(), $irt->getAttribute('href'));
|
static::assertSame($orig->getUrl(), $irt->getAttribute('href'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReplyAttention()
|
public function testReplyAttention()
|
||||||
{
|
{
|
||||||
$orig = $this->_fakeNotice(self::$targetUser1);
|
$orig = $this->_fakeNotice(self::$targetUser1);
|
||||||
|
|
||||||
$text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
$text = '@' . self::$targetUser1->nickname . ' reply text ' . common_random_hexstr(4);
|
||||||
|
|
||||||
$reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
$reply = Notice::saveNew(self::$author1->id, $text, 'test', ['uri' => null, 'reply_to' => $orig->id]);
|
||||||
|
|
||||||
$entry = $reply->asAtomEntry();
|
$entry = $reply->asAtomEntry();
|
||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$this->assertEquals(self::$targetUser1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
|
static::assertSame(self::$targetUser1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMultipleReplyAttention()
|
public function testMultipleReplyAttention()
|
||||||
{
|
{
|
||||||
$orig = $this->_fakeNotice(self::$targetUser1);
|
$orig = $this->_fakeNotice(self::$targetUser1);
|
||||||
|
|
||||||
$text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
$text = '@' . self::$targetUser1->nickname . ' reply text ' . common_random_hexstr(4);
|
||||||
|
|
||||||
$reply = Notice::saveNew(self::$targetUser2->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
$reply = Notice::saveNew(self::$targetUser2->id, $text, 'test', ['uri' => null, 'reply_to' => $orig->id]);
|
||||||
|
|
||||||
$text = "@" . self::$targetUser1->nickname . " @" . self::$targetUser2->nickname . " reply text " . common_random_hexstr(4);
|
$text = '@' . self::$targetUser1->nickname . ' @' . self::$targetUser2->nickname . ' reply text ' . common_random_hexstr(4);
|
||||||
|
|
||||||
$reply2 = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $reply->id));
|
$reply2 = Notice::saveNew(self::$author1->id, $text, 'test', ['uri' => null, 'reply_to' => $reply->id]);
|
||||||
|
|
||||||
$entry = $reply2->asAtomEntry();
|
$entry = $reply2->asAtomEntry();
|
||||||
|
|
||||||
@ -317,34 +317,34 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$links = ActivityUtils::getLinks($element, 'mentioned');
|
$links = ActivityUtils::getLinks($element, 'mentioned');
|
||||||
|
|
||||||
$hrefs = array();
|
$hrefs = [];
|
||||||
|
|
||||||
foreach ($links as $link) {
|
foreach ($links as $link) {
|
||||||
$hrefs[] = $link->getAttribute('href');
|
$hrefs[] = $link->getAttribute('href');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertTrue(in_array(self::$targetUser1->getUri(), $hrefs));
|
static::assertTrue(in_array(self::$targetUser1->getUri(), $hrefs));
|
||||||
$this->assertTrue(in_array(self::$targetUser2->getUri(), $hrefs));
|
static::assertTrue(in_array(self::$targetUser2->getUri(), $hrefs));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGroupPostAttention()
|
public function testGroupPostAttention()
|
||||||
{
|
{
|
||||||
$text = "!" . self::$targetGroup1->nickname . " reply text " . common_random_hexstr(4);
|
$text = '!' . self::$targetGroup1->nickname . ' reply text ' . common_random_hexstr(4);
|
||||||
|
|
||||||
$notice = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null));
|
$notice = Notice::saveNew(self::$author1->id, $text, 'test', ['uri' => null]);
|
||||||
|
|
||||||
$entry = $notice->asAtomEntry();
|
$entry = $notice->asAtomEntry();
|
||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$this->assertEquals(self::$targetGroup1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
|
static::assertSame(self::$targetGroup1->getUri(), ActivityUtils::getLink($element, 'mentioned'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMultipleGroupPostAttention()
|
public function testMultipleGroupPostAttention()
|
||||||
{
|
{
|
||||||
$text = "!" . self::$targetGroup1->nickname . " !" . self::$targetGroup2->nickname . " reply text " . common_random_hexstr(4);
|
$text = '!' . self::$targetGroup1->nickname . ' !' . self::$targetGroup2->nickname . ' reply text ' . common_random_hexstr(4);
|
||||||
|
|
||||||
$notice = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null));
|
$notice = Notice::saveNew(self::$author1->id, $text, 'test', ['uri' => null]);
|
||||||
|
|
||||||
$entry = $notice->asAtomEntry();
|
$entry = $notice->asAtomEntry();
|
||||||
|
|
||||||
@ -352,15 +352,14 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$links = ActivityUtils::getLinks($element, 'mentioned');
|
$links = ActivityUtils::getLinks($element, 'mentioned');
|
||||||
|
|
||||||
$hrefs = array();
|
$hrefs = [];
|
||||||
|
|
||||||
foreach ($links as $link) {
|
foreach ($links as $link) {
|
||||||
$hrefs[] = $link->getAttribute('href');
|
$hrefs[] = $link->getAttribute('href');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertTrue(in_array(self::$targetGroup1->getUri(), $hrefs));
|
static::assertTrue(in_array(self::$targetGroup1->getUri(), $hrefs));
|
||||||
$this->assertTrue(in_array(self::$targetGroup2->getUri(), $hrefs));
|
static::assertTrue(in_array(self::$targetGroup2->getUri(), $hrefs));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRepeatLink()
|
public function testRepeatLink()
|
||||||
@ -374,9 +373,9 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
|
||||||
|
|
||||||
$this->assertNotNull($noticeInfo);
|
static::assertNotNull($noticeInfo);
|
||||||
$this->assertEquals($notice->id, $noticeInfo->getAttribute('repeat_of'));
|
static::assertSame($notice->id, $noticeInfo->getAttribute('repeat_of'));
|
||||||
$this->assertEquals($repeat->id, $noticeInfo->getAttribute('local_id'));
|
static::assertSame($repeat->id, $noticeInfo->getAttribute('local_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTag()
|
public function testTag()
|
||||||
@ -391,8 +390,8 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$category = ActivityUtils::child($element, 'category');
|
$category = ActivityUtils::child($element, 'category');
|
||||||
|
|
||||||
$this->assertNotNull($category);
|
static::assertNotNull($category);
|
||||||
$this->assertEquals($tag1, $category->getAttribute('term'));
|
static::assertSame($tag1, $category->getAttribute('term'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMultiTag()
|
public function testMultiTag()
|
||||||
@ -408,29 +407,29 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$categories = $element->getElementsByTagName('category');
|
$categories = $element->getElementsByTagName('category');
|
||||||
|
|
||||||
$this->assertNotNull($categories);
|
static::assertNotNull($categories);
|
||||||
$this->assertEquals(2, $categories->length);
|
static::assertSame(2, $categories->length);
|
||||||
|
|
||||||
$terms = array();
|
$terms = [];
|
||||||
|
|
||||||
for ($i = 0; $i < $categories->length; $i++) {
|
for ($i = 0; $i < $categories->length; ++$i) {
|
||||||
$cat = $categories->item($i);
|
$cat = $categories->item($i);
|
||||||
$terms[] = $cat->getAttribute('term');
|
$terms[] = $cat->getAttribute('term');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertTrue(in_array($tag1, $terms));
|
static::assertTrue(in_array($tag1, $terms));
|
||||||
$this->assertTrue(in_array($tag2, $terms));
|
static::assertTrue(in_array($tag2, $terms));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGeotaggedActivity()
|
public function testGeotaggedActivity()
|
||||||
{
|
{
|
||||||
$notice = Notice::saveNew(self::$author1->id, common_random_hexstr(4), 'test', array('uri' => null, 'lat' => 45.5, 'lon' => -73.6));
|
$notice = Notice::saveNew(self::$author1->id, common_random_hexstr(4), 'test', ['uri' => null, 'lat' => 45.5, 'lon' => -73.6]);
|
||||||
|
|
||||||
$entry = $notice->asAtomEntry();
|
$entry = $notice->asAtomEntry();
|
||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$this->assertEquals('45.5000000 -73.6000000', ActivityUtils::childContent($element, 'point', "http://www.georss.org/georss"));
|
static::assertSame('45.5000000 -73.6000000', ActivityUtils::childContent($element, 'point', 'http://www.georss.org/georss'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoticeInfo()
|
public function testNoticeInfo()
|
||||||
@ -441,14 +440,14 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
|
||||||
|
|
||||||
$this->assertEquals($notice->id, $noticeInfo->getAttribute('local_id'));
|
static::assertSame($notice->id, $noticeInfo->getAttribute('local_id'));
|
||||||
$this->assertEquals($notice->source, $noticeInfo->getAttribute('source'));
|
static::assertSame($notice->source, $noticeInfo->getAttribute('source'));
|
||||||
$this->assertEquals('', $noticeInfo->getAttribute('repeat_of'));
|
static::assertSame('', $noticeInfo->getAttribute('repeat_of'));
|
||||||
$this->assertEquals('', $noticeInfo->getAttribute('repeated'));
|
static::assertSame('', $noticeInfo->getAttribute('repeated'));
|
||||||
// $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
|
// $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
|
||||||
$this->assertEquals('', $noticeInfo->getAttribute('source_link'));
|
static::assertSame('', $noticeInfo->getAttribute('source_link'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoticeInfoRepeatOf()
|
public function testNoticeInfoRepeatOf()
|
||||||
@ -461,9 +460,9 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
|
||||||
|
|
||||||
$this->assertEquals($notice->id, $noticeInfo->getAttribute('repeat_of'));
|
static::assertSame($notice->id, $noticeInfo->getAttribute('repeat_of'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoticeInfoRepeated()
|
public function testNoticeInfoRepeated()
|
||||||
@ -476,17 +475,17 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
|
||||||
|
|
||||||
$this->assertEquals('true', $noticeInfo->getAttribute('repeated'));
|
static::assertSame('true', $noticeInfo->getAttribute('repeated'));
|
||||||
|
|
||||||
$entry = $notice->asAtomEntry(false, false, false, self::$targetUser1->getProfile());
|
$entry = $notice->asAtomEntry(false, false, false, self::$targetUser1->getProfile());
|
||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
|
$noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
|
||||||
|
|
||||||
$this->assertEquals('false', $noticeInfo->getAttribute('repeated'));
|
static::assertSame('false', $noticeInfo->getAttribute('repeated'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public function testNoticeInfoFave()
|
/* public function testNoticeInfoFave()
|
||||||
@ -520,9 +519,9 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
{
|
{
|
||||||
$orig = $this->_fakeNotice(self::$targetUser1);
|
$orig = $this->_fakeNotice(self::$targetUser1);
|
||||||
|
|
||||||
$text = "@" . self::$targetUser1->nickname . " reply text " . common_random_hexstr(4);
|
$text = '@' . self::$targetUser1->nickname . ' reply text ' . common_random_hexstr(4);
|
||||||
|
|
||||||
$reply = Notice::saveNew(self::$author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
|
$reply = Notice::saveNew(self::$author1->id, $text, 'test', ['uri' => null, 'reply_to' => $orig->id]);
|
||||||
|
|
||||||
$conv = Conversation::getKV('id', $reply->conversation);
|
$conv = Conversation::getKV('id', $reply->conversation);
|
||||||
|
|
||||||
@ -530,7 +529,7 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
|
|
||||||
$element = $this->_entryToElement($entry, true);
|
$element = $this->_entryToElement($entry, true);
|
||||||
|
|
||||||
$this->assertEquals($conv->getUrl(), ActivityUtils::getLink($element, 'ostatus:conversation'));
|
static::assertSame($conv->getUrl(), ActivityUtils::getLink($element, 'ostatus:conversation'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass(): void
|
public static function tearDownAfterClass(): void
|
||||||
@ -567,10 +566,10 @@ final class ActivityGenerationTests extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($text)) {
|
if (empty($text)) {
|
||||||
$text = "fake-o text-o " . common_random_hexstr(32);
|
$text = 'fake-o text-o ' . common_random_hexstr(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Notice::saveNew($user->id, $text, 'test', array('uri' => null));
|
return Notice::saveNew($user->id, $text, 'test', ['uri' => null]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _entryToElement($entry, $namespace = false)
|
private function _entryToElement($entry, $namespace = false)
|
||||||
|
@ -40,7 +40,6 @@ require_once INSTALLDIR . '/lib/util/common.php';
|
|||||||
|
|
||||||
final class ActivityParseTests extends TestCase
|
final class ActivityParseTests extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testMastodonRetweet()
|
public function testMastodonRetweet()
|
||||||
{
|
{
|
||||||
global $_mastodon_retweet;
|
global $_mastodon_retweet;
|
||||||
@ -50,11 +49,11 @@ final class ActivityParseTests extends TestCase
|
|||||||
$entries = $feed->getElementsByTagName('entry');
|
$entries = $feed->getElementsByTagName('entry');
|
||||||
$entry = $entries->item(0);
|
$entry = $entries->item(0);
|
||||||
$act = new Activity($entry, $feed);
|
$act = new Activity($entry, $feed);
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
$this->assertFalse(empty($act->objects[0]));
|
static::assertFalse(empty($act->objects[0]));
|
||||||
|
|
||||||
$object = $act->objects[0];
|
$object = $act->objects[0];
|
||||||
$this->assertEquals($object->verb, ActivityVerb::POST);
|
static::assertSame($object->verb, ActivityVerb::POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGSReweet()
|
public function testGSReweet()
|
||||||
@ -66,11 +65,11 @@ final class ActivityParseTests extends TestCase
|
|||||||
$entries = $feed->getElementsByTagName('entry');
|
$entries = $feed->getElementsByTagName('entry');
|
||||||
$entry = $entries->item(0);
|
$entry = $entries->item(0);
|
||||||
$act = new Activity($entry, $feed);
|
$act = new Activity($entry, $feed);
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
$this->assertFalse(empty($act->objects[0]));
|
static::assertFalse(empty($act->objects[0]));
|
||||||
|
|
||||||
$object = $act->objects[0];
|
$object = $act->objects[0];
|
||||||
$this->assertEquals($object->verb, ActivityVerb::POST);
|
static::assertSame($object->verb, ActivityVerb::POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExample1()
|
public function testExample1()
|
||||||
@ -80,16 +79,16 @@ final class ActivityParseTests extends TestCase
|
|||||||
$dom->loadXML($_example1);
|
$dom->loadXML($_example1);
|
||||||
$act = new Activity($dom->documentElement);
|
$act = new Activity($dom->documentElement);
|
||||||
|
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
|
|
||||||
$this->assertEquals(1243860840, $act->time);
|
static::assertSame(1243860840, $act->time);
|
||||||
$this->assertEquals(ActivityVerb::POST, $act->verb);
|
static::assertSame(ActivityVerb::POST, $act->verb);
|
||||||
|
|
||||||
$this->assertFalse(empty($act->objects[0]));
|
static::assertFalse(empty($act->objects[0]));
|
||||||
$this->assertEquals('Punctuation Changeset', $act->objects[0]->title);
|
static::assertSame('Punctuation Changeset', $act->objects[0]->title);
|
||||||
$this->assertEquals('http://versioncentral.example.org/activity/changeset', $act->objects[0]->type);
|
static::assertSame('http://versioncentral.example.org/activity/changeset', $act->objects[0]->type);
|
||||||
$this->assertEquals('Fixing punctuation because it makes it more readable.', $act->objects[0]->summary);
|
static::assertSame('Fixing punctuation because it makes it more readable.', $act->objects[0]->summary);
|
||||||
$this->assertEquals('tag:versioncentral.example.org,2009:/change/1643245', $act->objects[0]->id);
|
static::assertSame('tag:versioncentral.example.org,2009:/change/1643245', $act->objects[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExample2()
|
public function testExample2()
|
||||||
@ -99,10 +98,10 @@ final class ActivityParseTests extends TestCase
|
|||||||
$dom->loadXML($_example2);
|
$dom->loadXML($_example2);
|
||||||
$act = new Activity($dom->documentElement);
|
$act = new Activity($dom->documentElement);
|
||||||
|
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
// Did we handle <content type="html"> correctly with a typical payload?
|
// Did we handle <content type="html"> correctly with a typical payload?
|
||||||
$this->assertEquals("<p>Geraldine posted a Photo on PhotoPanic</p>\n " .
|
static::assertSame("<p>Geraldine posted a Photo on PhotoPanic</p>\n " .
|
||||||
"<img src=\"/geraldine/photo1.jpg\">", trim($act->content));
|
'<img src="/geraldine/photo1.jpg">', trim($act->content));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExample3()
|
public function testExample3()
|
||||||
@ -119,30 +118,30 @@ final class ActivityParseTests extends TestCase
|
|||||||
|
|
||||||
$act = new Activity($entry, $feed);
|
$act = new Activity($entry, $feed);
|
||||||
|
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
$this->assertEquals(1071340202, $act->time);
|
static::assertSame(1071340202, $act->time);
|
||||||
$this->assertEquals('http://example.org/2003/12/13/atom03.html', $act->link);
|
static::assertSame('http://example.org/2003/12/13/atom03.html', $act->link);
|
||||||
|
|
||||||
$this->assertEquals($act->verb, ActivityVerb::POST);
|
static::assertSame($act->verb, ActivityVerb::POST);
|
||||||
|
|
||||||
$this->assertFalse(empty($act->actor));
|
static::assertFalse(empty($act->actor));
|
||||||
$this->assertEquals(ActivityObject::PERSON, $act->actor->type);
|
static::assertSame(ActivityObject::PERSON, $act->actor->type);
|
||||||
$this->assertEquals('John Doe', $act->actor->title);
|
static::assertSame('John Doe', $act->actor->title);
|
||||||
$this->assertEquals('mailto:johndoe@example.com', $act->actor->id);
|
static::assertSame('mailto:johndoe@example.com', $act->actor->id);
|
||||||
|
|
||||||
$this->assertFalse(empty($act->objects[0]));
|
static::assertFalse(empty($act->objects[0]));
|
||||||
$this->assertEquals(ActivityObject::NOTE, $act->objects[0]->type);
|
static::assertSame(ActivityObject::NOTE, $act->objects[0]->type);
|
||||||
$this->assertEquals('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $act->objects[0]->id);
|
static::assertSame('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $act->objects[0]->id);
|
||||||
$this->assertEquals('Atom-Powered Robots Run Amok', $act->objects[0]->title);
|
static::assertSame('Atom-Powered Robots Run Amok', $act->objects[0]->title);
|
||||||
$this->assertEquals('Some text.', $act->objects[0]->summary);
|
static::assertSame('Some text.', $act->objects[0]->summary);
|
||||||
$this->assertEquals('http://example.org/2003/12/13/atom03.html', $act->objects[0]->link);
|
static::assertSame('http://example.org/2003/12/13/atom03.html', $act->objects[0]->link);
|
||||||
|
|
||||||
$this->assertFalse(empty($act->context));
|
static::assertFalse(empty($act->context));
|
||||||
|
|
||||||
$this->assertTrue(empty($act->target));
|
static::assertTrue(empty($act->target));
|
||||||
|
|
||||||
$this->assertEquals($act->entry, $entry);
|
static::assertSame($act->entry, $entry);
|
||||||
$this->assertEquals($act->feed, $feed);
|
static::assertSame($act->feed, $feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExample4()
|
public function testExample4()
|
||||||
@ -155,21 +154,23 @@ final class ActivityParseTests extends TestCase
|
|||||||
|
|
||||||
$act = new Activity($entry);
|
$act = new Activity($entry);
|
||||||
|
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
$this->assertEquals(1266547958, $act->time);
|
static::assertSame(1266547958, $act->time);
|
||||||
$this->assertEquals('http://example.net/notice/14', $act->link);
|
static::assertSame('http://example.net/notice/14', $act->link);
|
||||||
|
|
||||||
$this->assertFalse(empty($act->context));
|
static::assertFalse(empty($act->context));
|
||||||
$this->assertEquals('http://example.net/notice/12', $act->context->replyToID);
|
static::assertSame('http://example.net/notice/12', $act->context->replyToID);
|
||||||
$this->assertEquals('http://example.net/notice/12', $act->context->replyToUrl);
|
static::assertSame('http://example.net/notice/12', $act->context->replyToUrl);
|
||||||
$this->assertEquals('http://example.net/conversation/11', $act->context->conversation);
|
static::assertSame('http://example.net/conversation/11', $act->context->conversation);
|
||||||
$this->assertEquals(array('http://example.net/user/1'), array_keys($act->context->attention));
|
static::assertSame(['http://example.net/user/1'], array_keys($act->context->attention));
|
||||||
|
|
||||||
$this->assertFalse(empty($act->objects[0]));
|
static::assertFalse(empty($act->objects[0]));
|
||||||
$this->assertEquals($act->objects[0]->content,
|
static::assertSame(
|
||||||
'@<span class="vcard"><a href="http://example.net/user/1" class="url"><span class="fn nickname">evan</span></a></span> now is the time for all good men to come to the aid of their country. #<span class="tag"><a href="http://example.net/tag/thetime" rel="tag">thetime</a></span>');
|
$act->objects[0]->content,
|
||||||
|
'@<span class="vcard"><a href="http://example.net/user/1" class="url"><span class="fn nickname">evan</span></a></span> now is the time for all good men to come to the aid of their country. #<span class="tag"><a href="http://example.net/tag/thetime" rel="tag">thetime</a></span>'
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertFalse(empty($act->actor));
|
static::assertFalse(empty($act->actor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExample5()
|
public function testExample5()
|
||||||
@ -188,32 +189,32 @@ final class ActivityParseTests extends TestCase
|
|||||||
$act = new Activity($entry, $feed);
|
$act = new Activity($entry, $feed);
|
||||||
|
|
||||||
// Post
|
// Post
|
||||||
$this->assertEquals($act->verb, ActivityVerb::POST);
|
static::assertSame($act->verb, ActivityVerb::POST);
|
||||||
$this->assertFalse(empty($act->context));
|
static::assertFalse(empty($act->context));
|
||||||
|
|
||||||
// Actor w/Portable Contacts stuff
|
// Actor w/Portable Contacts stuff
|
||||||
$this->assertFalse(empty($act->actor));
|
static::assertFalse(empty($act->actor));
|
||||||
$this->assertEquals($act->actor->type, ActivityObject::PERSON);
|
static::assertSame($act->actor->type, ActivityObject::PERSON);
|
||||||
$this->assertEquals($act->actor->title, 'Test User');
|
static::assertSame($act->actor->title, 'Test User');
|
||||||
$this->assertEquals($act->actor->id, 'http://example.net/mysite/user/3');
|
static::assertSame($act->actor->id, 'http://example.net/mysite/user/3');
|
||||||
$this->assertEquals($act->actor->link, 'http://example.net/mysite/testuser');
|
static::assertSame($act->actor->link, 'http://example.net/mysite/testuser');
|
||||||
|
|
||||||
$avatars = $act->actor->avatarLinks;
|
$avatars = $act->actor->avatarLinks;
|
||||||
|
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$avatars[0]->url,
|
$avatars[0]->url,
|
||||||
'http://example.net/mysite/avatar/3-96-20100224004207.jpeg'
|
'http://example.net/mysite/avatar/3-96-20100224004207.jpeg'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($act->actor->displayName, 'Test User');
|
static::assertSame($act->actor->displayName, 'Test User');
|
||||||
|
|
||||||
$poco = $act->actor->poco;
|
$poco = $act->actor->poco;
|
||||||
$this->assertEquals($poco->preferredUsername, 'testuser');
|
static::assertSame($poco->preferredUsername, 'testuser');
|
||||||
$this->assertEquals($poco->address->formatted, 'San Francisco, CA');
|
static::assertSame($poco->address->formatted, 'San Francisco, CA');
|
||||||
$this->assertEquals($poco->urls[0]->type, 'homepage');
|
static::assertSame($poco->urls[0]->type, 'homepage');
|
||||||
$this->assertEquals($poco->urls[0]->value, 'http://example.com/blog.html');
|
static::assertSame($poco->urls[0]->value, 'http://example.com/blog.html');
|
||||||
$this->assertEquals($poco->urls[0]->primary, 'true');
|
static::assertSame($poco->urls[0]->primary, 'true');
|
||||||
$this->assertEquals($act->actor->geopoint, '37.7749295 -122.4194155');
|
static::assertSame($act->actor->geopoint, '37.7749295 -122.4194155');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExample6()
|
public function testExample6()
|
||||||
@ -235,17 +236,17 @@ final class ActivityParseTests extends TestCase
|
|||||||
|
|
||||||
$act = new Activity($item, $channel);
|
$act = new Activity($item, $channel);
|
||||||
|
|
||||||
$this->assertEquals($act->verb, ActivityVerb::POST);
|
static::assertSame($act->verb, ActivityVerb::POST);
|
||||||
|
|
||||||
$this->assertEquals($act->id, 'http://en.blog.wordpress.com/?p=3857');
|
static::assertSame($act->id, 'http://en.blog.wordpress.com/?p=3857');
|
||||||
$this->assertEquals($act->link, 'http://en.blog.wordpress.com/2010/03/03/rub-a-dub-dub-in-the-pubsubhubbub/');
|
static::assertSame($act->link, 'http://en.blog.wordpress.com/2010/03/03/rub-a-dub-dub-in-the-pubsubhubbub/');
|
||||||
$this->assertEquals($act->title, 'Rub-a-Dub-Dub in the PubSubHubbub');
|
static::assertSame($act->title, 'Rub-a-Dub-Dub in the PubSubHubbub');
|
||||||
$this->assertEquals($act->time, 1267634892);
|
static::assertSame($act->time, 1267634892);
|
||||||
|
|
||||||
$actor = $act->actor;
|
$actor = $act->actor;
|
||||||
|
|
||||||
$this->assertFalse(empty($actor));
|
static::assertFalse(empty($actor));
|
||||||
$this->assertEquals($actor->title, "Joseph Scott");
|
static::assertSame($actor->title, 'Joseph Scott');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExample7()
|
public function testExample7()
|
||||||
@ -267,31 +268,33 @@ final class ActivityParseTests extends TestCase
|
|||||||
|
|
||||||
$act = new Activity($item, $channel);
|
$act = new Activity($item, $channel);
|
||||||
|
|
||||||
$this->assertEquals(ActivityVerb::POST, $act->verb);
|
static::assertSame(ActivityVerb::POST, $act->verb);
|
||||||
$this->assertEquals('http://evanpro.posterous.com/checking-out-captain-bones', $act->link);
|
static::assertSame('http://evanpro.posterous.com/checking-out-captain-bones', $act->link);
|
||||||
$this->assertEquals('http://evanpro.posterous.com/checking-out-captain-bones', $act->id);
|
static::assertSame('http://evanpro.posterous.com/checking-out-captain-bones', $act->id);
|
||||||
$this->assertEquals('Checking out captain bones', $act->title);
|
static::assertSame('Checking out captain bones', $act->title);
|
||||||
$this->assertEquals(1269095551, $act->time);
|
static::assertSame(1269095551, $act->time);
|
||||||
|
|
||||||
$actor = $act->actor;
|
$actor = $act->actor;
|
||||||
|
|
||||||
$this->assertEquals(ActivityObject::PERSON, $actor->type);
|
static::assertSame(ActivityObject::PERSON, $actor->type);
|
||||||
$this->assertEquals('http://posterous.com/people/3sDslhaepotz', $actor->id);
|
static::assertSame('http://posterous.com/people/3sDslhaepotz', $actor->id);
|
||||||
$this->assertEquals('Evan Prodromou', $actor->title);
|
static::assertSame('Evan Prodromou', $actor->title);
|
||||||
$this->assertNull($actor->summary);
|
static::assertNull($actor->summary);
|
||||||
$this->assertNull($actor->content);
|
static::assertNull($actor->content);
|
||||||
$this->assertEquals('http://posterous.com/people/3sDslhaepotz', $actor->link);
|
static::assertSame('http://posterous.com/people/3sDslhaepotz', $actor->link);
|
||||||
$this->assertNull($actor->source);
|
static::assertNull($actor->source);
|
||||||
$this->assertTrue(is_array($actor->avatarLinks));
|
static::assertTrue(is_array($actor->avatarLinks));
|
||||||
$this->assertEquals(1, count($actor->avatarLinks));
|
static::assertSame(1, count($actor->avatarLinks));
|
||||||
$this->assertEquals('http://files.posterous.com/user_profile_pics/480326/2009-08-05-142447.jpg',
|
static::assertSame(
|
||||||
$actor->avatarLinks[0]->url);
|
'http://files.posterous.com/user_profile_pics/480326/2009-08-05-142447.jpg',
|
||||||
$this->assertNotNull($actor->poco);
|
$actor->avatarLinks[0]->url
|
||||||
$this->assertEquals('evanpro', $actor->poco->preferredUsername);
|
);
|
||||||
$this->assertEquals('Evan Prodromou', $actor->poco->displayName);
|
static::assertNotNull($actor->poco);
|
||||||
$this->assertNull($actor->poco->note);
|
static::assertSame('evanpro', $actor->poco->preferredUsername);
|
||||||
$this->assertNull($actor->poco->address);
|
static::assertSame('Evan Prodromou', $actor->poco->displayName);
|
||||||
$this->assertEquals(0, count($actor->poco->urls));
|
static::assertNull($actor->poco->note);
|
||||||
|
static::assertNull($actor->poco->address);
|
||||||
|
static::assertSame(0, count($actor->poco->urls));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Media test - cliqset
|
// Media test - cliqset
|
||||||
@ -309,145 +312,144 @@ final class ActivityParseTests extends TestCase
|
|||||||
|
|
||||||
$act = new Activity($entry, $feed);
|
$act = new Activity($entry, $feed);
|
||||||
|
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
$this->assertEquals($act->time, 1269221753);
|
static::assertSame($act->time, 1269221753);
|
||||||
$this->assertEquals($act->verb, ActivityVerb::POST);
|
static::assertSame($act->verb, ActivityVerb::POST);
|
||||||
$this->assertEquals($act->summary, 'zcopley posted 5 photos on Flickr');
|
static::assertSame($act->summary, 'zcopley posted 5 photos on Flickr');
|
||||||
|
|
||||||
$this->assertFalse(empty($act->objects));
|
static::assertFalse(empty($act->objects));
|
||||||
$this->assertEquals(sizeof($act->objects), 5);
|
static::assertSame(sizeof($act->objects), 5);
|
||||||
|
|
||||||
$this->assertEquals($act->objects[0]->type, ActivityObject::PHOTO);
|
static::assertSame($act->objects[0]->type, ActivityObject::PHOTO);
|
||||||
$this->assertEquals($act->objects[0]->title, 'IMG_1368');
|
static::assertSame($act->objects[0]->title, 'IMG_1368');
|
||||||
$this->assertNull($act->objects[0]->description);
|
static::assertNull($act->objects[0]->description);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[0]->thumbnail,
|
$act->objects[0]->thumbnail,
|
||||||
'http://media.cliqset.com/6f6fbee9d7dfbffc73b6ef626275eb5f_thumb.jpg'
|
'http://media.cliqset.com/6f6fbee9d7dfbffc73b6ef626275eb5f_thumb.jpg'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[0]->link,
|
$act->objects[0]->link,
|
||||||
'http://www.flickr.com/photos/zcopley/4452933806/'
|
'http://www.flickr.com/photos/zcopley/4452933806/'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($act->objects[1]->type, ActivityObject::PHOTO);
|
static::assertSame($act->objects[1]->type, ActivityObject::PHOTO);
|
||||||
$this->assertEquals($act->objects[1]->title, 'IMG_1365');
|
static::assertSame($act->objects[1]->title, 'IMG_1365');
|
||||||
$this->assertNull($act->objects[1]->description);
|
static::assertNull($act->objects[1]->description);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[1]->thumbnail,
|
$act->objects[1]->thumbnail,
|
||||||
'http://media.cliqset.com/b8f3932cd0bba1b27f7c8b3ef986915e_thumb.jpg'
|
'http://media.cliqset.com/b8f3932cd0bba1b27f7c8b3ef986915e_thumb.jpg'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[1]->link,
|
$act->objects[1]->link,
|
||||||
'http://www.flickr.com/photos/zcopley/4442630390/'
|
'http://www.flickr.com/photos/zcopley/4442630390/'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($act->objects[2]->type, ActivityObject::PHOTO);
|
static::assertSame($act->objects[2]->type, ActivityObject::PHOTO);
|
||||||
$this->assertEquals($act->objects[2]->title, 'Classic');
|
static::assertSame($act->objects[2]->title, 'Classic');
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[2]->description,
|
$act->objects[2]->description,
|
||||||
'-Powered by pikchur.com/n0u'
|
'-Powered by pikchur.com/n0u'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[2]->thumbnail,
|
$act->objects[2]->thumbnail,
|
||||||
'http://media.cliqset.com/fc54c15f850b7a9a8efa644087a48c91_thumb.jpg'
|
'http://media.cliqset.com/fc54c15f850b7a9a8efa644087a48c91_thumb.jpg'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[2]->link,
|
$act->objects[2]->link,
|
||||||
'http://www.flickr.com/photos/zcopley/4430754103/'
|
'http://www.flickr.com/photos/zcopley/4430754103/'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($act->objects[3]->type, ActivityObject::PHOTO);
|
static::assertSame($act->objects[3]->type, ActivityObject::PHOTO);
|
||||||
$this->assertEquals($act->objects[3]->title, 'IMG_1363');
|
static::assertSame($act->objects[3]->title, 'IMG_1363');
|
||||||
$this->assertNull($act->objects[3]->description);
|
static::assertNull($act->objects[3]->description);
|
||||||
|
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[3]->thumbnail,
|
$act->objects[3]->thumbnail,
|
||||||
'http://media.cliqset.com/4b1d307c9217e2114391a8b229d612cb_thumb.jpg'
|
'http://media.cliqset.com/4b1d307c9217e2114391a8b229d612cb_thumb.jpg'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[3]->link,
|
$act->objects[3]->link,
|
||||||
'http://www.flickr.com/photos/zcopley/4416969717/'
|
'http://www.flickr.com/photos/zcopley/4416969717/'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($act->objects[4]->type, ActivityObject::PHOTO);
|
static::assertSame($act->objects[4]->type, ActivityObject::PHOTO);
|
||||||
$this->assertEquals($act->objects[4]->title, 'IMG_1361');
|
static::assertSame($act->objects[4]->title, 'IMG_1361');
|
||||||
$this->assertNull($act->objects[4]->description);
|
static::assertNull($act->objects[4]->description);
|
||||||
|
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[4]->thumbnail,
|
$act->objects[4]->thumbnail,
|
||||||
'http://media.cliqset.com/23d9b4b96b286e0347d36052f22f6e60_thumb.jpg'
|
'http://media.cliqset.com/23d9b4b96b286e0347d36052f22f6e60_thumb.jpg'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$act->objects[4]->link,
|
$act->objects[4]->link,
|
||||||
'http://www.flickr.com/photos/zcopley/4417734232/'
|
'http://www.flickr.com/photos/zcopley/4417734232/'
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAtomContent()
|
public function testAtomContent()
|
||||||
{
|
{
|
||||||
$tests = array(array("<content>Some regular plain text.</content>",
|
$tests = [['<content>Some regular plain text.</content>',
|
||||||
"Some regular plain text."),
|
'Some regular plain text.',],
|
||||||
array("<content><b>this is not HTML</b></content>",
|
['<content><b>this is not HTML</b></content>',
|
||||||
"<b>this is not HTML</b>"),
|
'<b>this is not HTML</b>',],
|
||||||
array("<content type='html'>Some regular plain HTML.</content>",
|
["<content type='html'>Some regular plain HTML.</content>",
|
||||||
"Some regular plain HTML."),
|
'Some regular plain HTML.',],
|
||||||
array("<content type='html'><b>this is too HTML</b></content>",
|
["<content type='html'><b>this is too HTML</b></content>",
|
||||||
"<b>this is too HTML</b>"),
|
'<b>this is too HTML</b>',],
|
||||||
array("<content type='html'>&lt;b&gt;but this is not HTML!&lt;/b&gt;</content>",
|
["<content type='html'>&lt;b&gt;but this is not HTML!&lt;/b&gt;</content>",
|
||||||
"<b>but this is not HTML!</b>"),
|
'<b>but this is not HTML!</b>',],
|
||||||
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Some regular plain XHTML.</div></content>",
|
["<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Some regular plain XHTML.</div></content>",
|
||||||
"Some regular plain XHTML."),
|
'Some regular plain XHTML.',],
|
||||||
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><b>This is some XHTML!</b></div></content>",
|
["<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><b>This is some XHTML!</b></div></content>",
|
||||||
"<b>This is some XHTML!</b>"),
|
'<b>This is some XHTML!</b>',],
|
||||||
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><b>This is not some XHTML!</b></div></content>",
|
["<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><b>This is not some XHTML!</b></div></content>",
|
||||||
"<b>This is not some XHTML!</b>"),
|
'<b>This is not some XHTML!</b>',],
|
||||||
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&lt;b&gt;This is not some XHTML either!&lt;/b&gt;</div></content>",
|
["<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&lt;b&gt;This is not some XHTML either!&lt;/b&gt;</div></content>",
|
||||||
"&lt;b&gt;This is not some XHTML either!&lt;/b&gt;"));
|
'&lt;b&gt;This is not some XHTML either!&lt;/b&gt;',],];
|
||||||
foreach ($tests as $data) {
|
foreach ($tests as $data) {
|
||||||
list($source, $output) = $data;
|
list($source, $output) = $data;
|
||||||
$xml = "<entry xmlns='http://www.w3.org/2005/Atom'>" .
|
$xml = "<entry xmlns='http://www.w3.org/2005/Atom'>" .
|
||||||
"<id>http://example.com/fakeid</id>" .
|
'<id>http://example.com/fakeid</id>' .
|
||||||
"<author><name>Test</name></author>" .
|
'<author><name>Test</name></author>' .
|
||||||
"<title>Atom content tests</title>" .
|
'<title>Atom content tests</title>' .
|
||||||
$source .
|
$source .
|
||||||
"</entry>";
|
'</entry>';
|
||||||
$dom = new DOMDocument();
|
$dom = new DOMDocument();
|
||||||
$dom->loadXML($xml);
|
$dom->loadXML($xml);
|
||||||
$act = new Activity($dom->documentElement);
|
$act = new Activity($dom->documentElement);
|
||||||
|
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
$this->assertEquals($output, trim($act->content));
|
static::assertSame($output, trim($act->content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRssContent()
|
public function testRssContent()
|
||||||
{
|
{
|
||||||
$tests = array(array("<content:encoded>Some regular plain HTML.</content:encoded>",
|
$tests = [['<content:encoded>Some regular plain HTML.</content:encoded>',
|
||||||
"Some regular plain HTML."),
|
'Some regular plain HTML.',],
|
||||||
array("<content:encoded>Some <b>exciting bold HTML</b></content:encoded>",
|
['<content:encoded>Some <b>exciting bold HTML</b></content:encoded>',
|
||||||
"Some <b>exciting bold HTML</b>"),
|
'Some <b>exciting bold HTML</b>',],
|
||||||
array("<content:encoded>Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;</content:encoded>",
|
['<content:encoded>Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;</content:encoded>',
|
||||||
"Some <b>escaped non-HTML.</b>"),
|
'Some <b>escaped non-HTML.</b>',],
|
||||||
array("<description>Some plain text.</description>",
|
['<description>Some plain text.</description>',
|
||||||
"Some plain text."),
|
'Some plain text.',],
|
||||||
array("<description>Some <b>non-HTML text</b></description>",
|
['<description>Some <b>non-HTML text</b></description>',
|
||||||
"Some <b>non-HTML text</b>"),
|
'Some <b>non-HTML text</b>',],
|
||||||
array("<description>Some &lt;b&gt;double-escaped text&lt;/b&gt;</description>",
|
['<description>Some &lt;b&gt;double-escaped text&lt;/b&gt;</description>',
|
||||||
"Some &lt;b&gt;double-escaped text&lt;/b&gt;"));
|
'Some &lt;b&gt;double-escaped text&lt;/b&gt;',],];
|
||||||
foreach ($tests as $data) {
|
foreach ($tests as $data) {
|
||||||
list($source, $output) = $data;
|
list($source, $output) = $data;
|
||||||
$xml = "<item xmlns:content='http://purl.org/rss/1.0/modules/content/'>" .
|
$xml = "<item xmlns:content='http://purl.org/rss/1.0/modules/content/'>" .
|
||||||
"<guid>http://example.com/fakeid</guid>" .
|
'<guid>http://example.com/fakeid</guid>' .
|
||||||
"<title>RSS content tests</title>" .
|
'<title>RSS content tests</title>' .
|
||||||
$source .
|
$source .
|
||||||
"</item>";
|
'</item>';
|
||||||
$dom = new DOMDocument();
|
$dom = new DOMDocument();
|
||||||
$dom->loadXML($xml);
|
$dom->loadXML($xml);
|
||||||
$act = new Activity($dom->documentElement);
|
$act = new Activity($dom->documentElement);
|
||||||
|
|
||||||
$this->assertFalse(empty($act));
|
static::assertFalse(empty($act));
|
||||||
$this->assertEquals($output, trim($act->content));
|
static::assertSame($output, trim($act->content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,13 +468,13 @@ final class ActivityParseTests extends TestCase
|
|||||||
// Reading just the entry alone should pick up its own <author>
|
// Reading just the entry alone should pick up its own <author>
|
||||||
// as the actor.
|
// as the actor.
|
||||||
$act = new Activity($entry);
|
$act = new Activity($entry);
|
||||||
$this->assertEquals($act->actor->id, $expected);
|
static::assertSame($act->actor->id, $expected);
|
||||||
|
|
||||||
// Reading the entry in feed context used to be buggy, picking up
|
// Reading the entry in feed context used to be buggy, picking up
|
||||||
// the feed's <activity:subject> which referred to the group.
|
// the feed's <activity:subject> which referred to the group.
|
||||||
// It should now be returning the expected author entry...
|
// It should now be returning the expected author entry...
|
||||||
$act = new Activity($entry, $feed);
|
$act = new Activity($entry, $feed);
|
||||||
$this->assertEquals($act->actor->id, $expected);
|
static::assertSame($act->actor->id, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBookmarkRelated()
|
public function testBookmarkRelated()
|
||||||
@ -488,13 +490,13 @@ final class ActivityParseTests extends TestCase
|
|||||||
|
|
||||||
$links = ActivityUtils::getLinks($entry, 'related');
|
$links = ActivityUtils::getLinks($entry, 'related');
|
||||||
|
|
||||||
$this->assertFalse(empty($links));
|
static::assertFalse(empty($links));
|
||||||
$this->assertTrue(is_array($links));
|
static::assertTrue(is_array($links));
|
||||||
$this->assertEquals(count($links), 1);
|
static::assertSame(count($links), 1);
|
||||||
|
|
||||||
$url = $links[0]->getAttribute('href');
|
$url = $links[0]->getAttribute('href');
|
||||||
|
|
||||||
$this->assertEquals($url, $expected);
|
static::assertSame($url, $expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ final class CallableLeftCurryTest extends TestCase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider provider
|
* @dataProvider provider
|
||||||
|
*
|
||||||
* @param $callback_test
|
* @param $callback_test
|
||||||
* @param $curry_params
|
* @param $curry_params
|
||||||
* @param $call_params
|
* @param $call_params
|
||||||
@ -41,42 +42,42 @@ final class CallableLeftCurryTest extends TestCase
|
|||||||
$params = array_merge([$callback_test], $curry_params);
|
$params = array_merge([$callback_test], $curry_params);
|
||||||
$curried = call_user_func_array('callableLeftCurry', $params);
|
$curried = call_user_func_array('callableLeftCurry', $params);
|
||||||
$result = call_user_func_array($curried, $call_params);
|
$result = call_user_func_array($curried, $call_params);
|
||||||
$this->assertEquals($expected, $result);
|
static::assertSame($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function provider()
|
public static function provider()
|
||||||
{
|
{
|
||||||
$obj = new CurryTestHelperObj('oldval');
|
$obj = new CurryTestHelperObj('oldval');
|
||||||
return [[['Tests\Unit\CallableLeftCurryTest', 'callback_test'],
|
return [[['Tests\Unit\CallableLeftCurryTest', 'callback_test'],
|
||||||
['curried'],
|
['curried'],
|
||||||
['called'],
|
['called'],
|
||||||
'called|curried'],
|
'called|curried',],
|
||||||
[['Tests\Unit\CallableLeftCurryTest', 'callback_test'],
|
[['Tests\Unit\CallableLeftCurryTest', 'callback_test'],
|
||||||
['curried1', 'curried2'],
|
['curried1', 'curried2'],
|
||||||
['called1', 'called2'],
|
['called1', 'called2'],
|
||||||
'called1|called2|curried1|curried2'],
|
'called1|called2|curried1|curried2',],
|
||||||
[['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'],
|
[['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'],
|
||||||
[$obj],
|
[$obj],
|
||||||
['newval1'],
|
['newval1'],
|
||||||
'oldval|newval1'],
|
'oldval|newval1',],
|
||||||
// Confirm object identity is retained...
|
// Confirm object identity is retained...
|
||||||
[['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'],
|
[['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'],
|
||||||
[$obj],
|
[$obj],
|
||||||
['newval2'],
|
['newval2'],
|
||||||
'newval1|newval2']];
|
'newval1|newval2',],];
|
||||||
}
|
}
|
||||||
|
|
||||||
static function callback_test()
|
public static function callback_test()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
return implode("|", $args);
|
return implode('|', $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function callback_testObj($val, $obj)
|
public static function callback_testObj($val, $obj)
|
||||||
{
|
{
|
||||||
$old = $obj->val;
|
$old = $obj->val;
|
||||||
$obj->val = $val;
|
$obj->val = $val;
|
||||||
return "$old|$val";
|
return "{$old}|{$val}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ class CurryTestHelperObj
|
|||||||
{
|
{
|
||||||
public $val = '';
|
public $val = '';
|
||||||
|
|
||||||
function __construct($val)
|
public function __construct($val)
|
||||||
{
|
{
|
||||||
$this->val = $val;
|
$this->val = $val;
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,16 @@ use User;
|
|||||||
|
|
||||||
require_once INSTALLDIR . '/lib/util/common.php';
|
require_once INSTALLDIR . '/lib/util/common.php';
|
||||||
|
|
||||||
final class CommandInterpreterTest extends TestCase
|
final class CommandInterperterTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider commandInterpreterCases
|
* @dataProvider commandInterpreterCases
|
||||||
|
*
|
||||||
* @param $input
|
* @param $input
|
||||||
* @param $expectedType
|
* @param $expectedType
|
||||||
* @param string $comment
|
* @param string $comment
|
||||||
|
* @throws \EmptyPkeyValueException
|
||||||
|
* @throws \ServerException
|
||||||
*/
|
*/
|
||||||
public function testCommandInterpreter($input, $expectedType, $comment = '')
|
public function testCommandInterpreter($input, $expectedType, $comment = '')
|
||||||
{
|
{
|
||||||
@ -51,148 +53,147 @@ final class CommandInterpreterTest extends TestCase
|
|||||||
$cmd = $inter->handle_command(User::getById(1), $input);
|
$cmd = $inter->handle_command(User::getById(1), $input);
|
||||||
|
|
||||||
$type = $cmd ? get_class($cmd) : null;
|
$type = $cmd ? get_class($cmd) : null;
|
||||||
$this->assertEquals(strtolower($expectedType), strtolower($type), $comment);
|
static::assertSame(strtolower($expectedType), strtolower($type), $comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function commandInterpreterCases()
|
public static function commandInterpreterCases()
|
||||||
{
|
{
|
||||||
$sets = array(
|
$sets = [
|
||||||
array('help', 'HelpCommand'),
|
['help', 'HelpCommand'],
|
||||||
array('help me bro', null, 'help does not accept multiple params'),
|
['help me bro', null, 'help does not accept multiple params'],
|
||||||
array('HeLP', 'HelpCommand', 'case check'),
|
['HeLP', 'HelpCommand', 'case check'],
|
||||||
array('HeLP Me BRO!', null, 'case & non-params check'),
|
['HeLP Me BRO!', null, 'case & non-params check'],
|
||||||
|
|
||||||
array('login', 'LoginCommand'),
|
['login', 'LoginCommand'],
|
||||||
array('login to savings!', null, 'login does not accept params'),
|
['login to savings!', null, 'login does not accept params'],
|
||||||
|
|
||||||
array('lose', null, 'lose must have at least 1 parameter'),
|
['lose', null, 'lose must have at least 1 parameter'],
|
||||||
array('lose foobar', 'LoseCommand', 'lose requires 1 parameter'),
|
['lose foobar', 'LoseCommand', 'lose requires 1 parameter'],
|
||||||
array('lose foobar', 'LoseCommand', 'check for space norm'),
|
['lose foobar', 'LoseCommand', 'check for space norm'],
|
||||||
array('lose more weight', null, 'lose does not accept multiple params'),
|
['lose more weight', null, 'lose does not accept multiple params'],
|
||||||
|
|
||||||
array('subscribers', 'SubscribersCommand'),
|
['subscribers', 'SubscribersCommand'],
|
||||||
array('subscribers foo', null, 'subscribers does not take params'),
|
['subscribers foo', null, 'subscribers does not take params'],
|
||||||
|
|
||||||
array('subscriptions', 'SubscriptionsCommand'),
|
['subscriptions', 'SubscriptionsCommand'],
|
||||||
array('subscriptions foo', null, 'subscriptions does not take params'),
|
['subscriptions foo', null, 'subscriptions does not take params'],
|
||||||
|
|
||||||
array('groups', 'GroupsCommand'),
|
['groups', 'GroupsCommand'],
|
||||||
array('groups foo', null, 'groups does not take params'),
|
['groups foo', null, 'groups does not take params'],
|
||||||
|
|
||||||
array('off', 'OffCommand', 'off accepts 0 or 1 params'),
|
['off', 'OffCommand', 'off accepts 0 or 1 params'],
|
||||||
array('off foo', 'OffCommand', 'off accepts 0 or 1 params'),
|
['off foo', 'OffCommand', 'off accepts 0 or 1 params'],
|
||||||
array('off foo bar', null, 'off accepts 0 or 1 params'),
|
['off foo bar', null, 'off accepts 0 or 1 params'],
|
||||||
|
|
||||||
array('stop', 'OffCommand', 'stop accepts 0 params'),
|
['stop', 'OffCommand', 'stop accepts 0 params'],
|
||||||
array('stop foo', null, 'stop accepts 0 params'),
|
['stop foo', null, 'stop accepts 0 params'],
|
||||||
|
|
||||||
array('quit', 'OffCommand', 'quit accepts 0 params'),
|
['quit', 'OffCommand', 'quit accepts 0 params'],
|
||||||
array('quit foo', null, 'quit accepts 0 params'),
|
['quit foo', null, 'quit accepts 0 params'],
|
||||||
|
|
||||||
array('on', 'OnCommand', 'on accepts 0 or 1 params'),
|
['on', 'OnCommand', 'on accepts 0 or 1 params'],
|
||||||
array('on foo', 'OnCommand', 'on accepts 0 or 1 params'),
|
['on foo', 'OnCommand', 'on accepts 0 or 1 params'],
|
||||||
array('on foo bar', null, 'on accepts 0 or 1 params'),
|
['on foo bar', null, 'on accepts 0 or 1 params'],
|
||||||
|
|
||||||
array('join', null),
|
['join', null],
|
||||||
array('join foo', 'JoinCommand'),
|
['join foo', 'JoinCommand'],
|
||||||
array('join foo bar', null),
|
['join foo bar', null],
|
||||||
|
|
||||||
array('drop', null),
|
['drop', null],
|
||||||
array('drop foo', 'DropCommand'),
|
['drop foo', 'DropCommand'],
|
||||||
array('drop foo bar', null),
|
['drop foo bar', null],
|
||||||
|
|
||||||
array('follow', null),
|
['follow', null],
|
||||||
array('follow foo', 'SubCommand'),
|
['follow foo', 'SubCommand'],
|
||||||
array('follow foo bar', null),
|
['follow foo bar', null],
|
||||||
|
|
||||||
array('sub', null),
|
['sub', null],
|
||||||
array('sub foo', 'SubCommand'),
|
['sub foo', 'SubCommand'],
|
||||||
array('sub foo bar', null),
|
['sub foo bar', null],
|
||||||
|
|
||||||
array('leave', null),
|
['leave', null],
|
||||||
array('leave foo', 'UnsubCommand'),
|
['leave foo', 'UnsubCommand'],
|
||||||
array('leave foo bar', null),
|
['leave foo bar', null],
|
||||||
|
|
||||||
array('unsub', null),
|
['unsub', null],
|
||||||
array('unsub foo', 'UnsubCommand'),
|
['unsub foo', 'UnsubCommand'],
|
||||||
array('unsub foo bar', null),
|
['unsub foo bar', null],
|
||||||
|
|
||||||
array('leave', null),
|
['leave', null],
|
||||||
array('leave foo', 'UnsubCommand'),
|
['leave foo', 'UnsubCommand'],
|
||||||
array('leave foo bar', null),
|
['leave foo bar', null],
|
||||||
|
|
||||||
array('d', null),
|
['d', null],
|
||||||
array('d foo', null),
|
['d foo', null],
|
||||||
array('d foo bar', 'MessageCommand'),
|
['d foo bar', 'MessageCommand'],
|
||||||
|
|
||||||
array('dm', null),
|
['dm', null],
|
||||||
array('dm foo', null),
|
['dm foo', null],
|
||||||
array('dm foo bar', 'MessageCommand'),
|
['dm foo bar', 'MessageCommand'],
|
||||||
|
|
||||||
array('r', null),
|
['r', null],
|
||||||
array('r foo', null),
|
['r foo', null],
|
||||||
array('r foo bar', 'ReplyCommand'),
|
['r foo bar', 'ReplyCommand'],
|
||||||
|
|
||||||
array('reply', null),
|
['reply', null],
|
||||||
array('reply foo', null),
|
['reply foo', null],
|
||||||
array('reply foo bar', 'ReplyCommand'),
|
['reply foo bar', 'ReplyCommand'],
|
||||||
|
|
||||||
array('repeat', null),
|
['repeat', null],
|
||||||
array('repeat foo', 'RepeatCommand'),
|
['repeat foo', 'RepeatCommand'],
|
||||||
array('repeat foo bar', null),
|
['repeat foo bar', null],
|
||||||
|
|
||||||
array('rp', null),
|
['rp', null],
|
||||||
array('rp foo', 'RepeatCommand'),
|
['rp foo', 'RepeatCommand'],
|
||||||
array('rp foo bar', null),
|
['rp foo bar', null],
|
||||||
|
|
||||||
array('rt', null),
|
['rt', null],
|
||||||
array('rt foo', 'RepeatCommand'),
|
['rt foo', 'RepeatCommand'],
|
||||||
array('rt foo bar', null),
|
['rt foo bar', null],
|
||||||
|
|
||||||
array('rd', null),
|
['rd', null],
|
||||||
array('rd foo', 'RepeatCommand'),
|
['rd foo', 'RepeatCommand'],
|
||||||
array('rd foo bar', null),
|
['rd foo bar', null],
|
||||||
|
|
||||||
array('whois', null),
|
['whois', null],
|
||||||
array('whois foo', 'WhoisCommand'),
|
['whois foo', 'WhoisCommand'],
|
||||||
array('whois foo bar', null),
|
['whois foo bar', null],
|
||||||
|
|
||||||
/* array('fav', null),
|
/* array('fav', null),
|
||||||
array('fav foo', 'FavCommand'),
|
array('fav foo', 'FavCommand'),
|
||||||
array('fav foo bar', null),*/
|
array('fav foo bar', null),*/
|
||||||
|
|
||||||
array('nudge', null),
|
['nudge', null],
|
||||||
array('nudge foo', 'NudgeCommand'),
|
['nudge foo', 'NudgeCommand'],
|
||||||
array('nudge foo bar', null),
|
['nudge foo bar', null],
|
||||||
|
|
||||||
array('stats', 'StatsCommand'),
|
['stats', 'StatsCommand'],
|
||||||
array('stats foo', null),
|
['stats foo', null],
|
||||||
|
|
||||||
array('invite', null),
|
['invite', null],
|
||||||
array('invite foo', 'InviteCommand'),
|
['invite foo', 'InviteCommand'],
|
||||||
array('invite foo bar', null),
|
['invite foo bar', null],
|
||||||
|
|
||||||
array('track', null),
|
['track', null],
|
||||||
array('track foo', 'SearchSubTrackCommand'),
|
['track foo', 'SearchSubTrackCommand'],
|
||||||
array('track off', 'SearchSubTrackOffCommand'),
|
['track off', 'SearchSubTrackOffCommand'],
|
||||||
array('track foo bar', null),
|
['track foo bar', null],
|
||||||
array('track off foo', null),
|
['track off foo', null],
|
||||||
|
|
||||||
array('untrack', null),
|
['untrack', null],
|
||||||
array('untrack foo', 'SearchSubUntrackCommand'),
|
['untrack foo', 'SearchSubUntrackCommand'],
|
||||||
array('untrack all', 'SearchSubTrackOffCommand'),
|
['untrack all', 'SearchSubTrackOffCommand'],
|
||||||
array('untrack foo bar', null),
|
['untrack foo bar', null],
|
||||||
array('untrack all foo', null),
|
['untrack all foo', null],
|
||||||
|
|
||||||
array('tracking', 'SearchSubTrackingCommand'),
|
['tracking', 'SearchSubTrackingCommand'],
|
||||||
array('tracking foo', null),
|
['tracking foo', null],
|
||||||
|
|
||||||
array('tracks', 'SearchSubTrackingCommand'),
|
['tracks', 'SearchSubTrackingCommand'],
|
||||||
array('tracks foo', null),
|
['tracks foo', null],
|
||||||
|
|
||||||
);
|
];
|
||||||
return $sets;
|
return $sets;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,50 +37,51 @@ final class HashTagDetectionTests extends TestCase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider provider
|
* @dataProvider provider
|
||||||
|
*
|
||||||
* @param $content
|
* @param $content
|
||||||
* @param $expected
|
* @param $expected
|
||||||
*/
|
*/
|
||||||
public function testProduction($content, $expected)
|
public function testProduction($content, $expected)
|
||||||
{
|
{
|
||||||
$rendered = common_render_text($content);
|
$rendered = common_render_text($content);
|
||||||
$this->assertEquals($expected, $rendered);
|
static::assertSame($expected, $rendered);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function provider()
|
public static function provider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('hello',
|
['hello',
|
||||||
'hello'),
|
'hello',],
|
||||||
array('#hello people',
|
['#hello people',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span> people'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span> people',],
|
||||||
array('"#hello" people',
|
['"#hello" people',
|
||||||
'"#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>" people'),
|
'"#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>" people',],
|
||||||
array('say "#hello" people',
|
['say "#hello" people',
|
||||||
'say "#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>" people'),
|
'say "#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>" people',],
|
||||||
array('say (#hello) people',
|
['say (#hello) people',
|
||||||
'say (#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>) people'),
|
'say (#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>) people',],
|
||||||
array('say [#hello] people',
|
['say [#hello] people',
|
||||||
'say [#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>] people'),
|
'say [#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>] people',],
|
||||||
array('say {#hello} people',
|
['say {#hello} people',
|
||||||
'say {#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>} people'),
|
'say {#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>} people',],
|
||||||
array('say \'#hello\' people',
|
['say \'#hello\' people',
|
||||||
'say \'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>\' people'),
|
'say \'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>\' people',],
|
||||||
|
|
||||||
// Unicode legit letters
|
// Unicode legit letters
|
||||||
array('#éclair yummy',
|
['#éclair yummy',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('éclair'))) . '" rel="tag">éclair</a></span> yummy'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('éclair')]) . '" rel="tag">éclair</a></span> yummy',],
|
||||||
array('#维基百科 zh.wikipedia!',
|
['#维基百科 zh.wikipedia!',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span> zh.wikipedia!'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span> zh.wikipedia!',],
|
||||||
array('#Россия russia',
|
['#Россия russia',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('Россия'))) . '" rel="tag">Россия</a></span> russia'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('Россия')]) . '" rel="tag">Россия</a></span> russia',],
|
||||||
|
|
||||||
// Unicode punctuators -- the ideographic "," separates the tag, just as "," does
|
// Unicode punctuators -- the ideographic "," separates the tag, just as "," does
|
||||||
array('#维基百科,zh.wikipedia!',
|
['#维基百科,zh.wikipedia!',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span>,zh.wikipedia!',],
|
||||||
array('#维基百科,zh.wikipedia!',
|
['#维基百科,zh.wikipedia!',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span>,zh.wikipedia!',],
|
||||||
|
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,86 +42,85 @@ addPlugin('Geonames');
|
|||||||
|
|
||||||
final class LocationTest extends TestCase
|
final class LocationTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider locationNames
|
* @dataProvider locationNames
|
||||||
|
*
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param $language
|
* @param $language
|
||||||
* @param $location
|
* @param $location
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function testLocationFromName($name, $language, $location)
|
public function testLocationFromName($name, $language, $location)
|
||||||
{
|
{
|
||||||
$result = Location::fromName($name, $language);
|
$result = Location::fromName($name, $language);
|
||||||
$this->assertEquals($result, $location);
|
static::assertSame($result, $location);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function locationNames()
|
public static function locationNames()
|
||||||
{
|
{
|
||||||
return array(array('Montreal', 'en', null),
|
return [['Montreal', 'en', null],
|
||||||
array('San Francisco, CA', 'en', null),
|
['San Francisco, CA', 'en', null],
|
||||||
array('Paris, France', 'en', null),
|
['Paris, France', 'en', null],
|
||||||
array('Paris, Texas', 'en', null));
|
['Paris, Texas', 'en', null],];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider locationIds
|
* @dataProvider locationIds
|
||||||
|
*
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param $ns
|
* @param $ns
|
||||||
* @param $language
|
* @param $language
|
||||||
* @param $location
|
* @param $location
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function testLocationFromId($id, $ns, $language, $location)
|
public function testLocationFromId($id, $ns, $language, $location)
|
||||||
{
|
{
|
||||||
$result = Location::fromId($id, $ns, $language);
|
$result = Location::fromId($id, $ns, $language);
|
||||||
$this->assertEquals($result, $location);
|
static::assertSame($result, $location);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function locationIds()
|
public static function locationIds()
|
||||||
{
|
{
|
||||||
return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
|
return [[6077243, GeonamesPlugin::LOCATION_NS, 'en', null],
|
||||||
array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
|
[5391959, GeonamesPlugin::LOCATION_NS, 'en', null],];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider locationLatLons
|
* @dataProvider locationLatLons
|
||||||
|
*
|
||||||
* @param $lat
|
* @param $lat
|
||||||
* @param $lon
|
* @param $lon
|
||||||
* @param $language
|
* @param $language
|
||||||
* @param $location
|
* @param $location
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function testLocationFromLatLon($lat, $lon, $language, $location)
|
public function testLocationFromLatLon($lat, $lon, $language, $location)
|
||||||
{
|
{
|
||||||
$result = Location::fromLatLon($lat, $lon, $language);
|
$result = Location::fromLatLon($lat, $lon, $language);
|
||||||
$this->assertEquals($location, $result->location_id);
|
static::assertSame($location, $result->location_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function locationLatLons()
|
public static function locationLatLons()
|
||||||
{
|
{
|
||||||
return array(array(37.77493, -122.41942, 'en', null),
|
return [[37.77493, -122.41942, 'en', null],
|
||||||
array(45.509, -73.588, 'en', null));
|
[45.509, -73.588, 'en', null],];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider nameOfLocation
|
* @dataProvider nameOfLocation
|
||||||
|
*
|
||||||
* @param $location
|
* @param $location
|
||||||
* @param $language
|
* @param $language
|
||||||
* @param $name
|
* @param $name
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function testLocationGetName($location, $language, $name)
|
public function testLocationGetName($location, $language, $name)
|
||||||
{
|
{
|
||||||
$result = empty($location) ? null : $location->getName($language);
|
$result = empty($location) ? null : $location->getName($language);
|
||||||
$this->assertEquals($name, $result);
|
static::assertSame($name, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function nameOfLocation()
|
public static function nameOfLocation()
|
||||||
{
|
{
|
||||||
$loc = Location::fromName('Montreal', 'en');
|
$loc = Location::fromName('Montreal', 'en');
|
||||||
return array(array($loc, 'en', null), //'Montreal'),
|
return [[$loc, 'en', null], //'Montreal'),
|
||||||
array($loc, 'fr', null));//'Montréal'));
|
[$loc, 'fr', null],]; //'Montréal'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ final class NicknameTest extends TestCase
|
|||||||
* Basic test using Nickname::normalize()
|
* Basic test using Nickname::normalize()
|
||||||
*
|
*
|
||||||
* @dataProvider provider
|
* @dataProvider provider
|
||||||
|
*
|
||||||
* @param $input
|
* @param $input
|
||||||
* @param $expected
|
* @param $expected
|
||||||
* @param null $expectedException
|
* @param null $expectedException
|
||||||
@ -71,25 +72,25 @@ final class NicknameTest extends TestCase
|
|||||||
} else {
|
} else {
|
||||||
$stuff = var_export($exception, true);
|
$stuff = var_export($exception, true);
|
||||||
}
|
}
|
||||||
$this->assertTrue(
|
static::assertTrue(
|
||||||
$exception && $exception instanceof $expectedException,
|
$exception && $exception instanceof $expectedException,
|
||||||
"invalid input '$input' expected to fail with $expectedException, " .
|
"invalid input '{$input}' expected to fail with {$expectedException}, " .
|
||||||
"got $stuff"
|
"got {$stuff}"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->assertTrue(
|
static::assertTrue(
|
||||||
$normalized == false,
|
$normalized == false,
|
||||||
"invalid input '$input' expected to fail"
|
"invalid input '{$input}' expected to fail"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$msg = "normalized input nickname '$input' expected to normalize to '$expected', got ";
|
$msg = "normalized input nickname '{$input}' expected to normalize to '{$expected}', got ";
|
||||||
if ($exception) {
|
if ($exception) {
|
||||||
$msg .= get_class($exception) . ': ' . $exception->getMessage();
|
$msg .= get_class($exception) . ': ' . $exception->getMessage();
|
||||||
} else {
|
} else {
|
||||||
$msg .= "'$normalized'";
|
$msg .= "'{$normalized}'";
|
||||||
}
|
}
|
||||||
$this->assertEquals($expected, $normalized, $msg);
|
static::assertSame($expected, $normalized, $msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +100,11 @@ final class NicknameTest extends TestCase
|
|||||||
* to be able to pull from global state)
|
* to be able to pull from global state)
|
||||||
*
|
*
|
||||||
* @dataProvider provider
|
* @dataProvider provider
|
||||||
|
*
|
||||||
* @param $input
|
* @param $input
|
||||||
* @param $expected
|
* @param $expected
|
||||||
* @param null $expectedException
|
* @param null $expectedException
|
||||||
|
*
|
||||||
* @throws NicknameBlacklistedException
|
* @throws NicknameBlacklistedException
|
||||||
* @throws NicknameEmptyException
|
* @throws NicknameEmptyException
|
||||||
* @throws NicknameException
|
* @throws NicknameException
|
||||||
@ -117,47 +120,47 @@ final class NicknameTest extends TestCase
|
|||||||
} else {
|
} else {
|
||||||
$text = "@{$input} awesome! :)";
|
$text = "@{$input} awesome! :)";
|
||||||
$matches = common_find_mentions_raw($text);
|
$matches = common_find_mentions_raw($text);
|
||||||
$this->assertCount(1, $matches);
|
static::assertCount(1, $matches);
|
||||||
$this->assertEquals($expected, Nickname::normalize($matches[0][0]));
|
static::assertSame($expected, Nickname::normalize($matches[0][0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function provider()
|
public static function provider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('evan', 'evan'),
|
['evan', 'evan'],
|
||||||
|
|
||||||
// Case and underscore variants
|
// Case and underscore variants
|
||||||
array('Evan', 'evan'),
|
['Evan', 'evan'],
|
||||||
array('EVAN', 'evan'),
|
['EVAN', 'evan'],
|
||||||
array('ev_an', 'evan'),
|
['ev_an', 'evan'],
|
||||||
array('E__V_an', 'evan'),
|
['E__V_an', 'evan'],
|
||||||
array('evan1', 'evan1'),
|
['evan1', 'evan1'],
|
||||||
array('evan_1', 'evan1'),
|
['evan_1', 'evan1'],
|
||||||
array('0x20', '0x20'),
|
['0x20', '0x20'],
|
||||||
array('1234', '1234'), // should this be allowed though? :)
|
['1234', '1234'], // should this be allowed though? :)
|
||||||
array('12__34', '1234'),
|
['12__34', '1234'],
|
||||||
|
|
||||||
// Some (currently) invalid chars...
|
// Some (currently) invalid chars...
|
||||||
array('^#@&^#@', false, 'NicknameInvalidException'), // all invalid :D
|
['^#@&^#@', false, 'NicknameInvalidException'], // all invalid :D
|
||||||
array('ev.an', false, 'NicknameInvalidException'),
|
['ev.an', false, 'NicknameInvalidException'],
|
||||||
array('ev/an', false, 'NicknameInvalidException'),
|
['ev/an', false, 'NicknameInvalidException'],
|
||||||
array('ev an', false, 'NicknameInvalidException'),
|
['ev an', false, 'NicknameInvalidException'],
|
||||||
array('ev-an', false, 'NicknameInvalidException'),
|
['ev-an', false, 'NicknameInvalidException'],
|
||||||
|
|
||||||
// Non-ASCII letters; currently not allowed, in future
|
// Non-ASCII letters; currently not allowed, in future
|
||||||
// we'll add them at least with conversion to ASCII.
|
// we'll add them at least with conversion to ASCII.
|
||||||
// Not much use until we have storage of display names,
|
// Not much use until we have storage of display names,
|
||||||
// though.
|
// though.
|
||||||
array('évan', false, 'NicknameInvalidException'), // so far...
|
['évan', false, 'NicknameInvalidException'], // so far...
|
||||||
array('Évan', false, 'NicknameInvalidException'), // so far...
|
['Évan', false, 'NicknameInvalidException'], // so far...
|
||||||
|
|
||||||
// Length checks
|
// Length checks
|
||||||
array('', false, 'NicknameEmptyException'),
|
['', false, 'NicknameEmptyException'],
|
||||||
array('___', false, 'NicknameEmptyException'),
|
['___', false, 'NicknameEmptyException'],
|
||||||
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // 64 chars
|
['eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'], // 64 chars
|
||||||
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'), // the _ is too long...
|
['eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'], // the _ is too long...
|
||||||
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'), // 65 chars -- too long
|
['eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'], // 65 chars -- too long
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,23 +40,25 @@ final class TagURITest extends TestCase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider provider
|
* @dataProvider provider
|
||||||
|
*
|
||||||
* @param $format
|
* @param $format
|
||||||
* @param $args
|
* @param $args
|
||||||
* @param $uri
|
* @param $uri
|
||||||
*/
|
*/
|
||||||
public function testProduction($format, $args, $uri)
|
public function testProduction($format, $args, $uri)
|
||||||
{
|
{
|
||||||
$minted = call_user_func_array(array('TagURI', 'mint'),
|
$minted = call_user_func_array(
|
||||||
array_merge(array($format), $args));
|
['TagURI', 'mint'],
|
||||||
|
array_merge([$format], $args)
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals($uri, $minted);
|
static::assertSame($uri, $minted);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function provider()
|
public static function provider()
|
||||||
{
|
{
|
||||||
return array(array('favorite:%d:%d',
|
return [['favorite:%d:%d',
|
||||||
array(1, 3),
|
[1, 3],
|
||||||
'tag:example.net,' . date('Y-m-d') . ':apps:statusnet:favorite:1:3'));
|
'tag:example.net,' . date('Y-m-d') . ':apps:statusnet:favorite:1:3',]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ final class URLDetectionTest extends TestCase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider provider
|
* @dataProvider provider
|
||||||
|
*
|
||||||
* @param $content
|
* @param $content
|
||||||
* @param $expected
|
* @param $expected
|
||||||
*/
|
*/
|
||||||
@ -45,14 +46,16 @@ final class URLDetectionTest extends TestCase
|
|||||||
$rendered = common_render_text($content);
|
$rendered = common_render_text($content);
|
||||||
// hack!
|
// hack!
|
||||||
$rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered);
|
$rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered);
|
||||||
$this->assertEquals($expected, $rendered);
|
static::assertSame($expected, $rendered);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider linkifyProvider
|
* @dataProvider linkifyProvider
|
||||||
|
*
|
||||||
* @param $content
|
* @param $content
|
||||||
* @param $expected
|
* @param $expected
|
||||||
* @param $config
|
* @param $config
|
||||||
|
* @throws \ServerException
|
||||||
*/
|
*/
|
||||||
public function testLinkifyProduction($content, $expected, $config)
|
public function testLinkifyProduction($content, $expected, $config)
|
||||||
{
|
{
|
||||||
@ -60,321 +63,321 @@ final class URLDetectionTest extends TestCase
|
|||||||
// hack!
|
// hack!
|
||||||
$rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered);
|
$rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered);
|
||||||
if (common_config('linkify', $config)) {
|
if (common_config('linkify', $config)) {
|
||||||
$this->assertEquals($expected, $rendered);
|
static::assertSame($expected, $rendered);
|
||||||
} else {
|
} else {
|
||||||
$content = common_remove_unicode_formatting(nl2br(htmlspecialchars($content)));
|
$content = common_remove_unicode_formatting(nl2br(htmlspecialchars($content)));
|
||||||
$this->assertEquals($content, $rendered);
|
static::assertSame($content, $rendered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function provider()
|
public static function provider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('not a link :: no way',
|
['not a link :: no way',
|
||||||
'not a link :: no way'),
|
'not a link :: no way',],
|
||||||
array('link http://www.somesite.com/xyz/35637563@N00/52803365/ link',
|
['link http://www.somesite.com/xyz/35637563@N00/52803365/ link',
|
||||||
'link <a href="http://www.somesite.com/xyz/35637563@N00/52803365/" title="http://www.somesite.com/xyz/35637563@N00/52803365/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://www.somesite.com/xyz/35637563@N00/52803365/</a> link'),
|
'link <a href="http://www.somesite.com/xyz/35637563@N00/52803365/" title="http://www.somesite.com/xyz/35637563@N00/52803365/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://www.somesite.com/xyz/35637563@N00/52803365/</a> link',],
|
||||||
array('http://127.0.0.1',
|
['http://127.0.0.1',
|
||||||
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://127.0.0.1</a>'),
|
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://127.0.0.1</a>',],
|
||||||
array('http://[::1]:99/test.php',
|
['http://[::1]:99/test.php',
|
||||||
'<a href="http://[::1]:99/test.php" title="http://[::1]:99/test.php" rel="nofollow external">http://[::1]:99/test.php</a>'),
|
'<a href="http://[::1]:99/test.php" title="http://[::1]:99/test.php" rel="nofollow external">http://[::1]:99/test.php</a>',],
|
||||||
array('http://::1/test.php',
|
['http://::1/test.php',
|
||||||
'<a href="http://::1/test.php" title="http://::1/test.php" rel="nofollow external">http://::1/test.php</a>'),
|
'<a href="http://::1/test.php" title="http://::1/test.php" rel="nofollow external">http://::1/test.php</a>',],
|
||||||
array('http://::1',
|
['http://::1',
|
||||||
'<a href="http://::1/" title="http://::1/" rel="nofollow external">http://::1</a>'),
|
'<a href="http://::1/" title="http://::1/" rel="nofollow external">http://::1</a>',],
|
||||||
array('http://127.0.0.1',
|
['http://127.0.0.1',
|
||||||
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://127.0.0.1</a>'),
|
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://127.0.0.1</a>',],
|
||||||
array('http://example.com',
|
['http://example.com',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>',],
|
||||||
array('http://example.com.',
|
['http://example.com.',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.',],
|
||||||
array('/var/lib/example.so',
|
['/var/lib/example.so',
|
||||||
'/var/lib/example.so'),
|
'/var/lib/example.so',],
|
||||||
array('example',
|
['example',
|
||||||
'example'),
|
'example',],
|
||||||
array('mailto:user@example.com',
|
['mailto:user@example.com',
|
||||||
'<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">mailto:user@example.com</a>'),
|
'<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">mailto:user@example.com</a>',],
|
||||||
array('mailto:user@example.com?subject=test',
|
['mailto:user@example.com?subject=test',
|
||||||
'<a href="mailto:user@example.com?subject=test" title="mailto:user@example.com?subject=test" rel="nofollow external">mailto:user@example.com?subject=test</a>'),
|
'<a href="mailto:user@example.com?subject=test" title="mailto:user@example.com?subject=test" rel="nofollow external">mailto:user@example.com?subject=test</a>',],
|
||||||
array('xmpp:user@example.com',
|
['xmpp:user@example.com',
|
||||||
'<a href="xmpp:user@example.com" title="xmpp:user@example.com" rel="nofollow external">xmpp:user@example.com</a>'),
|
'<a href="xmpp:user@example.com" title="xmpp:user@example.com" rel="nofollow external">xmpp:user@example.com</a>',],
|
||||||
array('#example',
|
['#example',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example'))) . '" rel="tag">example</a></span>'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('example')]) . '" rel="tag">example</a></span>',],
|
||||||
array('#example.com',
|
['#example.com',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example.com'))) . '" rel="tag">example.com</a></span>'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('example.com')]) . '" rel="tag">example.com</a></span>',],
|
||||||
array('#.net',
|
['#.net',
|
||||||
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('.net'))) . '" rel="tag">.net</a></span>'),
|
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('.net')]) . '" rel="tag">.net</a></span>',],
|
||||||
array('http://example',
|
['http://example',
|
||||||
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example</a>'),
|
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example</a>',],
|
||||||
array('http://3xampl3',
|
['http://3xampl3',
|
||||||
'<a href="http://3xampl3/" title="http://3xampl3/" rel="nofollow external">http://3xampl3</a>'),
|
'<a href="http://3xampl3/" title="http://3xampl3/" rel="nofollow external">http://3xampl3</a>',],
|
||||||
array('http://example/',
|
['http://example/',
|
||||||
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example/</a>'),
|
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example/</a>',],
|
||||||
array('http://example/path',
|
['http://example/path',
|
||||||
'<a href="http://example/path" title="http://example/path" rel="nofollow external">http://example/path</a>'),
|
'<a href="http://example/path" title="http://example/path" rel="nofollow external">http://example/path</a>',],
|
||||||
array('http://example.com',
|
['http://example.com',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>',],
|
||||||
array('https://example.com',
|
['https://example.com',
|
||||||
'<a href="https://example.com/" title="https://example.com/" rel="nofollow external">https://example.com</a>'),
|
'<a href="https://example.com/" title="https://example.com/" rel="nofollow external">https://example.com</a>',],
|
||||||
array('ftp://example.com',
|
['ftp://example.com',
|
||||||
'<a href="ftp://example.com/" title="ftp://example.com/" rel="nofollow external">ftp://example.com</a>'),
|
'<a href="ftp://example.com/" title="ftp://example.com/" rel="nofollow external">ftp://example.com</a>',],
|
||||||
array('ftps://example.com',
|
['ftps://example.com',
|
||||||
'<a href="ftps://example.com/" title="ftps://example.com/" rel="nofollow external">ftps://example.com</a>'),
|
'<a href="ftps://example.com/" title="ftps://example.com/" rel="nofollow external">ftps://example.com</a>',],
|
||||||
array('http://user@example.com',
|
['http://user@example.com',
|
||||||
'<a href="http://@example.com/" title="http://@example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://user@example.com</a>'),
|
'<a href="http://@example.com/" title="http://@example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://user@example.com</a>',],
|
||||||
array('http://user:pass@example.com',
|
['http://user:pass@example.com',
|
||||||
'<a href="http://@example.com/" title="http://@example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://user:pass@example.com</a>'),
|
'<a href="http://@example.com/" title="http://@example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://user:pass@example.com</a>',],
|
||||||
array('http://example.com:8080',
|
['http://example.com:8080',
|
||||||
'<a href="http://example.com:8080/" title="http://example.com:8080/" rel="nofollow external">http://example.com:8080</a>'),
|
'<a href="http://example.com:8080/" title="http://example.com:8080/" rel="nofollow external">http://example.com:8080</a>',],
|
||||||
array('http://example.com:8080/test.php',
|
['http://example.com:8080/test.php',
|
||||||
'<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="nofollow external">http://example.com:8080/test.php</a>'),
|
'<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="nofollow external">http://example.com:8080/test.php</a>',],
|
||||||
array('http://www.example.com',
|
['http://www.example.com',
|
||||||
'<a href="http://www.example.com/" title="http://www.example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://www.example.com</a>'),
|
'<a href="http://www.example.com/" title="http://www.example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://www.example.com</a>',],
|
||||||
array('http://example.com/',
|
['http://example.com/',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>',],
|
||||||
array('http://example.com/path',
|
['http://example.com/path',
|
||||||
'<a href="http://example.com/path" title="http://example.com/path" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path</a>'),
|
'<a href="http://example.com/path" title="http://example.com/path" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path</a>',],
|
||||||
array('http://example.com/path.html',
|
['http://example.com/path.html',
|
||||||
'<a href="http://example.com/path.html" title="http://example.com/path.html" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.html</a>'),
|
'<a href="http://example.com/path.html" title="http://example.com/path.html" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.html</a>',],
|
||||||
array('http://example.com/path.html#fragment',
|
['http://example.com/path.html#fragment',
|
||||||
'<a href="http://example.com/path.html#fragment" title="http://example.com/path.html#fragment" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.html#fragment</a>'),
|
'<a href="http://example.com/path.html#fragment" title="http://example.com/path.html#fragment" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.html#fragment</a>',],
|
||||||
array('http://example.com/path.php?foo=bar&bar=foo',
|
['http://example.com/path.php?foo=bar&bar=foo',
|
||||||
'<a href="http://example.com/path.php?foo=bar&bar=foo" title="http://example.com/path.php?foo=bar&bar=foo" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.php?foo=bar&bar=foo</a>'),
|
'<a href="http://example.com/path.php?foo=bar&bar=foo" title="http://example.com/path.php?foo=bar&bar=foo" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.php?foo=bar&bar=foo</a>',],
|
||||||
array('http://example.com.',
|
['http://example.com.',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.',],
|
||||||
array('http://müllärör.de',
|
['http://müllärör.de',
|
||||||
'<a href="http://müllärör.de/" title="http://müllärör.de/" rel="nofollow external">http://müllärör.de</a>'),
|
'<a href="http://müllärör.de/" title="http://müllärör.de/" rel="nofollow external">http://müllärör.de</a>',],
|
||||||
array('http://ﺱﺲﺷ.com',
|
['http://ﺱﺲﺷ.com',
|
||||||
'<a href="http://ﺱﺲﺷ.com/" title="http://ﺱﺲﺷ.com/" rel="nofollow external">http://ﺱﺲﺷ.com</a>'),
|
'<a href="http://ﺱﺲﺷ.com/" title="http://ﺱﺲﺷ.com/" rel="nofollow external">http://ﺱﺲﺷ.com</a>',],
|
||||||
array('http://сделаткартинки.com',
|
['http://сделаткартинки.com',
|
||||||
'<a href="http://сделаткартинки.com/" title="http://сделаткартинки.com/" rel="nofollow external">http://сделаткартинки.com</a>'),
|
'<a href="http://сделаткартинки.com/" title="http://сделаткартинки.com/" rel="nofollow external">http://сделаткартинки.com</a>',],
|
||||||
array('http://tūdaliņ.lv',
|
['http://tūdaliņ.lv',
|
||||||
'<a href="http://tūdaliņ.lv/" title="http://tūdaliņ.lv/" rel="nofollow external">http://tūdaliņ.lv</a>'),
|
'<a href="http://tūdaliņ.lv/" title="http://tūdaliņ.lv/" rel="nofollow external">http://tūdaliņ.lv</a>',],
|
||||||
array('http://brændendekærlighed.com',
|
['http://brændendekærlighed.com',
|
||||||
'<a href="http://brændendekærlighed.com/" title="http://brændendekærlighed.com/" rel="nofollow external">http://brændendekærlighed.com</a>'),
|
'<a href="http://brændendekærlighed.com/" title="http://brændendekærlighed.com/" rel="nofollow external">http://brændendekærlighed.com</a>',],
|
||||||
array('http://あーるいん.com',
|
['http://あーるいん.com',
|
||||||
'<a href="http://あーるいん.com/" title="http://あーるいん.com/" rel="nofollow external">http://あーるいん.com</a>'),
|
'<a href="http://あーるいん.com/" title="http://あーるいん.com/" rel="nofollow external">http://あーるいん.com</a>',],
|
||||||
array('http://예비교사.com',
|
['http://예비교사.com',
|
||||||
'<a href="http://예비교사.com/" title="http://예비교사.com/" rel="nofollow external">http://예비교사.com</a>'),
|
'<a href="http://예비교사.com/" title="http://예비교사.com/" rel="nofollow external">http://예비교사.com</a>',],
|
||||||
array('http://example.com.',
|
['http://example.com.',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>.',],
|
||||||
array('http://example.com?',
|
['http://example.com?',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>?'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>?',],
|
||||||
array('http://example.com!',
|
['http://example.com!',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>!'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>!',],
|
||||||
array('http://example.com,',
|
['http://example.com,',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>,'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>,',],
|
||||||
array('http://example.com;',
|
['http://example.com;',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>;'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>;',],
|
||||||
array('http://example.com:',
|
['http://example.com:',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>:'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>:',],
|
||||||
array('\'http://example.com\'',
|
['\'http://example.com\'',
|
||||||
'\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>\''),
|
'\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>\'',],
|
||||||
array('"http://example.com"',
|
['"http://example.com"',
|
||||||
'"<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>"'),
|
'"<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>"',],
|
||||||
array('"http://example.com/"',
|
['"http://example.com/"',
|
||||||
'"<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>"'),
|
'"<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>"',],
|
||||||
array('http://example.com',
|
['http://example.com',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>'),
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>',],
|
||||||
array('(http://example.com)',
|
['(http://example.com)',
|
||||||
'(<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>)'),
|
'(<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>)',],
|
||||||
array('[http://example.com]',
|
['[http://example.com]',
|
||||||
'[<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>]'),
|
'[<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>]',],
|
||||||
array('<http://example.com>',
|
['<http://example.com>',
|
||||||
'<<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>>'),
|
'<<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>>',],
|
||||||
array('http://example.com/path/(foo)/bar',
|
['http://example.com/path/(foo)/bar',
|
||||||
'<a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo)/bar'),
|
'<a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo)/bar',],
|
||||||
array('http://example.com/path/[foo]/bar',
|
['http://example.com/path/[foo]/bar',
|
||||||
'<a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>[foo]/bar'),
|
'<a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>[foo]/bar',],
|
||||||
array('http://example.com/path/foo/(bar)',
|
['http://example.com/path/foo/(bar)',
|
||||||
'<a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar)'),
|
'<a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar)',],
|
||||||
//Not a valid url - urls cannot contain unencoded square brackets
|
//Not a valid url - urls cannot contain unencoded square brackets
|
||||||
array('http://example.com/path/foo/[bar]',
|
['http://example.com/path/foo/[bar]',
|
||||||
'<a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>[bar]'),
|
'<a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>[bar]',],
|
||||||
array('Hey, check out my cool site http://example.com okay?',
|
['Hey, check out my cool site http://example.com okay?',
|
||||||
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a> okay?'),
|
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a> okay?',],
|
||||||
array('What about parens (e.g. http://example.com/path/foo/(bar))?',
|
['What about parens (e.g. http://example.com/path/foo/(bar))?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar))?'),
|
'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar))?',],
|
||||||
array('What about parens (e.g. http://example.com/path/foo/(bar)?',
|
['What about parens (e.g. http://example.com/path/foo/(bar)?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar)?'),
|
'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar)?',],
|
||||||
array('What about parens (e.g. http://example.com/path/foo/(bar).)?',
|
['What about parens (e.g. http://example.com/path/foo/(bar).)?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar).)?'),
|
'What about parens (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar).)?',],
|
||||||
//Not a valid url - urls cannot contain unencoded commas
|
//Not a valid url - urls cannot contain unencoded commas
|
||||||
array('What about parens (e.g. http://example.com/path/(foo,bar)?',
|
['What about parens (e.g. http://example.com/path/(foo,bar)?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo,bar)?'),
|
'What about parens (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo,bar)?',],
|
||||||
array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
|
['Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
|
||||||
'Unbalanced too (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>((((foo)/bar)?'),
|
'Unbalanced too (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>((((foo)/bar)?',],
|
||||||
array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
|
['Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
|
||||||
'Unbalanced too (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo))))/bar)?'),
|
'Unbalanced too (e.g. <a href="http://example.com/path/" title="http://example.com/path/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/</a>(foo))))/bar)?',],
|
||||||
array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',
|
['Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',
|
||||||
'Unbalanced too (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>((((bar)?'),
|
'Unbalanced too (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>((((bar)?',],
|
||||||
array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?',
|
['Unbalanced too (e.g. http://example.com/path/foo/(bar))))?',
|
||||||
'Unbalanced too (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar))))?'),
|
'Unbalanced too (e.g. <a href="http://example.com/path/foo/" title="http://example.com/path/foo/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path/foo/</a>(bar))))?',],
|
||||||
array('file.ext',
|
['file.ext',
|
||||||
'file.ext'),
|
'file.ext',],
|
||||||
array('file.html',
|
['file.html',
|
||||||
'file.html'),
|
'file.html',],
|
||||||
array('file.php',
|
['file.php',
|
||||||
'file.php'),
|
'file.php',],
|
||||||
|
|
||||||
// scheme-less HTTP URLs with @ in the path: http://status.net/open-source/issues/2248
|
// scheme-less HTTP URLs with @ in the path: http://status.net/open-source/issues/2248
|
||||||
array('http://flickr.com/photos/34807140@N05/3838905434',
|
['http://flickr.com/photos/34807140@N05/3838905434',
|
||||||
'<a href="http://www.flickr.com/photos/34807140@N05/3838905434" title="http://www.flickr.com/photos/34807140@N05/3838905434" rel="nofollow external noreferrer" class="attachment thumbnail" id="attachment-XXX">http://flickr.com/photos/34807140@N05/3838905434</a>'),
|
'<a href="http://www.flickr.com/photos/34807140@N05/3838905434" title="http://www.flickr.com/photos/34807140@N05/3838905434" rel="nofollow external noreferrer" class="attachment thumbnail" id="attachment-XXX">http://flickr.com/photos/34807140@N05/3838905434</a>',],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function linkifyProvider()
|
public static function linkifyProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
//bare ip addresses are no longer supported
|
//bare ip addresses are no longer supported
|
||||||
array('127.0.0.1',
|
['127.0.0.1',
|
||||||
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1</a>',
|
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1:99',
|
['127.0.0.1:99',
|
||||||
'<a href="http://127.0.0.1:99/" title="http://127.0.0.1:99/" rel="nofollow external">127.0.0.1:99</a>',
|
'<a href="http://127.0.0.1:99/" title="http://127.0.0.1:99/" rel="nofollow external">127.0.0.1:99</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/Name:test.php',
|
['127.0.0.1/Name:test.php',
|
||||||
'<a href="http://127.0.0.1/Name:test.php" title="http://127.0.0.1/Name:test.php" rel="nofollow external">127.0.0.1/Name:test.php</a>',
|
'<a href="http://127.0.0.1/Name:test.php" title="http://127.0.0.1/Name:test.php" rel="nofollow external">127.0.0.1/Name:test.php</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/~test',
|
['127.0.0.1/~test',
|
||||||
'<a href="http://127.0.0.1/~test" title="http://127.0.0.1/~test" rel="nofollow external">127.0.0.1/~test</a>',
|
'<a href="http://127.0.0.1/~test" title="http://127.0.0.1/~test" rel="nofollow external">127.0.0.1/~test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/+test',
|
['127.0.0.1/+test',
|
||||||
'<a href="http://127.0.0.1/+test" title="http://127.0.0.1/+test" rel="nofollow external">127.0.0.1/+test</a>',
|
'<a href="http://127.0.0.1/+test" title="http://127.0.0.1/+test" rel="nofollow external">127.0.0.1/+test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/$test',
|
['127.0.0.1/$test',
|
||||||
'<a href="http://127.0.0.1/$test" title="http://127.0.0.1/$test" rel="nofollow external">127.0.0.1/$test</a>',
|
'<a href="http://127.0.0.1/$test" title="http://127.0.0.1/$test" rel="nofollow external">127.0.0.1/$test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/\'test',
|
['127.0.0.1/\'test',
|
||||||
'<a href="http://127.0.0.1/\'test" title="http://127.0.0.1/\'test" rel="nofollow external">127.0.0.1/\'test</a>',
|
'<a href="http://127.0.0.1/\'test" title="http://127.0.0.1/\'test" rel="nofollow external">127.0.0.1/\'test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/"test',
|
['127.0.0.1/"test',
|
||||||
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1/</a>"test',
|
'<a href="http://127.0.0.1/" title="http://127.0.0.1/" rel="nofollow external">127.0.0.1/</a>"test',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/test"test',
|
['127.0.0.1/test"test',
|
||||||
'<a href="http://127.0.0.1/test" title="http://127.0.0.1/test" rel="nofollow external">127.0.0.1/test</a>"test',
|
'<a href="http://127.0.0.1/test" title="http://127.0.0.1/test" rel="nofollow external">127.0.0.1/test</a>"test',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/-test',
|
['127.0.0.1/-test',
|
||||||
'<a href="http://127.0.0.1/-test" title="http://127.0.0.1/-test" rel="nofollow external">127.0.0.1/-test</a>',
|
'<a href="http://127.0.0.1/-test" title="http://127.0.0.1/-test" rel="nofollow external">127.0.0.1/-test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/_test',
|
['127.0.0.1/_test',
|
||||||
'<a href="http://127.0.0.1/_test" title="http://127.0.0.1/_test" rel="nofollow external">127.0.0.1/_test</a>',
|
'<a href="http://127.0.0.1/_test" title="http://127.0.0.1/_test" rel="nofollow external">127.0.0.1/_test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/!test',
|
['127.0.0.1/!test',
|
||||||
'<a href="http://127.0.0.1/!test" title="http://127.0.0.1/!test" rel="nofollow external">127.0.0.1/!test</a>',
|
'<a href="http://127.0.0.1/!test" title="http://127.0.0.1/!test" rel="nofollow external">127.0.0.1/!test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/*test',
|
['127.0.0.1/*test',
|
||||||
'<a href="http://127.0.0.1/*test" title="http://127.0.0.1/*test" rel="nofollow external">127.0.0.1/*test</a>',
|
'<a href="http://127.0.0.1/*test" title="http://127.0.0.1/*test" rel="nofollow external">127.0.0.1/*test</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('127.0.0.1/test%20stuff',
|
['127.0.0.1/test%20stuff',
|
||||||
'<a href="http://127.0.0.1/test%20stuff" title="http://127.0.0.1/test%20stuff" rel="nofollow external">127.0.0.1/test%20stuff</a>',
|
'<a href="http://127.0.0.1/test%20stuff" title="http://127.0.0.1/test%20stuff" rel="nofollow external">127.0.0.1/test%20stuff</a>',
|
||||||
'bare_ipv4'),
|
'bare_ipv4',],
|
||||||
array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
|
['2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
|
||||||
'<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php</a>',
|
'<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php</a>',
|
||||||
'bare_ipv6'),
|
'bare_ipv6',],
|
||||||
array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
|
['[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
|
||||||
'<a href="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" title="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" rel="nofollow external">[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php</a>',
|
'<a href="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" title="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" rel="nofollow external">[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php</a>',
|
||||||
'bare_ipv6'),
|
'bare_ipv6',],
|
||||||
array('2001:4978:1b5:0:21d:e0ff:fe66:59ab',
|
['2001:4978:1b5:0:21d:e0ff:fe66:59ab',
|
||||||
'<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab</a>',
|
'<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" title="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" rel="nofollow external">2001:4978:1b5:0:21d:e0ff:fe66:59ab</a>',
|
||||||
'bare_ipv6'),
|
'bare_ipv6',],
|
||||||
array('example.com',
|
['example.com',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('flickr.com/photos/34807140@N05/3838905434',
|
['flickr.com/photos/34807140@N05/3838905434',
|
||||||
'<a href="http://flickr.com/photos/34807140@N05/3838905434" title="http://flickr.com/photos/34807140@N05/3838905434" class="attachment thumbnail" id="attachment-XXX" rel="nofollow external">flickr.com/photos/34807140@N05/3838905434</a>',
|
'<a href="http://flickr.com/photos/34807140@N05/3838905434" title="http://flickr.com/photos/34807140@N05/3838905434" class="attachment thumbnail" id="attachment-XXX" rel="nofollow external">flickr.com/photos/34807140@N05/3838905434</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('What about parens (e.g. example.com/path/foo/(bar))?',
|
['What about parens (e.g. example.com/path/foo/(bar))?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>)?',
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>)?',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('What about parens (e.g. example.com/path/foo/(bar)?',
|
['What about parens (e.g. example.com/path/foo/(bar)?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>?',
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>?',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('What about parens (e.g. example.com/path/foo/(bar).)?',
|
['What about parens (e.g. example.com/path/foo/(bar).)?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>.?',
|
'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" title="http://example.com/path/foo/(bar)" rel="nofollow external">example.com/path/foo/(bar)</a>.?',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('What about parens (e.g. example.com/path/(foo,bar)?',
|
['What about parens (e.g. example.com/path/(foo,bar)?',
|
||||||
'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" title="http://example.com/path/(foo,bar)" rel="nofollow external">example.com/path/(foo,bar)</a>?',
|
'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" title="http://example.com/path/(foo,bar)" rel="nofollow external">example.com/path/(foo,bar)</a>?',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com',
|
['example.com',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.org',
|
['example.org',
|
||||||
'<a href="http://example.org/" title="http://example.org/" rel="nofollow external">example.org</a>',
|
'<a href="http://example.org/" title="http://example.org/" rel="nofollow external">example.org</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.co.uk',
|
['example.co.uk',
|
||||||
'<a href="http://example.co.uk/" title="http://example.co.uk/" rel="nofollow external">example.co.uk</a>',
|
'<a href="http://example.co.uk/" title="http://example.co.uk/" rel="nofollow external">example.co.uk</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('www.example.co.uk',
|
['www.example.co.uk',
|
||||||
'<a href="http://www.example.co.uk/" title="http://www.example.co.uk/" rel="nofollow external">www.example.co.uk</a>',
|
'<a href="http://www.example.co.uk/" title="http://www.example.co.uk/" rel="nofollow external">www.example.co.uk</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('farm1.images.example.co.uk',
|
['farm1.images.example.co.uk',
|
||||||
'<a href="http://farm1.images.example.co.uk/" title="http://farm1.images.example.co.uk/" rel="nofollow external">farm1.images.example.co.uk</a>',
|
'<a href="http://farm1.images.example.co.uk/" title="http://farm1.images.example.co.uk/" rel="nofollow external">farm1.images.example.co.uk</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.museum',
|
['example.museum',
|
||||||
'<a href="http://example.museum/" title="http://example.museum/" rel="nofollow external">example.museum</a>',
|
'<a href="http://example.museum/" title="http://example.museum/" rel="nofollow external">example.museum</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.travel',
|
['example.travel',
|
||||||
'<a href="http://example.travel/" title="http://example.travel/" rel="nofollow external">example.travel</a>',
|
'<a href="http://example.travel/" title="http://example.travel/" rel="nofollow external">example.travel</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com.',
|
['example.com.',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com?',
|
['example.com?',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>?',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>?',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com!',
|
['example.com!',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>!',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>!',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com,',
|
['example.com,',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>,',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>,',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com;',
|
['example.com;',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>;',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>;',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com:',
|
['example.com:',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>:',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>:',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('\'example.com\'',
|
['\'example.com\'',
|
||||||
'\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>\'',
|
'\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>\'',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('"example.com"',
|
['"example.com"',
|
||||||
'"<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>"',
|
'"<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>"',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com',
|
['example.com',
|
||||||
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
|
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('(example.com)',
|
['(example.com)',
|
||||||
'(<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>)',
|
'(<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>)',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('[example.com]',
|
['[example.com]',
|
||||||
'[<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>]',
|
'[<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>]',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('<example.com>',
|
['<example.com>',
|
||||||
'<<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>>',
|
'<<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('Hey, check out my cool site example.com okay?',
|
['Hey, check out my cool site example.com okay?',
|
||||||
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a> okay?',
|
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a> okay?',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('Hey, check out my cool site example.com.I made it.',
|
['Hey, check out my cool site example.com.I made it.',
|
||||||
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.I made it.',
|
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.I made it.',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('Hey, check out my cool site example.com.Funny thing...',
|
['Hey, check out my cool site example.com.Funny thing...',
|
||||||
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.Funny thing...',
|
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.Funny thing...',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('Hey, check out my cool site example.com.You will love it.',
|
['Hey, check out my cool site example.com.You will love it.',
|
||||||
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.You will love it.',
|
'Hey, check out my cool site <a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.You will love it.',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('example.com:8080/test.php',
|
['example.com:8080/test.php',
|
||||||
'<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="nofollow external">example.com:8080/test.php</a>',
|
'<a href="http://example.com:8080/test.php" title="http://example.com:8080/test.php" rel="nofollow external">example.com:8080/test.php</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('user_name+other@example.com',
|
['user_name+other@example.com',
|
||||||
'<a href="mailto:user_name+other@example.com" title="mailto:user_name+other@example.com" rel="nofollow external">user_name+other@example.com</a>',
|
'<a href="mailto:user_name+other@example.com" title="mailto:user_name+other@example.com" rel="nofollow external">user_name+other@example.com</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
array('user@example.com',
|
['user@example.com',
|
||||||
'<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">user@example.com</a>',
|
'<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">user@example.com</a>',
|
||||||
'bare_domains'),
|
'bare_domains',],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,23 +39,24 @@ final class UUIDTest extends TestCase
|
|||||||
public function testGenerate()
|
public function testGenerate()
|
||||||
{
|
{
|
||||||
$result = UUID::gen();
|
$result = UUID::gen();
|
||||||
$this->assertRegExp('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
|
static::assertRegExp(
|
||||||
$result);
|
'/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
|
||||||
|
$result
|
||||||
|
);
|
||||||
// Check version number
|
// Check version number
|
||||||
$this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
|
static::assertSame(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
|
||||||
$this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
|
static::assertSame(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnique()
|
public function testUnique()
|
||||||
{
|
{
|
||||||
$reps = 100;
|
$reps = 100;
|
||||||
$ids = array();
|
$ids = [];
|
||||||
|
|
||||||
for ($i = 0; $i < $reps; $i++) {
|
for ($i = 0; $i < $reps; ++$i) {
|
||||||
$ids[] = UUID::gen();
|
$ids[] = UUID::gen();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals(count($ids), count(array_unique($ids)), "UUIDs must be unique");
|
static::assertSame(count($ids), count(array_unique($ids)), 'UUIDs must be unique');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,71 +36,69 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
require_once INSTALLDIR . '/lib/util/common.php';
|
require_once INSTALLDIR . '/lib/util/common.php';
|
||||||
|
|
||||||
final class UserFeedParseTests extends TestCase
|
final class UserFeedParseTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testFeed1()
|
public function testFeed1()
|
||||||
{
|
{
|
||||||
global $_testfeed1;
|
global $_testfeed1;
|
||||||
$dom = new DOMDocument();
|
$dom = new DOMDocument();
|
||||||
$dom->loadXML($_testfeed1);
|
$dom->loadXML($_testfeed1);
|
||||||
$this->assertFalse(empty($dom));
|
static::assertFalse(empty($dom));
|
||||||
|
|
||||||
$entries = $dom->getElementsByTagName('entry');
|
$entries = $dom->getElementsByTagName('entry');
|
||||||
|
|
||||||
$entry1 = $entries->item(0);
|
$entry1 = $entries->item(0);
|
||||||
$this->assertFalse(empty($entry1));
|
static::assertFalse(empty($entry1));
|
||||||
|
|
||||||
$feedEl = $dom->getElementsByTagName('feed')->item(0);
|
$feedEl = $dom->getElementsByTagName('feed')->item(0);
|
||||||
$this->assertFalse(empty($feedEl));
|
static::assertFalse(empty($feedEl));
|
||||||
|
|
||||||
// Test actor (from activity:subject)
|
// Test actor (from activity:subject)
|
||||||
|
|
||||||
$act1 = new Activity($entry1, $feedEl);
|
$act1 = new Activity($entry1, $feedEl);
|
||||||
$this->assertFalse(empty($act1));
|
static::assertFalse(empty($act1));
|
||||||
$this->assertFalse(empty($act1->actor));
|
static::assertFalse(empty($act1->actor));
|
||||||
$this->assertEquals($act1->actor->type, ActivityObject::PERSON);
|
static::assertSame($act1->actor->type, ActivityObject::PERSON);
|
||||||
$this->assertEquals($act1->actor->title, 'Zach Copley');
|
static::assertSame($act1->actor->title, 'Zach Copley');
|
||||||
$this->assertEquals($act1->actor->id, 'http://localhost/statusnet/user/1');
|
static::assertSame($act1->actor->id, 'http://localhost/statusnet/user/1');
|
||||||
$this->assertEquals($act1->actor->link, 'http://localhost/statusnet/zach');
|
static::assertSame($act1->actor->link, 'http://localhost/statusnet/zach');
|
||||||
|
|
||||||
$avatars = $act1->actor->avatarLinks;
|
$avatars = $act1->actor->avatarLinks;
|
||||||
|
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$avatars[0]->url,
|
$avatars[0]->url,
|
||||||
'http://localhost/statusnet/theme/default/default-avatar-profile.png'
|
'http://localhost/statusnet/theme/default/default-avatar-profile.png'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$avatars[1]->url,
|
$avatars[1]->url,
|
||||||
'http://localhost/statusnet/theme/default/default-avatar-stream.png'
|
'http://localhost/statusnet/theme/default/default-avatar-stream.png'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
static::assertSame(
|
||||||
$avatars[2]->url,
|
$avatars[2]->url,
|
||||||
'http://localhost/statusnet/theme/default/default-avatar-mini.png'
|
'http://localhost/statusnet/theme/default/default-avatar-mini.png'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($act1->actor->displayName, 'Zach Copley');
|
static::assertSame($act1->actor->displayName, 'Zach Copley');
|
||||||
|
|
||||||
$poco = $act1->actor->poco;
|
$poco = $act1->actor->poco;
|
||||||
$this->assertEquals($poco->preferredUsername, 'zach');
|
static::assertSame($poco->preferredUsername, 'zach');
|
||||||
$this->assertEquals($poco->address->formatted, 'El Cerrito, CA');
|
static::assertSame($poco->address->formatted, 'El Cerrito, CA');
|
||||||
$this->assertEquals($poco->urls[0]->type, 'homepage');
|
static::assertSame($poco->urls[0]->type, 'homepage');
|
||||||
$this->assertEquals($poco->urls[0]->value, 'http://zach.copley.name');
|
static::assertSame($poco->urls[0]->value, 'http://zach.copley.name');
|
||||||
$this->assertEquals($poco->urls[0]->primary, true);
|
static::assertSame($poco->urls[0]->primary, true);
|
||||||
$this->assertEquals($poco->note, 'Zach Hack Attack');
|
static::assertSame($poco->note, 'Zach Hack Attack');
|
||||||
|
|
||||||
// test the post
|
// test the post
|
||||||
|
|
||||||
//var_export($act1);
|
//var_export($act1);
|
||||||
$this->assertEquals($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
|
static::assertSame($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
|
||||||
$this->assertEquals($act1->objects[0]->title, 'And now for something completely insane...');
|
static::assertSame($act1->objects[0]->title, 'And now for something completely insane...');
|
||||||
|
|
||||||
$this->assertEquals($act1->objects[0]->content, 'And now for something completely insane...');
|
|
||||||
$this->assertEquals($act1->objects[0]->id, 'http://localhost/statusnet/notice/3');
|
|
||||||
|
|
||||||
|
static::assertSame($act1->objects[0]->content, 'And now for something completely insane...');
|
||||||
|
static::assertSame($act1->objects[0]->id, 'http://localhost/statusnet/notice/3');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$_testfeed1 = <<<TESTFEED1
|
$_testfeed1 = <<<TESTFEED1
|
||||||
|
@ -37,9 +37,9 @@ require_once INSTALLDIR . '/lib/util/common.php';
|
|||||||
|
|
||||||
final class UserRightsTest extends TestCase
|
final class UserRightsTest extends TestCase
|
||||||
{
|
{
|
||||||
protected $user = null;
|
protected $user;
|
||||||
|
|
||||||
function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$user = User::getKV('nickname', 'userrightstestuser');
|
$user = User::getKV('nickname', 'userrightstestuser');
|
||||||
if ($user) {
|
if ($user) {
|
||||||
@ -48,13 +48,13 @@ final class UserRightsTest extends TestCase
|
|||||||
$user->delete();
|
$user->delete();
|
||||||
$profile->delete();
|
$profile->delete();
|
||||||
}
|
}
|
||||||
$this->user = User::register(array('nickname' => 'userrightstestuser'));
|
$this->user = User::register(['nickname' => 'userrightstestuser']);
|
||||||
if (!$this->user) {
|
if (!$this->user) {
|
||||||
throw new Exception("Couldn't register userrightstestuser");
|
throw new Exception("Couldn't register userrightstestuser");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
if ($this->user) {
|
if ($this->user) {
|
||||||
$profile = $this->user->getProfile();
|
$profile = $this->user->getProfile();
|
||||||
@ -63,35 +63,35 @@ final class UserRightsTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInvalidRole()
|
public function testInvalidRole()
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->user->hasRole('invalidrole'));
|
static::assertFalse($this->user->hasRole('invalidrole'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function standardRoles()
|
public function standardRoles()
|
||||||
{
|
{
|
||||||
return array(array('admin'),
|
return [['admin'],
|
||||||
array('moderator'));
|
['moderator'],];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider standardRoles
|
* @dataProvider standardRoles
|
||||||
|
*
|
||||||
* @param $role
|
* @param $role
|
||||||
*/
|
*/
|
||||||
|
public function testUngrantedRole($role)
|
||||||
function testUngrantedRole($role)
|
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->user->hasRole($role));
|
static::assertFalse($this->user->hasRole($role));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider standardRoles
|
* @dataProvider standardRoles
|
||||||
|
*
|
||||||
* @param $role
|
* @param $role
|
||||||
*/
|
*/
|
||||||
|
public function testGrantedRole($role)
|
||||||
function testGrantedRole($role)
|
|
||||||
{
|
{
|
||||||
$this->user->grantRole($role);
|
$this->user->grantRole($role);
|
||||||
$this->assertTrue($this->user->hasRole($role));
|
static::assertTrue($this->user->hasRole($role));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ if (!defined('STATUSNET')) { // Compatibility
|
|||||||
define('STATUSNET', true);
|
define('STATUSNET', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
use GNUsocial;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PluginList;
|
use PluginList;
|
||||||
use XmppPlugin;
|
use XmppPlugin;
|
||||||
@ -39,15 +38,16 @@ require_once INSTALLDIR . '/plugins/Xmpp/XmppPlugin.php';
|
|||||||
|
|
||||||
final class XmppValidateTest extends TestCase
|
final class XmppValidateTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
if (!PluginList::isPluginActive('Xmpp')) {
|
if (!PluginList::isPluginActive('Xmpp')) {
|
||||||
$this->markTestSkipped('XmppPlugin is not enabled.');
|
static::markTestSkipped('XmppPlugin is not enabled.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider validationCases
|
* @dataProvider validationCases
|
||||||
|
*
|
||||||
* @param $jid
|
* @param $jid
|
||||||
* @param $validFull
|
* @param $validFull
|
||||||
* @param $validBase
|
* @param $validBase
|
||||||
@ -55,24 +55,26 @@ final class XmppValidateTest extends TestCase
|
|||||||
public function testValidate($jid, $validFull, $validBase)
|
public function testValidate($jid, $validFull, $validBase)
|
||||||
{
|
{
|
||||||
$xmpp = new TestXmppPlugin();
|
$xmpp = new TestXmppPlugin();
|
||||||
$this->assertEquals($validFull || $validBase, $xmpp->validate($jid));
|
static::assertSame($validFull || $validBase, $xmpp->validate($jid));
|
||||||
$this->assertEquals($validFull, $xmpp->validateFullJid($jid), "validating as full or base JID");
|
static::assertSame($validFull, $xmpp->validateFullJid($jid), 'validating as full or base JID');
|
||||||
$this->assertEquals($validBase, $xmpp->validateBaseJid($jid), "validating as base JID only");
|
static::assertSame($validBase, $xmpp->validateBaseJid($jid), 'validating as base JID only');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider normalizationCases
|
* @dataProvider normalizationCases
|
||||||
|
*
|
||||||
* @param $jid
|
* @param $jid
|
||||||
* @param $expected
|
* @param $expected
|
||||||
*/
|
*/
|
||||||
public function testNormalize($jid, $expected)
|
public function testNormalize($jid, $expected)
|
||||||
{
|
{
|
||||||
$xmpp = new XmppPlugin();
|
$xmpp = new XmppPlugin();
|
||||||
$this->assertEquals($expected, $xmpp->normalize($jid));
|
static::assertSame($expected, $xmpp->normalize($jid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider domainCheckCases()
|
* @dataProvider domainCheckCases()
|
||||||
|
*
|
||||||
* @param $domain
|
* @param $domain
|
||||||
* @param $expected
|
* @param $expected
|
||||||
* @param $note
|
* @param $note
|
||||||
@ -80,69 +82,69 @@ final class XmppValidateTest extends TestCase
|
|||||||
public function testDomainCheck($domain, $expected, $note)
|
public function testDomainCheck($domain, $expected, $note)
|
||||||
{
|
{
|
||||||
$xmpp = new TestXmppPlugin();
|
$xmpp = new TestXmppPlugin();
|
||||||
$this->assertEquals($expected, $xmpp->checkDomain($domain), $note);
|
static::assertSame($expected, $xmpp->checkDomain($domain), $note);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function validationCases()
|
public static function validationCases()
|
||||||
{
|
{
|
||||||
$long1023 = "long1023" . str_repeat('x', 1023 - 8);
|
$long1023 = 'long1023' . str_repeat('x', 1023 - 8);
|
||||||
$long1024 = "long1024" . str_repeat('x', 1024 - 8);
|
$long1024 = 'long1024' . str_repeat('x', 1024 - 8);
|
||||||
return array(
|
return [
|
||||||
// Our own test cases for standard things & those mentioned in bug reports
|
// Our own test cases for standard things & those mentioned in bug reports
|
||||||
// (jid, valid_full, valid_base)
|
// (jid, valid_full, valid_base)
|
||||||
array('user@example.com', true, true),
|
['user@example.com', true, true],
|
||||||
array('user@example.com/resource', true, false),
|
['user@example.com/resource', true, false],
|
||||||
array('user with spaces@example.com', false, false), // not kosher
|
['user with spaces@example.com', false, false], // not kosher
|
||||||
|
|
||||||
array('user.@example.com', true, true), // "common in intranets"
|
['user.@example.com', true, true], // "common in intranets"
|
||||||
array('example.com', true, true),
|
['example.com', true, true],
|
||||||
array('example.com/resource', true, false),
|
['example.com/resource', true, false],
|
||||||
array('jabchat', true, true),
|
['jabchat', true, true],
|
||||||
|
|
||||||
array("$long1023@$long1023/$long1023", true, false), // max 1023 "bytes" per portion per spec. Do they really mean bytes though?
|
["{$long1023}@{$long1023}/{$long1023}", true, false], // max 1023 "bytes" per portion per spec. Do they really mean bytes though?
|
||||||
array("$long1024@$long1023/$long1023", false, false),
|
["{$long1024}@{$long1023}/{$long1023}", false, false],
|
||||||
array("$long1023@$long1024/$long1023", false, false),
|
["{$long1023}@{$long1024}/{$long1023}", false, false],
|
||||||
array("$long1023@$long1023/$long1024", false, false),
|
["{$long1023}@{$long1023}/{$long1024}", false, false],
|
||||||
|
|
||||||
// Borrowed from test_jabber_jutil.c in libpurple
|
// Borrowed from test_jabber_jutil.c in libpurple
|
||||||
array("gmail.com", true, true),
|
['gmail.com', true, true],
|
||||||
array("gmail.com/Test", true, false),
|
['gmail.com/Test', true, false],
|
||||||
array("gmail.com/Test@", true, false),
|
['gmail.com/Test@', true, false],
|
||||||
array("gmail.com/@", true, false),
|
['gmail.com/@', true, false],
|
||||||
array("gmail.com/Test@alkjaweflkj", true, false),
|
['gmail.com/Test@alkjaweflkj', true, false],
|
||||||
array("mark.doliner@gmail.com", true, true),
|
['mark.doliner@gmail.com', true, true],
|
||||||
array("mark.doliner@gmail.com/Test12345", true, false),
|
['mark.doliner@gmail.com/Test12345', true, false],
|
||||||
array("mark.doliner@gmail.com/Test@12345", true, false),
|
['mark.doliner@gmail.com/Test@12345', true, false],
|
||||||
array("mark.doliner@gmail.com/Te/st@12@//345", true, false),
|
['mark.doliner@gmail.com/Te/st@12@//345', true, false],
|
||||||
array("わいど@conference.jabber.org", true, true),
|
['わいど@conference.jabber.org', true, true],
|
||||||
array("まりるーむ@conference.jabber.org", true, true),
|
['まりるーむ@conference.jabber.org', true, true],
|
||||||
array("mark.doliner@gmail.com/まりるーむ", true, false),
|
['mark.doliner@gmail.com/まりるーむ', true, false],
|
||||||
array("mark.doliner@gmail/stuff.org", true, false),
|
['mark.doliner@gmail/stuff.org', true, false],
|
||||||
array("stuart@nödåtXäYZ.se", true, true),
|
['stuart@nödåtXäYZ.se', true, true],
|
||||||
array("stuart@nödåtXäYZ.se/まりるーむ", true, false),
|
['stuart@nödåtXäYZ.se/まりるーむ', true, false],
|
||||||
array("mark.doliner@わいど.org", true, true),
|
['mark.doliner@わいど.org', true, true],
|
||||||
array("nick@まつ.おおかみ.net", true, true),
|
['nick@まつ.おおかみ.net', true, true],
|
||||||
array("paul@10.0.42.230/s", true, false),
|
['paul@10.0.42.230/s', true, false],
|
||||||
array("paul@[::1]", true, true), /* IPv6 */
|
['paul@[::1]', true, true], // IPv6
|
||||||
array("paul@[2001:470:1f05:d58::2]", true, true),
|
['paul@[2001:470:1f05:d58::2]', true, true],
|
||||||
array("paul@[2001:470:1f05:d58::2]/foo", true, false),
|
['paul@[2001:470:1f05:d58::2]/foo', true, false],
|
||||||
array("pa=ul@10.0.42.230", true, true),
|
['pa=ul@10.0.42.230', true, true],
|
||||||
array("pa,ul@10.0.42.230", true, true),
|
['pa,ul@10.0.42.230', true, true],
|
||||||
|
|
||||||
array("@gmail.com", false, false),
|
['@gmail.com', false, false],
|
||||||
array("@@gmail.com", false, false),
|
['@@gmail.com', false, false],
|
||||||
array("mark.doliner@@gmail.com/Test12345", false, false),
|
['mark.doliner@@gmail.com/Test12345', false, false],
|
||||||
array("mark@doliner@gmail.com/Test12345", false, false),
|
['mark@doliner@gmail.com/Test12345', false, false],
|
||||||
array("@gmail.com/Test@12345", false, false),
|
['@gmail.com/Test@12345', false, false],
|
||||||
array("/Test@12345", false, false),
|
['/Test@12345', false, false],
|
||||||
array("mark.doliner@", false, false),
|
['mark.doliner@', false, false],
|
||||||
array("mark.doliner/", false, false),
|
['mark.doliner/', false, false],
|
||||||
array("mark.doliner@gmail_stuff.org", false, false),
|
['mark.doliner@gmail_stuff.org', false, false],
|
||||||
array("mark.doliner@gmail[stuff.org", false, false),
|
['mark.doliner@gmail[stuff.org', false, false],
|
||||||
array("mark.doliner@gmail\\stuff.org", false, false),
|
['mark.doliner@gmail\\stuff.org', false, false],
|
||||||
array("paul@[::1]124", false, false),
|
['paul@[::1]124', false, false],
|
||||||
array("paul@2[::1]124/as", false, false),
|
['paul@2[::1]124/as', false, false],
|
||||||
array("paul@まつ.おおかみ/\x01", false, false),
|
["paul@まつ.おおかみ/\x01", false, false],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RFC 3454 Section 6 reads, in part,
|
* RFC 3454 Section 6 reads, in part,
|
||||||
@ -153,34 +155,32 @@ final class XmppValidateTest extends TestCase
|
|||||||
// Leaving this one commented out for the moment
|
// Leaving this one commented out for the moment
|
||||||
// as it shouldn't hurt anything for our purposes.
|
// as it shouldn't hurt anything for our purposes.
|
||||||
//array("foo@example.com/٭simplexe٭", false, false)
|
//array("foo@example.com/٭simplexe٭", false, false)
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function normalizationCases()
|
public static function normalizationCases()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
// Borrowed from test_jabber_jutil.c in libpurple
|
// Borrowed from test_jabber_jutil.c in libpurple
|
||||||
array('PaUL@DaRkRain42.org', 'paul@darkrain42.org'),
|
['PaUL@DaRkRain42.org', 'paul@darkrain42.org'],
|
||||||
array('PaUL@DaRkRain42.org/', 'paul@darkrain42.org'),
|
['PaUL@DaRkRain42.org/', 'paul@darkrain42.org'],
|
||||||
array('PaUL@DaRkRain42.org/resource', 'paul@darkrain42.org'),
|
['PaUL@DaRkRain42.org/resource', 'paul@darkrain42.org'],
|
||||||
|
|
||||||
// Also adapted from libpurple tests...
|
// Also adapted from libpurple tests...
|
||||||
array('Ф@darkrain42.org', 'ф@darkrain42.org'),
|
['Ф@darkrain42.org', 'ф@darkrain42.org'],
|
||||||
array('paul@Өarkrain.org', 'paul@өarkrain.org'),
|
['paul@Өarkrain.org', 'paul@өarkrain.org'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function domainCheckCases()
|
public static function domainCheckCases()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('gmail.com', true, 'known SRV record'),
|
['gmail.com', true, 'known SRV record'],
|
||||||
array('jabber.org', true, 'known SRV record'),
|
['jabber.org', true, 'known SRV record'],
|
||||||
array('status.net', true, 'known SRV record'),
|
['status.net', true, 'known SRV record'],
|
||||||
array('status.leuksman.com', true, 'known no SRV record but valid domain'),
|
['status.leuksman.com', true, 'known no SRV record but valid domain'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestXmppPlugin extends XmppPlugin
|
class TestXmppPlugin extends XmppPlugin
|
||||||
|
@ -39,87 +39,89 @@ require_once INSTALLDIR . '/lib/util/common.php';
|
|||||||
|
|
||||||
final class MediaFileTest extends TestCase
|
final class MediaFileTest extends TestCase
|
||||||
{
|
{
|
||||||
|
protected function setup(): void
|
||||||
public function setup(): void
|
|
||||||
{
|
{
|
||||||
$this->old_attachments_supported = common_config('attachments', 'supported');
|
$this->old_attachments_supported = common_config('attachments', 'supported');
|
||||||
$GLOBALS['config']['attachments']['supported'] = true;
|
$GLOBALS['config']['attachments']['supported'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
$GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported;
|
$GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider fileTypeCases
|
* @dataProvider fileTypeCases
|
||||||
|
*
|
||||||
* @param $filename
|
* @param $filename
|
||||||
* @param $expectedType
|
* @param $expectedType
|
||||||
|
*
|
||||||
* @throws ClientException
|
* @throws ClientException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public function testMimeType($filename, $expectedType)
|
public function testMimeType($filename, $expectedType)
|
||||||
{
|
{
|
||||||
if (!file_exists($filename)) {
|
if (!file_exists($filename)) {
|
||||||
throw new Exception("Test file $filename missing");
|
throw new Exception("Test file {$filename} missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = MediaFile::getUploadedMimeType($filename, basename($filename));
|
$type = MediaFile::getUploadedMimeType($filename, basename($filename));
|
||||||
$this->assertEquals($expectedType, $type);
|
static::assertSame($expectedType, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider fileTypeCases
|
* @dataProvider fileTypeCases
|
||||||
|
*
|
||||||
* @param $filename
|
* @param $filename
|
||||||
* @param $expectedType
|
* @param $expectedType
|
||||||
|
*
|
||||||
* @throws ClientException
|
* @throws ClientException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public function testUploadedMimeType($filename, $expectedType)
|
public function testUploadedMimeType($filename, $expectedType)
|
||||||
{
|
{
|
||||||
if (!file_exists($filename)) {
|
if (!file_exists($filename)) {
|
||||||
throw new Exception("WTF? $filename test file missing");
|
throw new Exception("WTF? {$filename} test file missing");
|
||||||
}
|
}
|
||||||
$tmp = tmpfile();
|
$tmp = tmpfile();
|
||||||
fwrite($tmp, file_get_contents($filename));
|
fwrite($tmp, file_get_contents($filename));
|
||||||
|
|
||||||
$tmp_metadata = stream_get_meta_data($tmp);
|
$tmp_metadata = stream_get_meta_data($tmp);
|
||||||
$type = MediaFile::getUploadedMimeType($tmp_metadata['uri'], basename($filename));
|
$type = MediaFile::getUploadedMimeType($tmp_metadata['uri'], basename($filename));
|
||||||
$this->assertEquals($expectedType, $type);
|
static::assertSame($expectedType, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function fileTypeCases()
|
public static function fileTypeCases()
|
||||||
{
|
{
|
||||||
$base = dirname(__FILE__);
|
$base = __DIR__;
|
||||||
$dir = "$base/sample-uploads";
|
$dir = "{$base}/sample-uploads";
|
||||||
$files = array(
|
$files = [
|
||||||
"image.png" => "image/png",
|
'image.png' => 'image/png',
|
||||||
"image.gif" => "image/gif",
|
'image.gif' => 'image/gif',
|
||||||
"image.jpg" => "image/jpeg",
|
'image.jpg' => 'image/jpeg',
|
||||||
"image.jpeg" => "image/jpeg",
|
'image.jpeg' => 'image/jpeg',
|
||||||
"office.pdf" => "application/pdf",
|
'office.pdf' => 'application/pdf',
|
||||||
"wordproc.odt" => "application/vnd.oasis.opendocument.text",
|
'wordproc.odt' => 'application/vnd.oasis.opendocument.text',
|
||||||
"wordproc.ott" => "application/vnd.oasis.opendocument.text-template",
|
'wordproc.ott' => 'application/vnd.oasis.opendocument.text-template',
|
||||||
"wordproc.doc" => "application/msword",
|
'wordproc.doc' => 'application/msword',
|
||||||
"wordproc.docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
'wordproc.docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
"wordproc.rtf" => "text/rtf",
|
'wordproc.rtf' => 'text/rtf',
|
||||||
"spreadsheet.ods" => "application/vnd.oasis.opendocument.spreadsheet",
|
'spreadsheet.ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||||
"spreadsheet.ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
|
'spreadsheet.ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
|
||||||
"spreadsheet.xls" => "application/vnd.ms-excel",
|
'spreadsheet.xls' => 'application/vnd.ms-excel',
|
||||||
"spreadsheet.xlt" => "application/vnd.ms-excel",
|
'spreadsheet.xlt' => 'application/vnd.ms-excel',
|
||||||
"spreadsheet.xlsx" =>"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
'spreadsheet.xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
"presentation.odp" => "application/vnd.oasis.opendocument.presentation",
|
'presentation.odp' => 'application/vnd.oasis.opendocument.presentation',
|
||||||
"presentation.otp" => "application/vnd.oasis.opendocument.presentation-template",
|
'presentation.otp' => 'application/vnd.oasis.opendocument.presentation-template',
|
||||||
"presentation.ppt" => "application/vnd.ms-powerpoint",
|
'presentation.ppt' => 'application/vnd.ms-powerpoint',
|
||||||
"presentation.pptx" => 'application/zip', //"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
'presentation.pptx' => 'application/zip', //"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||||
);
|
];
|
||||||
|
|
||||||
$dataset = array();
|
$dataset = [];
|
||||||
foreach ($files as $file => $type) {
|
foreach ($files as $file => $type) {
|
||||||
$dataset[] = array("$dir/$file", $type);
|
$dataset[] = ["{$dir}/{$file}", $type];
|
||||||
}
|
}
|
||||||
return $dataset;
|
return $dataset;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ if (!defined('INSTALLDIR')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$shortoptions = 'n:p:';
|
$shortoptions = 'n:p:';
|
||||||
$longoptions = array('nickname=', 'password=', 'dry-run');
|
$longoptions = ['nickname=', 'password=', 'dry-run'];
|
||||||
|
|
||||||
$helptext = <<<END_OF_HELP
|
$helptext = <<<END_OF_HELP
|
||||||
USAGE: atompub_test.php [options]
|
USAGE: atompub_test.php [options]
|
||||||
@ -39,7 +39,7 @@ Options:
|
|||||||
|
|
||||||
END_OF_HELP;
|
END_OF_HELP;
|
||||||
|
|
||||||
require_once INSTALLDIR.'/scripts/commandline.inc';
|
require_once INSTALLDIR . '/scripts/commandline.inc';
|
||||||
|
|
||||||
$user = get_option_value('n', 'nickname');
|
$user = get_option_value('n', 'nickname');
|
||||||
$pass = get_option_value('p', 'password');
|
$pass = get_option_value('p', 'password');
|
||||||
@ -53,15 +53,15 @@ if (!$pass) {
|
|||||||
|
|
||||||
// discover the feed...
|
// discover the feed...
|
||||||
// @fixme will this actually work?
|
// @fixme will this actually work?
|
||||||
$url = common_local_url('ApiTimelineUser', array('format' => 'atom', 'id' => $user));
|
$url = common_local_url('ApiTimelineUser', ['format' => 'atom', 'id' => $user]);
|
||||||
|
|
||||||
echo "Collection URL is: $url\n";
|
echo "Collection URL is: {$url}\n";
|
||||||
|
|
||||||
$collection = new AtomPubClient($url, $user, $pass);
|
$collection = new AtomPubClient($url, $user, $pass);
|
||||||
|
|
||||||
// confirm the feed has edit links ..... ?
|
// confirm the feed has edit links ..... ?
|
||||||
|
|
||||||
echo "Posting an empty message (should fail)... ";
|
echo 'Posting an empty message (should fail)... ';
|
||||||
try {
|
try {
|
||||||
$noticeUrl = $collection->post('');
|
$noticeUrl = $collection->post('');
|
||||||
die("FAILED, succeeded!\n");
|
die("FAILED, succeeded!\n");
|
||||||
@ -69,7 +69,7 @@ try {
|
|||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Posting an invalid XML message (should fail)... ";
|
echo 'Posting an invalid XML message (should fail)... ';
|
||||||
try {
|
try {
|
||||||
$noticeUrl = $collection->post('<feed<entry>barf</yomomma>');
|
$noticeUrl = $collection->post('<feed<entry>barf</yomomma>');
|
||||||
die("FAILED, succeeded!\n");
|
die("FAILED, succeeded!\n");
|
||||||
@ -77,7 +77,7 @@ try {
|
|||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Posting a valid XML but non-Atom message (should fail)... ";
|
echo 'Posting a valid XML but non-Atom message (should fail)... ';
|
||||||
try {
|
try {
|
||||||
$noticeUrl = $collection->post('<feed xmlns="http://notatom.com"><id>arf</id><entry><id>barf</id></entry></feed>');
|
$noticeUrl = $collection->post('<feed xmlns="http://notatom.com"><id>arf</id><entry><id>barf</id></entry></feed>');
|
||||||
die("FAILED, succeeded!\n");
|
die("FAILED, succeeded!\n");
|
||||||
@ -89,37 +89,37 @@ try {
|
|||||||
$rand = mt_rand(0, 99999);
|
$rand = mt_rand(0, 99999);
|
||||||
$atom = <<<END_ATOM
|
$atom = <<<END_ATOM
|
||||||
<entry xmlns="http://www.w3.org/2005/Atom">
|
<entry xmlns="http://www.w3.org/2005/Atom">
|
||||||
<title>This is an AtomPub test post title ($rand)</title>
|
<title>This is an AtomPub test post title ({$rand})</title>
|
||||||
<content>This is an AtomPub test post content ($rand)</content>
|
<content>This is an AtomPub test post content ({$rand})</content>
|
||||||
</entry>
|
</entry>
|
||||||
END_ATOM;
|
END_ATOM;
|
||||||
|
|
||||||
echo "Posting a new message... ";
|
echo 'Posting a new message... ';
|
||||||
$noticeUrl = $collection->post($atom);
|
$noticeUrl = $collection->post($atom);
|
||||||
echo "ok, got $noticeUrl\n";
|
echo "ok, got {$noticeUrl}\n";
|
||||||
|
|
||||||
echo "Fetching the new notice... ";
|
echo 'Fetching the new notice... ';
|
||||||
$notice = new AtomPubClient($noticeUrl, $user, $pass);
|
$notice = new AtomPubClient($noticeUrl, $user, $pass);
|
||||||
$body = $notice->get();
|
$body = $notice->get();
|
||||||
AtomPubClient::validateAtomEntry($body);
|
AtomPubClient::validateAtomEntry($body);
|
||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
|
|
||||||
echo "Getting the notice ID URI... ";
|
echo 'Getting the notice ID URI... ';
|
||||||
$noticeUri = AtomPubClient::entryId($body);
|
$noticeUri = AtomPubClient::entryId($body);
|
||||||
echo "ok: $noticeUri\n";
|
echo "ok: {$noticeUri}\n";
|
||||||
|
|
||||||
echo "Confirming new entry points to itself right... ";
|
echo 'Confirming new entry points to itself right... ';
|
||||||
$editUrl = AtomPubClient::entryEditURL($body);
|
$editUrl = AtomPubClient::entryEditURL($body);
|
||||||
if ($editUrl != $noticeUrl) {
|
if ($editUrl != $noticeUrl) {
|
||||||
die("Entry lists edit URL as $editUrl, no match!\n");
|
die("Entry lists edit URL as {$editUrl}, no match!\n");
|
||||||
}
|
}
|
||||||
echo "OK\n";
|
echo "OK\n";
|
||||||
|
|
||||||
echo "Refetching the collection... ";
|
echo 'Refetching the collection... ';
|
||||||
$feed = $collection->get();
|
$feed = $collection->get();
|
||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
|
|
||||||
echo "Confirming new entry is in the feed... ";
|
echo 'Confirming new entry is in the feed... ';
|
||||||
$entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
|
$entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
|
||||||
if (!$entry) {
|
if (!$entry) {
|
||||||
die("missing!\n");
|
die("missing!\n");
|
||||||
@ -127,7 +127,7 @@ if (!$entry) {
|
|||||||
// edit URL should match
|
// edit URL should match
|
||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
|
|
||||||
echo "Editing notice (should fail)... ";
|
echo 'Editing notice (should fail)... ';
|
||||||
try {
|
try {
|
||||||
$notice->put($target, $atom2);
|
$notice->put($target, $atom2);
|
||||||
die("ERROR: editing a notice should have failed.\n");
|
die("ERROR: editing a notice should have failed.\n");
|
||||||
@ -135,7 +135,7 @@ try {
|
|||||||
echo "ok (failed as expected)\n";
|
echo "ok (failed as expected)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Deleting notice... ";
|
echo 'Deleting notice... ';
|
||||||
$notice->delete();
|
$notice->delete();
|
||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
|
|
||||||
@ -148,11 +148,11 @@ try {
|
|||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Refetching the collection.. ";
|
echo 'Refetching the collection.. ';
|
||||||
$feed = $collection->get();
|
$feed = $collection->get();
|
||||||
echo "ok\n";
|
echo "ok\n";
|
||||||
|
|
||||||
echo "Confirming deleted notice is no longer in the feed... ";
|
echo 'Confirming deleted notice is no longer in the feed... ';
|
||||||
$entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
|
$entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
|
||||||
if ($entry) {
|
if ($entry) {
|
||||||
die("still there!\n");
|
die("still there!\n");
|
||||||
@ -167,9 +167,6 @@ echo "ok\n";
|
|||||||
|
|
||||||
// group memberships too
|
// group memberships too
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// make sure we can't post to someone else's feed!
|
// 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 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 subscriptions
|
||||||
|
@ -18,17 +18,17 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
|
define('INSTALLDIR', realpath(__DIR__ . '/../..'));
|
||||||
|
|
||||||
require_once INSTALLDIR . '/scripts/commandline.inc';
|
require_once INSTALLDIR . '/scripts/commandline.inc';
|
||||||
require_once INSTALLDIR . '/extlib/OAuth.php';
|
require_once INSTALLDIR . '/extlib/OAuth.php';
|
||||||
|
|
||||||
$ini = parse_ini_file("oauth.ini");
|
$ini = parse_ini_file('oauth.ini');
|
||||||
|
|
||||||
// Check to make sure we have everything we need from the ini file
|
// Check to make sure we have everything we need from the ini file
|
||||||
foreach(array('consumer_key', 'consumer_secret', 'apiroot', 'request_token_url') as $inikey) {
|
foreach (['consumer_key', 'consumer_secret', 'apiroot', 'request_token_url'] as $inikey) {
|
||||||
if (empty($ini[$inikey])) {
|
if (empty($ini[$inikey])) {
|
||||||
print "You forgot to specify a $inikey in your oauth.ini file.\n";
|
echo "You forgot to specify a {$inikey} in your oauth.ini file.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ foreach(array('consumer_key', 'consumer_secret', 'apiroot', 'request_token_url')
|
|||||||
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
||||||
$endpoint = $ini['apiroot'] . $ini['request_token_url'];
|
$endpoint = $ini['apiroot'] . $ini['request_token_url'];
|
||||||
$parsed = parse_url($endpoint);
|
$parsed = parse_url($endpoint);
|
||||||
$params = array();
|
$params = [];
|
||||||
|
|
||||||
parse_str($parsed['query'], $params);
|
parse_str($parsed['query'], $params);
|
||||||
$params['oauth_callback'] = 'oob'; // out-of-band
|
$params['oauth_callback'] = 'oob'; // out-of-band
|
||||||
@ -47,22 +47,22 @@ try {
|
|||||||
$req = OAuthRequest::from_consumer_and_token(
|
$req = OAuthRequest::from_consumer_and_token(
|
||||||
$consumer,
|
$consumer,
|
||||||
null,
|
null,
|
||||||
"POST",
|
'POST',
|
||||||
$endpoint,
|
$endpoint,
|
||||||
$params
|
$params
|
||||||
);
|
);
|
||||||
$req->sign_request($hmac_method, $consumer, NULL);
|
$req->sign_request($hmac_method, $consumer, null);
|
||||||
$r = httpRequest($endpoint, $req->to_postdata());
|
$r = httpRequest($endpoint, $req->to_postdata());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// oh noez
|
// oh noez
|
||||||
print $e->getMessage();
|
echo $e->getMessage();
|
||||||
print "\nOAuth Request:\n";
|
echo "\nOAuth Request:\n";
|
||||||
var_dump($req);
|
var_dump($req);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = $r->getBody();
|
$body = $r->getBody();
|
||||||
$tokenStuff = array();
|
$tokenStuff = [];
|
||||||
|
|
||||||
parse_str($body, $tokenStuff);
|
parse_str($body, $tokenStuff);
|
||||||
|
|
||||||
@ -72,32 +72,31 @@ $confirmed = $tokenStuff['oauth_callback_confirmed'];
|
|||||||
if (empty($tokenStuff['oauth_token'])
|
if (empty($tokenStuff['oauth_token'])
|
||||||
|| empty($tokenStuff['oauth_token_secret'])
|
|| empty($tokenStuff['oauth_token_secret'])
|
||||||
|| empty($confirmed)
|
|| empty($confirmed)
|
||||||
|| $confirmed != 'true')
|
|| $confirmed != 'true') {
|
||||||
{
|
echo "Error! HTTP response body: {$body}\n";
|
||||||
print "Error! HTTP response body: $body\n";
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$authurl = $ini['apiroot'] . $ini['authorize_url'] . '?oauth_token=' . $tok;
|
$authurl = $ini['apiroot'] . $ini['authorize_url'] . '?oauth_token=' . $tok;
|
||||||
|
|
||||||
print "Request Token\n";
|
echo "Request Token\n";
|
||||||
print ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
|
echo ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
|
||||||
print ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
|
echo ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
|
||||||
print "Authorize URL\n $authurl\n\n";
|
echo "Authorize URL\n {$authurl}\n\n";
|
||||||
print "Now paste the Authorize URL into your browser and authorize your temporary credentials.\n";
|
echo "Now paste the Authorize URL into your browser and authorize your temporary credentials.\n";
|
||||||
|
|
||||||
function httpRequest($endpoint, $poststr)
|
function httpRequest($endpoint, $poststr)
|
||||||
{
|
{
|
||||||
$request = HTTPClient::start();
|
$request = HTTPClient::start();
|
||||||
|
|
||||||
$request->setConfig(
|
$request->setConfig(
|
||||||
array(
|
[
|
||||||
'follow_redirects' => true,
|
'follow_redirects' => true,
|
||||||
'connect_timeout' => 120,
|
'connect_timeout' => 120,
|
||||||
'timeout' => 120,
|
'timeout' => 120,
|
||||||
'ssl_verify_peer' => false,
|
'ssl_verify_peer' => false,
|
||||||
'ssl_verify_host' => false
|
'ssl_verify_host' => false,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Turn signed request query string back into an array
|
// Turn signed request query string back into an array
|
||||||
|
@ -18,16 +18,16 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
|
define('INSTALLDIR', realpath(__DIR__ . '/../..'));
|
||||||
|
|
||||||
require_once INSTALLDIR . '/extlib/OAuth.php';
|
require_once INSTALLDIR . '/extlib/OAuth.php';
|
||||||
|
|
||||||
$ini = parse_ini_file("oauth.ini");
|
$ini = parse_ini_file('oauth.ini');
|
||||||
|
|
||||||
// Check to make sure we have everything we need from the ini file
|
// Check to make sure we have everything we need from the ini file
|
||||||
foreach(array('consumer_key', 'consumer_secret', 'apiroot', 'access_token_url') as $inikey) {
|
foreach (['consumer_key', 'consumer_secret', 'apiroot', 'access_token_url'] as $inikey) {
|
||||||
if (empty($ini[$inikey])) {
|
if (empty($ini[$inikey])) {
|
||||||
print "You forgot to specify a $inikey in your oauth.ini file.\n";
|
echo "You forgot to specify a {$inikey} in your oauth.ini file.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
|||||||
$endpoint = $ini['apiroot'] . $ini['access_token_url'];
|
$endpoint = $ini['apiroot'] . $ini['access_token_url'];
|
||||||
|
|
||||||
$shortoptions = 't:s:v:';
|
$shortoptions = 't:s:v:';
|
||||||
$longoptions = array('oauth_token=', 'oauth_token_secret=', 'oauth_verifier=');
|
$longoptions = ['oauth_token=', 'oauth_token_secret=', 'oauth_verifier='];
|
||||||
|
|
||||||
$helptext = <<<END_OF_ETOKENS_HELP
|
$helptext = <<<END_OF_ETOKENS_HELP
|
||||||
fetch_token_creds.php [options]
|
fetch_token_creds.php [options]
|
||||||
@ -69,17 +69,17 @@ if (have_option('v', 'oauth_verifier')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token)) {
|
if (empty($token)) {
|
||||||
print "Please specify the request token (--help for help).\n";
|
echo "Please specify the request token (--help for help).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($secret)) {
|
if (empty($secret)) {
|
||||||
print "Please specify the request token secret (--help for help).\n";
|
echo "Please specify the request token secret (--help for help).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($verifier)) {
|
if (empty($verifier)) {
|
||||||
print "Please specify the request token verifier (--help for help).\n";
|
echo "Please specify the request token verifier (--help for help).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,11 +92,10 @@ $params['oauth_verifier'] = $verifier; // 1.0a
|
|||||||
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$oauthReq = OAuthRequest::from_consumer_and_token(
|
$oauthReq = OAuthRequest::from_consumer_and_token(
|
||||||
$consumer,
|
$consumer,
|
||||||
$rtok,
|
$rtok,
|
||||||
"POST",
|
'POST',
|
||||||
$endpoint,
|
$endpoint,
|
||||||
$params
|
$params
|
||||||
);
|
);
|
||||||
@ -105,39 +104,38 @@ try {
|
|||||||
|
|
||||||
$httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
|
$httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
|
||||||
$body = $httpReq->getBody();
|
$body = $httpReq->getBody();
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// oh noez
|
// oh noez
|
||||||
print $e->getMessage();
|
echo $e->getMessage();
|
||||||
print "\nOAuth Request:\n";
|
echo "\nOAuth Request:\n";
|
||||||
var_dump($oauthReq);
|
var_dump($oauthReq);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokenStuff = array();
|
$tokenStuff = [];
|
||||||
parse_str($body, $tokenStuff);
|
parse_str($body, $tokenStuff);
|
||||||
|
|
||||||
if (empty($tokenStuff['oauth_token']) || empty($tokenStuff['oauth_token_secret'])) {
|
if (empty($tokenStuff['oauth_token']) || empty($tokenStuff['oauth_token_secret'])) {
|
||||||
print "Error! HTTP response body: $body\n";
|
echo "Error! HTTP response body: {$body}\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Access Token\n";
|
echo "Access Token\n";
|
||||||
print ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
|
echo ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
|
||||||
print ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
|
echo ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
|
||||||
|
|
||||||
function httpRequest($endpoint, $poststr)
|
function httpRequest($endpoint, $poststr)
|
||||||
{
|
{
|
||||||
$request = HTTPClient::start();
|
$request = HTTPClient::start();
|
||||||
|
|
||||||
$request->setConfig(
|
$request->setConfig(
|
||||||
array(
|
[
|
||||||
'follow_redirects' => true,
|
'follow_redirects' => true,
|
||||||
'connect_timeout' => 120,
|
'connect_timeout' => 120,
|
||||||
'timeout' => 120,
|
'timeout' => 120,
|
||||||
'ssl_verify_peer' => false,
|
'ssl_verify_peer' => false,
|
||||||
'ssl_verify_host' => false
|
'ssl_verify_host' => false,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
parse_str($poststr, $postdata);
|
parse_str($poststr, $postdata);
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
**/
|
*/
|
||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
|
define('INSTALLDIR', realpath(__DIR__ . '/../..'));
|
||||||
|
|
||||||
require_once INSTALLDIR . '/extlib/OAuth.php';
|
require_once INSTALLDIR . '/extlib/OAuth.php';
|
||||||
|
|
||||||
$shortoptions = 't:s:u:';
|
$shortoptions = 't:s:u:';
|
||||||
$longoptions = array('oauth_token=', 'oauth_token_secret=', 'update=');
|
$longoptions = ['oauth_token=', 'oauth_token_secret=', 'update='];
|
||||||
|
|
||||||
$helptext = <<<END_OF_VERIFY_HELP
|
$helptext = <<<END_OF_VERIFY_HELP
|
||||||
oauth_post_notice.php [options]
|
oauth_post_notice.php [options]
|
||||||
@ -55,21 +55,21 @@ if (have_option('u', 'update')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token)) {
|
if (empty($token)) {
|
||||||
print "Please specify an access token.\n";
|
echo "Please specify an access token.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token_secret)) {
|
if (empty($token_secret)) {
|
||||||
print "Please specify an access token secret.\n";
|
echo "Please specify an access token secret.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($update)) {
|
if (empty($update)) {
|
||||||
print "You forgot to update your status!\n";
|
echo "You forgot to update your status!\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ini = parse_ini_file("oauth.ini");
|
$ini = parse_ini_file('oauth.ini');
|
||||||
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
||||||
$endpoint = $ini['apiroot'] . '/statuses/update.xml';
|
$endpoint = $ini['apiroot'] . '/statuses/update.xml';
|
||||||
|
|
||||||
@ -83,7 +83,6 @@ $params['status'] = $update;
|
|||||||
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$oauthReq = OAuthRequest::from_consumer_and_token(
|
$oauthReq = OAuthRequest::from_consumer_and_token(
|
||||||
$consumer,
|
$consumer,
|
||||||
$atok,
|
$atok,
|
||||||
@ -96,10 +95,9 @@ try {
|
|||||||
|
|
||||||
$httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
|
$httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
|
||||||
|
|
||||||
print $httpReq->getBody();
|
echo $httpReq->getBody();
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print "Error! . $e->getMessage() . 'HTTP reponse body: " . $httpReq->getBody();
|
echo "Error! . {$e->getMessage}() . 'HTTP reponse body: " . $httpReq->getBody();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,13 +106,13 @@ function httpRequest($endpoint, $poststr)
|
|||||||
$request = HTTPClient::start();
|
$request = HTTPClient::start();
|
||||||
|
|
||||||
$request->setConfig(
|
$request->setConfig(
|
||||||
array(
|
[
|
||||||
'follow_redirects' => true,
|
'follow_redirects' => true,
|
||||||
'connect_timeout' => 120,
|
'connect_timeout' => 120,
|
||||||
'timeout' => 120,
|
'timeout' => 120,
|
||||||
'ssl_verify_peer' => false,
|
'ssl_verify_peer' => false,
|
||||||
'ssl_verify_host' => false
|
'ssl_verify_host' => false,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Turn signed request query string back into an array
|
// Turn signed request query string back into an array
|
||||||
|
@ -18,12 +18,12 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
|
define('INSTALLDIR', realpath(__DIR__ . '/../..'));
|
||||||
|
|
||||||
require_once INSTALLDIR . '/extlib/OAuth.php';
|
require_once INSTALLDIR . '/extlib/OAuth.php';
|
||||||
|
|
||||||
$shortoptions = 't:s:';
|
$shortoptions = 't:s:';
|
||||||
$longoptions = array('oauth_token=', 'oauth_token_secret=');
|
$longoptions = ['oauth_token=', 'oauth_token_secret='];
|
||||||
|
|
||||||
$helptext = <<<END_OF_VERIFY_HELP
|
$helptext = <<<END_OF_VERIFY_HELP
|
||||||
oauth_verify_creds.php [options]
|
oauth_verify_creds.php [options]
|
||||||
@ -48,16 +48,16 @@ if (have_option('s', 'oauth_token_secret')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token)) {
|
if (empty($token)) {
|
||||||
print "Please specify an access token (--help for help).\n";
|
echo "Please specify an access token (--help for help).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token_secret)) {
|
if (empty($token_secret)) {
|
||||||
print "Please specify an access token secret (--help for help).\n";
|
echo "Please specify an access token secret (--help for help).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ini = parse_ini_file("oauth.ini");
|
$ini = parse_ini_file('oauth.ini');
|
||||||
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
|
||||||
$endpoint = $ini['apiroot'] . '/account/verify_credentials.xml';
|
$endpoint = $ini['apiroot'] . '/account/verify_credentials.xml';
|
||||||
|
|
||||||
@ -67,13 +67,12 @@ $parsed = parse_url($endpoint);
|
|||||||
parse_str($parsed['query'], $params);
|
parse_str($parsed['query'], $params);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
||||||
|
|
||||||
$oauthReq = OAuthRequest::from_consumer_and_token(
|
$oauthReq = OAuthRequest::from_consumer_and_token(
|
||||||
$consumer,
|
$consumer,
|
||||||
$atok,
|
$atok,
|
||||||
"GET",
|
'GET',
|
||||||
$endpoint,
|
$endpoint,
|
||||||
$params
|
$params
|
||||||
);
|
);
|
||||||
@ -81,26 +80,25 @@ try {
|
|||||||
$oauthReq->sign_request($hmac_method, $consumer, $atok);
|
$oauthReq->sign_request($hmac_method, $consumer, $atok);
|
||||||
|
|
||||||
$httpReq = httpRequest($oauthReq->to_url());
|
$httpReq = httpRequest($oauthReq->to_url());
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print "Error! HTTP response body: " . $httpReq->getBody();
|
echo 'Error! HTTP response body: ' . $httpReq->getBody();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
print $httpReq->getBody();
|
echo $httpReq->getBody();
|
||||||
|
|
||||||
function httpRequest($url)
|
function httpRequest($url)
|
||||||
{
|
{
|
||||||
$request = HTTPClient::start();
|
$request = HTTPClient::start();
|
||||||
|
|
||||||
$request->setConfig(
|
$request->setConfig(
|
||||||
array(
|
[
|
||||||
'follow_redirects' => true,
|
'follow_redirects' => true,
|
||||||
'connect_timeout' => 120,
|
'connect_timeout' => 120,
|
||||||
'timeout' => 120,
|
'timeout' => 120,
|
||||||
'ssl_verify_peer' => false,
|
'ssl_verify_peer' => false,
|
||||||
'ssl_verify_host' => false
|
'ssl_verify_host' => false,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return $request->get($url);
|
return $request->get($url);
|
||||||
|
Loading…
Reference in New Issue
Block a user