[FORMAT] Run php-cs-fixer on tests/

This commit is contained in:
Diogo Cordeiro 2020-06-24 13:08:11 +01:00 committed by Diogo Peralta Cordeiro
parent bba9c0d560
commit 81d50c4ec3
19 changed files with 1026 additions and 1024 deletions

View File

@ -45,14 +45,14 @@ require_once INSTALLDIR . '/lib/util/common.php';
final class ActivityGenerationTests extends TestCase
{
static $author1 = null;
static $author2 = null;
public static $author1 = null;
public static $author2 = null;
static $targetUser1 = null;
static $targetUser2 = null;
public static $targetUser1 = null;
public static $targetUser2 = null;
static $targetGroup1 = null;
static $targetGroup2 = null;
public static $targetGroup1 = null;
public static $targetGroup2 = null;
public static function setUpBeforeClass(): void
{
@ -66,42 +66,42 @@ final class ActivityGenerationTests extends TestCase
$groupNick2 = 'activitygenerationtestsgroup' . common_random_hexstr(4);
try {
self::$author1 = User::register(array('nickname' => $authorNick1,
self::$author1 = User::register(['nickname' => $authorNick1,
'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_confirmed' => true));
'email_confirmed' => true,]);
self::$targetUser1 = User::register(array('nickname' => $targetNick1,
self::$targetUser1 = User::register(['nickname' => $targetNick1,
'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_confirmed' => true));
'email_confirmed' => true,]);
self::$targetGroup1 = User_group::register(array('nickname' => $groupNick1,
self::$targetGroup1 = User_group::register(['nickname' => $groupNick1,
'userid' => self::$author1->id,
'aliases' => array(),
'aliases' => [],
'local' => true,
'location' => null,
'description' => null,
'fullname' => null,
'homepage' => null,
'mainpage' => null));
self::$targetGroup2 = User_group::register(array('nickname' => $groupNick2,
'mainpage' => null,]);
self::$targetGroup2 = User_group::register(['nickname' => $groupNick2,
'userid' => self::$author1->id,
'aliases' => array(),
'aliases' => [],
'local' => true,
'location' => null,
'description' => null,
'fullname' => null,
'homepage' => null,
'mainpage' => null));
'mainpage' => null,]);
} catch (Exception $e) {
self::tearDownAfterClass();
static::tearDownAfterClass();
throw $e;
}
}
@ -114,13 +114,13 @@ final class ActivityGenerationTests extends TestCase
$element = $this->_entryToElement($entry, false);
$this->assertEquals($notice->getUri(), ActivityUtils::childContent($element, 'id'));
$this->assertEquals('New note by ' . self::$author1->nickname, ActivityUtils::childContent($element, 'title'));
$this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content'));
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published')));
$this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated')));
$this->assertEquals(ActivityVerb::POST, ActivityUtils::childContent($element, 'verb', Activity::SPEC));
$this->assertEquals(ActivityObject::NOTE, ActivityUtils::childContent($element, 'object-type', Activity::SPEC));
static::assertSame($notice->getUri(), ActivityUtils::childContent($element, 'id'));
static::assertSame('New note by ' . self::$author1->nickname, ActivityUtils::childContent($element, 'title'));
static::assertSame($notice->rendered, ActivityUtils::childContent($element, 'content'));
static::assertSame(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published')));
static::assertSame(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated')));
static::assertSame(ActivityVerb::POST, ActivityUtils::childContent($element, 'verb', Activity::SPEC));
static::assertSame(ActivityObject::NOTE, ActivityUtils::childContent($element, 'object-type', Activity::SPEC));
}
public function testNamespaceFlag()
@ -131,27 +131,27 @@ final class ActivityGenerationTests extends TestCase
$element = $this->_entryToElement($entry, false);
$this->assertTrue($element->hasAttribute('xmlns'));
$this->assertTrue($element->hasAttribute('xmlns:thr'));
$this->assertTrue($element->hasAttribute('xmlns:georss'));
$this->assertTrue($element->hasAttribute('xmlns:activity'));
$this->assertTrue($element->hasAttribute('xmlns:media'));
$this->assertTrue($element->hasAttribute('xmlns:poco'));
$this->assertTrue($element->hasAttribute('xmlns:ostatus'));
$this->assertTrue($element->hasAttribute('xmlns:statusnet'));
static::assertTrue($element->hasAttribute('xmlns'));
static::assertTrue($element->hasAttribute('xmlns:thr'));
static::assertTrue($element->hasAttribute('xmlns:georss'));
static::assertTrue($element->hasAttribute('xmlns:activity'));
static::assertTrue($element->hasAttribute('xmlns:media'));
static::assertTrue($element->hasAttribute('xmlns:poco'));
static::assertTrue($element->hasAttribute('xmlns:ostatus'));
static::assertTrue($element->hasAttribute('xmlns:statusnet'));
$entry = $notice->asAtomEntry(false);
$element = $this->_entryToElement($entry, true);
$this->assertFalse($element->hasAttribute('xmlns'));
$this->assertFalse($element->hasAttribute('xmlns:thr'));
$this->assertFalse($element->hasAttribute('xmlns:georss'));
$this->assertFalse($element->hasAttribute('xmlns:activity'));
$this->assertFalse($element->hasAttribute('xmlns:media'));
$this->assertFalse($element->hasAttribute('xmlns:poco'));
$this->assertFalse($element->hasAttribute('xmlns:ostatus'));
$this->assertFalse($element->hasAttribute('xmlns:statusnet'));
static::assertFalse($element->hasAttribute('xmlns'));
static::assertFalse($element->hasAttribute('xmlns:thr'));
static::assertFalse($element->hasAttribute('xmlns:georss'));
static::assertFalse($element->hasAttribute('xmlns:activity'));
static::assertFalse($element->hasAttribute('xmlns:media'));
static::assertFalse($element->hasAttribute('xmlns:poco'));
static::assertFalse($element->hasAttribute('xmlns:ostatus'));
static::assertFalse($element->hasAttribute('xmlns:statusnet'));
}
public function testSourceFlag()
@ -166,7 +166,7 @@ final class ActivityGenerationTests extends TestCase
$source = ActivityUtils::child($element, 'source');
$this->assertNull($source);
static::assertNull($source);
// Test with source
@ -176,7 +176,7 @@ final class ActivityGenerationTests extends TestCase
$source = ActivityUtils::child($element, 'source');
$this->assertNotNull($source);
static::assertNotNull($source);
}
public function testSourceContent()
@ -192,17 +192,17 @@ final class ActivityGenerationTests extends TestCase
$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();
$this->assertEquals($atomUrl, ActivityUtils::childContent($source, 'id'));
$this->assertEquals($atomUrl, ActivityUtils::getLink($source, 'self', 'application/atom+xml'));
$this->assertEquals($profile->profileurl, ActivityUtils::getPermalink($source));
$this->assertEquals(strtotime($notice2->created), strtotime(ActivityUtils::childContent($source, 'updated')));
static::assertSame($atomUrl, ActivityUtils::childContent($source, 'id'));
static::assertSame($atomUrl, ActivityUtils::getLink($source, 'self', 'application/atom+xml'));
static::assertSame($profile->profileurl, ActivityUtils::getPermalink($source));
static::assertSame(strtotime($notice2->created), strtotime(ActivityUtils::childContent($source, 'updated')));
// XXX: do we care here?
$this->assertFalse(is_null(ActivityUtils::childContent($source, 'title')));
$this->assertEquals(common_config('license', 'url'), ActivityUtils::getLink($source, 'license'));
static::assertFalse(is_null(ActivityUtils::childContent($source, 'title')));
static::assertSame(common_config('license', 'url'), ActivityUtils::getLink($source, 'license'));
}
public function testAuthorFlag()
@ -215,8 +215,8 @@ final class ActivityGenerationTests extends TestCase
$element = $this->_entryToElement($entry, true);
$this->assertNull(ActivityUtils::child($element, 'author'));
$this->assertNull(ActivityUtils::child($element, 'actor', Activity::SPEC));
static::assertNull(ActivityUtils::child($element, 'author'));
static::assertNull(ActivityUtils::child($element, 'actor', Activity::SPEC));
// Test with source
@ -227,8 +227,8 @@ final class ActivityGenerationTests extends TestCase
$author = ActivityUtils::child($element, 'author');
$actor = ActivityUtils::child($element, 'actor', Activity::SPEC);
$this->assertFalse(is_null($author));
$this->assertTrue(is_null($actor)); // <activity:actor> is obsolete, no longer added
static::assertFalse(is_null($author));
static::assertTrue(is_null($actor)); // <activity:actor> is obsolete, no longer added
}
public function testAuthorContent()
@ -243,8 +243,8 @@ final class ActivityGenerationTests extends TestCase
$author = ActivityUtils::child($element, 'author');
$this->assertEquals(self::$author1->getNickname(), ActivityUtils::childContent($author, 'name'));
$this->assertEquals(self::$author1->getUri(), ActivityUtils::childContent($author, 'uri'));
static::assertSame(self::$author1->getNickname(), ActivityUtils::childContent($author, 'name'));
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);
$this->assertEquals($actor, null);
static::assertSame($actor, null);
}
public function testReplyLink()
{
$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();
@ -279,37 +279,37 @@ final class ActivityGenerationTests extends TestCase
$irt = ActivityUtils::child($element, 'in-reply-to', 'http://purl.org/syndication/thread/1.0');
$this->assertNotNull($irt);
$this->assertEquals($orig->getUri(), $irt->getAttribute('ref'));
$this->assertEquals($orig->getUrl(), $irt->getAttribute('href'));
static::assertNotNull($irt);
static::assertSame($orig->getUri(), $irt->getAttribute('ref'));
static::assertSame($orig->getUrl(), $irt->getAttribute('href'));
}
public function testReplyAttention()
{
$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();
$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()
{
$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();
@ -317,34 +317,34 @@ final class ActivityGenerationTests extends TestCase
$links = ActivityUtils::getLinks($element, 'mentioned');
$hrefs = array();
$hrefs = [];
foreach ($links as $link) {
$hrefs[] = $link->getAttribute('href');
}
$this->assertTrue(in_array(self::$targetUser1->getUri(), $hrefs));
$this->assertTrue(in_array(self::$targetUser2->getUri(), $hrefs));
static::assertTrue(in_array(self::$targetUser1->getUri(), $hrefs));
static::assertTrue(in_array(self::$targetUser2->getUri(), $hrefs));
}
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();
$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()
{
$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();
@ -352,15 +352,14 @@ final class ActivityGenerationTests extends TestCase
$links = ActivityUtils::getLinks($element, 'mentioned');
$hrefs = array();
$hrefs = [];
foreach ($links as $link) {
$hrefs[] = $link->getAttribute('href');
}
$this->assertTrue(in_array(self::$targetGroup1->getUri(), $hrefs));
$this->assertTrue(in_array(self::$targetGroup2->getUri(), $hrefs));
static::assertTrue(in_array(self::$targetGroup1->getUri(), $hrefs));
static::assertTrue(in_array(self::$targetGroup2->getUri(), $hrefs));
}
public function testRepeatLink()
@ -374,9 +373,9 @@ final class ActivityGenerationTests extends TestCase
$noticeInfo = ActivityUtils::child($element, 'notice_info', 'http://status.net/schema/api/1/');
$this->assertNotNull($noticeInfo);
$this->assertEquals($notice->id, $noticeInfo->getAttribute('repeat_of'));
$this->assertEquals($repeat->id, $noticeInfo->getAttribute('local_id'));
static::assertNotNull($noticeInfo);
static::assertSame($notice->id, $noticeInfo->getAttribute('repeat_of'));
static::assertSame($repeat->id, $noticeInfo->getAttribute('local_id'));
}
public function testTag()
@ -391,8 +390,8 @@ final class ActivityGenerationTests extends TestCase
$category = ActivityUtils::child($element, 'category');
$this->assertNotNull($category);
$this->assertEquals($tag1, $category->getAttribute('term'));
static::assertNotNull($category);
static::assertSame($tag1, $category->getAttribute('term'));
}
public function testMultiTag()
@ -408,29 +407,29 @@ final class ActivityGenerationTests extends TestCase
$categories = $element->getElementsByTagName('category');
$this->assertNotNull($categories);
$this->assertEquals(2, $categories->length);
static::assertNotNull($categories);
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);
$terms[] = $cat->getAttribute('term');
}
$this->assertTrue(in_array($tag1, $terms));
$this->assertTrue(in_array($tag2, $terms));
static::assertTrue(in_array($tag1, $terms));
static::assertTrue(in_array($tag2, $terms));
}
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();
$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()
@ -441,14 +440,14 @@ final class ActivityGenerationTests extends TestCase
$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'));
$this->assertEquals($notice->source, $noticeInfo->getAttribute('source'));
$this->assertEquals('', $noticeInfo->getAttribute('repeat_of'));
$this->assertEquals('', $noticeInfo->getAttribute('repeated'));
static::assertSame($notice->id, $noticeInfo->getAttribute('local_id'));
static::assertSame($notice->source, $noticeInfo->getAttribute('source'));
static::assertSame('', $noticeInfo->getAttribute('repeat_of'));
static::assertSame('', $noticeInfo->getAttribute('repeated'));
// $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
$this->assertEquals('', $noticeInfo->getAttribute('source_link'));
static::assertSame('', $noticeInfo->getAttribute('source_link'));
}
public function testNoticeInfoRepeatOf()
@ -461,9 +460,9 @@ final class ActivityGenerationTests extends TestCase
$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()
@ -476,17 +475,17 @@ final class ActivityGenerationTests extends TestCase
$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());
$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()
@ -520,9 +519,9 @@ final class ActivityGenerationTests extends TestCase
{
$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);
@ -530,7 +529,7 @@ final class ActivityGenerationTests extends TestCase
$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
@ -567,10 +566,10 @@ final class ActivityGenerationTests extends TestCase
}
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)

View File

@ -40,7 +40,6 @@ require_once INSTALLDIR . '/lib/util/common.php';
final class ActivityParseTests extends TestCase
{
public function testMastodonRetweet()
{
global $_mastodon_retweet;
@ -50,11 +49,11 @@ final class ActivityParseTests extends TestCase
$entries = $feed->getElementsByTagName('entry');
$entry = $entries->item(0);
$act = new Activity($entry, $feed);
$this->assertFalse(empty($act));
$this->assertFalse(empty($act->objects[0]));
static::assertFalse(empty($act));
static::assertFalse(empty($act->objects[0]));
$object = $act->objects[0];
$this->assertEquals($object->verb, ActivityVerb::POST);
static::assertSame($object->verb, ActivityVerb::POST);
}
public function testGSReweet()
@ -66,11 +65,11 @@ final class ActivityParseTests extends TestCase
$entries = $feed->getElementsByTagName('entry');
$entry = $entries->item(0);
$act = new Activity($entry, $feed);
$this->assertFalse(empty($act));
$this->assertFalse(empty($act->objects[0]));
static::assertFalse(empty($act));
static::assertFalse(empty($act->objects[0]));
$object = $act->objects[0];
$this->assertEquals($object->verb, ActivityVerb::POST);
static::assertSame($object->verb, ActivityVerb::POST);
}
public function testExample1()
@ -80,16 +79,16 @@ final class ActivityParseTests extends TestCase
$dom->loadXML($_example1);
$act = new Activity($dom->documentElement);
$this->assertFalse(empty($act));
static::assertFalse(empty($act));
$this->assertEquals(1243860840, $act->time);
$this->assertEquals(ActivityVerb::POST, $act->verb);
static::assertSame(1243860840, $act->time);
static::assertSame(ActivityVerb::POST, $act->verb);
$this->assertFalse(empty($act->objects[0]));
$this->assertEquals('Punctuation Changeset', $act->objects[0]->title);
$this->assertEquals('http://versioncentral.example.org/activity/changeset', $act->objects[0]->type);
$this->assertEquals('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::assertFalse(empty($act->objects[0]));
static::assertSame('Punctuation Changeset', $act->objects[0]->title);
static::assertSame('http://versioncentral.example.org/activity/changeset', $act->objects[0]->type);
static::assertSame('Fixing punctuation because it makes it more readable.', $act->objects[0]->summary);
static::assertSame('tag:versioncentral.example.org,2009:/change/1643245', $act->objects[0]->id);
}
public function testExample2()
@ -99,10 +98,10 @@ final class ActivityParseTests extends TestCase
$dom->loadXML($_example2);
$act = new Activity($dom->documentElement);
$this->assertFalse(empty($act));
static::assertFalse(empty($act));
// Did we handle <content type="html"> correctly with a typical payload?
$this->assertEquals("<p>Geraldine posted a Photo on PhotoPanic</p>\n " .
"<img src=\"/geraldine/photo1.jpg\">", trim($act->content));
static::assertSame("<p>Geraldine posted a Photo on PhotoPanic</p>\n " .
'<img src="/geraldine/photo1.jpg">', trim($act->content));
}
public function testExample3()
@ -119,30 +118,30 @@ final class ActivityParseTests extends TestCase
$act = new Activity($entry, $feed);
$this->assertFalse(empty($act));
$this->assertEquals(1071340202, $act->time);
$this->assertEquals('http://example.org/2003/12/13/atom03.html', $act->link);
static::assertFalse(empty($act));
static::assertSame(1071340202, $act->time);
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));
$this->assertEquals(ActivityObject::PERSON, $act->actor->type);
$this->assertEquals('John Doe', $act->actor->title);
$this->assertEquals('mailto:johndoe@example.com', $act->actor->id);
static::assertFalse(empty($act->actor));
static::assertSame(ActivityObject::PERSON, $act->actor->type);
static::assertSame('John Doe', $act->actor->title);
static::assertSame('mailto:johndoe@example.com', $act->actor->id);
$this->assertFalse(empty($act->objects[0]));
$this->assertEquals(ActivityObject::NOTE, $act->objects[0]->type);
$this->assertEquals('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $act->objects[0]->id);
$this->assertEquals('Atom-Powered Robots Run Amok', $act->objects[0]->title);
$this->assertEquals('Some text.', $act->objects[0]->summary);
$this->assertEquals('http://example.org/2003/12/13/atom03.html', $act->objects[0]->link);
static::assertFalse(empty($act->objects[0]));
static::assertSame(ActivityObject::NOTE, $act->objects[0]->type);
static::assertSame('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', $act->objects[0]->id);
static::assertSame('Atom-Powered Robots Run Amok', $act->objects[0]->title);
static::assertSame('Some text.', $act->objects[0]->summary);
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);
$this->assertEquals($act->feed, $feed);
static::assertSame($act->entry, $entry);
static::assertSame($act->feed, $feed);
}
public function testExample4()
@ -155,21 +154,23 @@ final class ActivityParseTests extends TestCase
$act = new Activity($entry);
$this->assertFalse(empty($act));
$this->assertEquals(1266547958, $act->time);
$this->assertEquals('http://example.net/notice/14', $act->link);
static::assertFalse(empty($act));
static::assertSame(1266547958, $act->time);
static::assertSame('http://example.net/notice/14', $act->link);
$this->assertFalse(empty($act->context));
$this->assertEquals('http://example.net/notice/12', $act->context->replyToID);
$this->assertEquals('http://example.net/notice/12', $act->context->replyToUrl);
$this->assertEquals('http://example.net/conversation/11', $act->context->conversation);
$this->assertEquals(array('http://example.net/user/1'), array_keys($act->context->attention));
static::assertFalse(empty($act->context));
static::assertSame('http://example.net/notice/12', $act->context->replyToID);
static::assertSame('http://example.net/notice/12', $act->context->replyToUrl);
static::assertSame('http://example.net/conversation/11', $act->context->conversation);
static::assertSame(['http://example.net/user/1'], array_keys($act->context->attention));
$this->assertFalse(empty($act->objects[0]));
$this->assertEquals($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>');
static::assertFalse(empty($act->objects[0]));
static::assertSame(
$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()
@ -188,32 +189,32 @@ final class ActivityParseTests extends TestCase
$act = new Activity($entry, $feed);
// Post
$this->assertEquals($act->verb, ActivityVerb::POST);
$this->assertFalse(empty($act->context));
static::assertSame($act->verb, ActivityVerb::POST);
static::assertFalse(empty($act->context));
// Actor w/Portable Contacts stuff
$this->assertFalse(empty($act->actor));
$this->assertEquals($act->actor->type, ActivityObject::PERSON);
$this->assertEquals($act->actor->title, 'Test User');
$this->assertEquals($act->actor->id, 'http://example.net/mysite/user/3');
$this->assertEquals($act->actor->link, 'http://example.net/mysite/testuser');
static::assertFalse(empty($act->actor));
static::assertSame($act->actor->type, ActivityObject::PERSON);
static::assertSame($act->actor->title, 'Test User');
static::assertSame($act->actor->id, 'http://example.net/mysite/user/3');
static::assertSame($act->actor->link, 'http://example.net/mysite/testuser');
$avatars = $act->actor->avatarLinks;
$this->assertEquals(
static::assertSame(
$avatars[0]->url,
'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;
$this->assertEquals($poco->preferredUsername, 'testuser');
$this->assertEquals($poco->address->formatted, 'San Francisco, CA');
$this->assertEquals($poco->urls[0]->type, 'homepage');
$this->assertEquals($poco->urls[0]->value, 'http://example.com/blog.html');
$this->assertEquals($poco->urls[0]->primary, 'true');
$this->assertEquals($act->actor->geopoint, '37.7749295 -122.4194155');
static::assertSame($poco->preferredUsername, 'testuser');
static::assertSame($poco->address->formatted, 'San Francisco, CA');
static::assertSame($poco->urls[0]->type, 'homepage');
static::assertSame($poco->urls[0]->value, 'http://example.com/blog.html');
static::assertSame($poco->urls[0]->primary, 'true');
static::assertSame($act->actor->geopoint, '37.7749295 -122.4194155');
}
public function testExample6()
@ -235,17 +236,17 @@ final class ActivityParseTests extends TestCase
$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');
$this->assertEquals($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');
$this->assertEquals($act->time, 1267634892);
static::assertSame($act->id, 'http://en.blog.wordpress.com/?p=3857');
static::assertSame($act->link, 'http://en.blog.wordpress.com/2010/03/03/rub-a-dub-dub-in-the-pubsubhubbub/');
static::assertSame($act->title, 'Rub-a-Dub-Dub in the PubSubHubbub');
static::assertSame($act->time, 1267634892);
$actor = $act->actor;
$this->assertFalse(empty($actor));
$this->assertEquals($actor->title, "Joseph Scott");
static::assertFalse(empty($actor));
static::assertSame($actor->title, 'Joseph Scott');
}
public function testExample7()
@ -267,31 +268,33 @@ final class ActivityParseTests extends TestCase
$act = new Activity($item, $channel);
$this->assertEquals(ActivityVerb::POST, $act->verb);
$this->assertEquals('http://evanpro.posterous.com/checking-out-captain-bones', $act->link);
$this->assertEquals('http://evanpro.posterous.com/checking-out-captain-bones', $act->id);
$this->assertEquals('Checking out captain bones', $act->title);
$this->assertEquals(1269095551, $act->time);
static::assertSame(ActivityVerb::POST, $act->verb);
static::assertSame('http://evanpro.posterous.com/checking-out-captain-bones', $act->link);
static::assertSame('http://evanpro.posterous.com/checking-out-captain-bones', $act->id);
static::assertSame('Checking out captain bones', $act->title);
static::assertSame(1269095551, $act->time);
$actor = $act->actor;
$this->assertEquals(ActivityObject::PERSON, $actor->type);
$this->assertEquals('http://posterous.com/people/3sDslhaepotz', $actor->id);
$this->assertEquals('Evan Prodromou', $actor->title);
$this->assertNull($actor->summary);
$this->assertNull($actor->content);
$this->assertEquals('http://posterous.com/people/3sDslhaepotz', $actor->link);
$this->assertNull($actor->source);
$this->assertTrue(is_array($actor->avatarLinks));
$this->assertEquals(1, count($actor->avatarLinks));
$this->assertEquals('http://files.posterous.com/user_profile_pics/480326/2009-08-05-142447.jpg',
$actor->avatarLinks[0]->url);
$this->assertNotNull($actor->poco);
$this->assertEquals('evanpro', $actor->poco->preferredUsername);
$this->assertEquals('Evan Prodromou', $actor->poco->displayName);
$this->assertNull($actor->poco->note);
$this->assertNull($actor->poco->address);
$this->assertEquals(0, count($actor->poco->urls));
static::assertSame(ActivityObject::PERSON, $actor->type);
static::assertSame('http://posterous.com/people/3sDslhaepotz', $actor->id);
static::assertSame('Evan Prodromou', $actor->title);
static::assertNull($actor->summary);
static::assertNull($actor->content);
static::assertSame('http://posterous.com/people/3sDslhaepotz', $actor->link);
static::assertNull($actor->source);
static::assertTrue(is_array($actor->avatarLinks));
static::assertSame(1, count($actor->avatarLinks));
static::assertSame(
'http://files.posterous.com/user_profile_pics/480326/2009-08-05-142447.jpg',
$actor->avatarLinks[0]->url
);
static::assertNotNull($actor->poco);
static::assertSame('evanpro', $actor->poco->preferredUsername);
static::assertSame('Evan Prodromou', $actor->poco->displayName);
static::assertNull($actor->poco->note);
static::assertNull($actor->poco->address);
static::assertSame(0, count($actor->poco->urls));
}
// Media test - cliqset
@ -309,145 +312,144 @@ final class ActivityParseTests extends TestCase
$act = new Activity($entry, $feed);
$this->assertFalse(empty($act));
$this->assertEquals($act->time, 1269221753);
$this->assertEquals($act->verb, ActivityVerb::POST);
$this->assertEquals($act->summary, 'zcopley posted 5 photos on Flickr');
static::assertFalse(empty($act));
static::assertSame($act->time, 1269221753);
static::assertSame($act->verb, ActivityVerb::POST);
static::assertSame($act->summary, 'zcopley posted 5 photos on Flickr');
$this->assertFalse(empty($act->objects));
$this->assertEquals(sizeof($act->objects), 5);
static::assertFalse(empty($act->objects));
static::assertSame(sizeof($act->objects), 5);
$this->assertEquals($act->objects[0]->type, ActivityObject::PHOTO);
$this->assertEquals($act->objects[0]->title, 'IMG_1368');
$this->assertNull($act->objects[0]->description);
$this->assertEquals(
static::assertSame($act->objects[0]->type, ActivityObject::PHOTO);
static::assertSame($act->objects[0]->title, 'IMG_1368');
static::assertNull($act->objects[0]->description);
static::assertSame(
$act->objects[0]->thumbnail,
'http://media.cliqset.com/6f6fbee9d7dfbffc73b6ef626275eb5f_thumb.jpg'
);
$this->assertEquals(
static::assertSame(
$act->objects[0]->link,
'http://www.flickr.com/photos/zcopley/4452933806/'
);
$this->assertEquals($act->objects[1]->type, ActivityObject::PHOTO);
$this->assertEquals($act->objects[1]->title, 'IMG_1365');
$this->assertNull($act->objects[1]->description);
$this->assertEquals(
static::assertSame($act->objects[1]->type, ActivityObject::PHOTO);
static::assertSame($act->objects[1]->title, 'IMG_1365');
static::assertNull($act->objects[1]->description);
static::assertSame(
$act->objects[1]->thumbnail,
'http://media.cliqset.com/b8f3932cd0bba1b27f7c8b3ef986915e_thumb.jpg'
);
$this->assertEquals(
static::assertSame(
$act->objects[1]->link,
'http://www.flickr.com/photos/zcopley/4442630390/'
);
$this->assertEquals($act->objects[2]->type, ActivityObject::PHOTO);
$this->assertEquals($act->objects[2]->title, 'Classic');
$this->assertEquals(
static::assertSame($act->objects[2]->type, ActivityObject::PHOTO);
static::assertSame($act->objects[2]->title, 'Classic');
static::assertSame(
$act->objects[2]->description,
'-Powered by pikchur.com/n0u'
);
$this->assertEquals(
static::assertSame(
$act->objects[2]->thumbnail,
'http://media.cliqset.com/fc54c15f850b7a9a8efa644087a48c91_thumb.jpg'
);
$this->assertEquals(
static::assertSame(
$act->objects[2]->link,
'http://www.flickr.com/photos/zcopley/4430754103/'
);
$this->assertEquals($act->objects[3]->type, ActivityObject::PHOTO);
$this->assertEquals($act->objects[3]->title, 'IMG_1363');
$this->assertNull($act->objects[3]->description);
static::assertSame($act->objects[3]->type, ActivityObject::PHOTO);
static::assertSame($act->objects[3]->title, 'IMG_1363');
static::assertNull($act->objects[3]->description);
$this->assertEquals(
static::assertSame(
$act->objects[3]->thumbnail,
'http://media.cliqset.com/4b1d307c9217e2114391a8b229d612cb_thumb.jpg'
);
$this->assertEquals(
static::assertSame(
$act->objects[3]->link,
'http://www.flickr.com/photos/zcopley/4416969717/'
);
$this->assertEquals($act->objects[4]->type, ActivityObject::PHOTO);
$this->assertEquals($act->objects[4]->title, 'IMG_1361');
$this->assertNull($act->objects[4]->description);
static::assertSame($act->objects[4]->type, ActivityObject::PHOTO);
static::assertSame($act->objects[4]->title, 'IMG_1361');
static::assertNull($act->objects[4]->description);
$this->assertEquals(
static::assertSame(
$act->objects[4]->thumbnail,
'http://media.cliqset.com/23d9b4b96b286e0347d36052f22f6e60_thumb.jpg'
);
$this->assertEquals(
static::assertSame(
$act->objects[4]->link,
'http://www.flickr.com/photos/zcopley/4417734232/'
);
}
public function testAtomContent()
{
$tests = array(array("<content>Some regular plain text.</content>",
"Some regular plain text."),
array("<content>&lt;b&gt;this is not HTML&lt;/b&gt;</content>",
"&lt;b&gt;this is not HTML&lt;/b&gt;"),
array("<content type='html'>Some regular plain HTML.</content>",
"Some regular plain HTML."),
array("<content type='html'>&lt;b&gt;this is too HTML&lt;/b&gt;</content>",
"<b>this is too HTML</b>"),
array("<content type='html'>&amp;lt;b&amp;gt;but this is not HTML!&amp;lt;/b&amp;gt;</content>",
"&lt;b&gt;but this is not HTML!&lt;/b&gt;"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Some regular plain XHTML.</div></content>",
"Some regular plain XHTML."),
array("<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>"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&lt;b&gt;This is not some XHTML!&lt;/b&gt;</div></content>",
"&lt;b&gt;This is not some XHTML!&lt;/b&gt;"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;</div></content>",
"&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;"));
$tests = [['<content>Some regular plain text.</content>',
'Some regular plain text.',],
['<content>&lt;b&gt;this is not HTML&lt;/b&gt;</content>',
'&lt;b&gt;this is not HTML&lt;/b&gt;',],
["<content type='html'>Some regular plain HTML.</content>",
'Some regular plain HTML.',],
["<content type='html'>&lt;b&gt;this is too HTML&lt;/b&gt;</content>",
'<b>this is too HTML</b>',],
["<content type='html'>&amp;lt;b&amp;gt;but this is not HTML!&amp;lt;/b&amp;gt;</content>",
'&lt;b&gt;but this is not HTML!&lt;/b&gt;',],
["<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Some regular plain XHTML.</div></content>",
'Some regular plain XHTML.',],
["<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>',],
["<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&lt;b&gt;This is not some XHTML!&lt;/b&gt;</div></content>",
'&lt;b&gt;This is not some XHTML!&lt;/b&gt;',],
["<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;</div></content>",
'&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;',],];
foreach ($tests as $data) {
list($source, $output) = $data;
$xml = "<entry xmlns='http://www.w3.org/2005/Atom'>" .
"<id>http://example.com/fakeid</id>" .
"<author><name>Test</name></author>" .
"<title>Atom content tests</title>" .
'<id>http://example.com/fakeid</id>' .
'<author><name>Test</name></author>' .
'<title>Atom content tests</title>' .
$source .
"</entry>";
'</entry>';
$dom = new DOMDocument();
$dom->loadXML($xml);
$act = new Activity($dom->documentElement);
$this->assertFalse(empty($act));
$this->assertEquals($output, trim($act->content));
static::assertFalse(empty($act));
static::assertSame($output, trim($act->content));
}
}
public function testRssContent()
{
$tests = array(array("<content:encoded>Some regular plain HTML.</content:encoded>",
"Some regular plain HTML."),
array("<content:encoded>Some &lt;b&gt;exciting bold HTML&lt;/b&gt;</content:encoded>",
"Some <b>exciting bold HTML</b>"),
array("<content:encoded>Some &amp;lt;b&amp;gt;escaped non-HTML.&amp;lt;/b&amp;gt;</content:encoded>",
"Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;"),
array("<description>Some plain text.</description>",
"Some plain text."),
array("<description>Some &lt;b&gt;non-HTML text&lt;/b&gt;</description>",
"Some &lt;b&gt;non-HTML text&lt;/b&gt;"),
array("<description>Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;</description>",
"Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;"));
$tests = [['<content:encoded>Some regular plain HTML.</content:encoded>',
'Some regular plain HTML.',],
['<content:encoded>Some &lt;b&gt;exciting bold HTML&lt;/b&gt;</content:encoded>',
'Some <b>exciting bold HTML</b>',],
['<content:encoded>Some &amp;lt;b&amp;gt;escaped non-HTML.&amp;lt;/b&amp;gt;</content:encoded>',
'Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;',],
['<description>Some plain text.</description>',
'Some plain text.',],
['<description>Some &lt;b&gt;non-HTML text&lt;/b&gt;</description>',
'Some &lt;b&gt;non-HTML text&lt;/b&gt;',],
['<description>Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;</description>',
'Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;',],];
foreach ($tests as $data) {
list($source, $output) = $data;
$xml = "<item xmlns:content='http://purl.org/rss/1.0/modules/content/'>" .
"<guid>http://example.com/fakeid</guid>" .
"<title>RSS content tests</title>" .
'<guid>http://example.com/fakeid</guid>' .
'<title>RSS content tests</title>' .
$source .
"</item>";
'</item>';
$dom = new DOMDocument();
$dom->loadXML($xml);
$act = new Activity($dom->documentElement);
$this->assertFalse(empty($act));
$this->assertEquals($output, trim($act->content));
static::assertFalse(empty($act));
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>
// as the actor.
$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
// the feed's <activity:subject> which referred to the group.
// It should now be returning the expected author entry...
$act = new Activity($entry, $feed);
$this->assertEquals($act->actor->id, $expected);
static::assertSame($act->actor->id, $expected);
}
public function testBookmarkRelated()
@ -488,13 +490,13 @@ final class ActivityParseTests extends TestCase
$links = ActivityUtils::getLinks($entry, 'related');
$this->assertFalse(empty($links));
$this->assertTrue(is_array($links));
$this->assertEquals(count($links), 1);
static::assertFalse(empty($links));
static::assertTrue(is_array($links));
static::assertSame(count($links), 1);
$url = $links[0]->getAttribute('href');
$this->assertEquals($url, $expected);
static::assertSame($url, $expected);
}
}

View File

@ -31,6 +31,7 @@ final class CallableLeftCurryTest extends TestCase
{
/**
* @dataProvider provider
*
* @param $callback_test
* @param $curry_params
* @param $call_params
@ -41,42 +42,42 @@ final class CallableLeftCurryTest extends TestCase
$params = array_merge([$callback_test], $curry_params);
$curried = call_user_func_array('callableLeftCurry', $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');
return [[['Tests\Unit\CallableLeftCurryTest', 'callback_test'],
['curried'],
['called'],
'called|curried'],
'called|curried',],
[['Tests\Unit\CallableLeftCurryTest', 'callback_test'],
['curried1', 'curried2'],
['called1', 'called2'],
'called1|called2|curried1|curried2'],
'called1|called2|curried1|curried2',],
[['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'],
[$obj],
['newval1'],
'oldval|newval1'],
'oldval|newval1',],
// Confirm object identity is retained...
[['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'],
[$obj],
['newval2'],
'newval1|newval2']];
'newval1|newval2',],];
}
static function callback_test()
public static function callback_test()
{
$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;
$obj->val = $val;
return "$old|$val";
return "{$old}|{$val}";
}
}
@ -84,7 +85,7 @@ class CurryTestHelperObj
{
public $val = '';
function __construct($val)
public function __construct($val)
{
$this->val = $val;
}

View File

@ -35,14 +35,16 @@ use User;
require_once INSTALLDIR . '/lib/util/common.php';
final class CommandInterpreterTest extends TestCase
final class CommandInterperterTest extends TestCase
{
/**
* @dataProvider commandInterpreterCases
*
* @param $input
* @param $expectedType
* @param string $comment
* @throws \EmptyPkeyValueException
* @throws \ServerException
*/
public function testCommandInterpreter($input, $expectedType, $comment = '')
{
@ -51,148 +53,147 @@ final class CommandInterpreterTest extends TestCase
$cmd = $inter->handle_command(User::getById(1), $input);
$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(
array('help', 'HelpCommand'),
array('help me bro', null, 'help does not accept multiple params'),
array('HeLP', 'HelpCommand', 'case check'),
array('HeLP Me BRO!', null, 'case & non-params check'),
$sets = [
['help', 'HelpCommand'],
['help me bro', null, 'help does not accept multiple params'],
['HeLP', 'HelpCommand', 'case check'],
['HeLP Me BRO!', null, 'case & non-params check'],
array('login', 'LoginCommand'),
array('login to savings!', null, 'login does not accept params'),
['login', 'LoginCommand'],
['login to savings!', null, 'login does not accept params'],
array('lose', null, 'lose must have at least 1 parameter'),
array('lose foobar', 'LoseCommand', 'lose requires 1 parameter'),
array('lose foobar', 'LoseCommand', 'check for space norm'),
array('lose more weight', null, 'lose does not accept multiple params'),
['lose', null, 'lose must have at least 1 parameter'],
['lose foobar', 'LoseCommand', 'lose requires 1 parameter'],
['lose foobar', 'LoseCommand', 'check for space norm'],
['lose more weight', null, 'lose does not accept multiple params'],
array('subscribers', 'SubscribersCommand'),
array('subscribers foo', null, 'subscribers does not take params'),
['subscribers', 'SubscribersCommand'],
['subscribers foo', null, 'subscribers does not take params'],
array('subscriptions', 'SubscriptionsCommand'),
array('subscriptions foo', null, 'subscriptions does not take params'),
['subscriptions', 'SubscriptionsCommand'],
['subscriptions foo', null, 'subscriptions does not take params'],
array('groups', 'GroupsCommand'),
array('groups foo', null, 'groups does not take params'),
['groups', 'GroupsCommand'],
['groups foo', null, 'groups does not take params'],
array('off', 'OffCommand', 'off accepts 0 or 1 params'),
array('off foo', 'OffCommand', 'off accepts 0 or 1 params'),
array('off foo bar', null, 'off accepts 0 or 1 params'),
['off', 'OffCommand', 'off accepts 0 or 1 params'],
['off foo', 'OffCommand', 'off accepts 0 or 1 params'],
['off foo bar', null, 'off accepts 0 or 1 params'],
array('stop', 'OffCommand', 'stop accepts 0 params'),
array('stop foo', null, 'stop accepts 0 params'),
['stop', 'OffCommand', 'stop accepts 0 params'],
['stop foo', null, 'stop accepts 0 params'],
array('quit', 'OffCommand', 'quit accepts 0 params'),
array('quit foo', null, 'quit accepts 0 params'),
['quit', 'OffCommand', 'quit accepts 0 params'],
['quit foo', null, 'quit accepts 0 params'],
array('on', 'OnCommand', 'on accepts 0 or 1 params'),
array('on foo', 'OnCommand', 'on accepts 0 or 1 params'),
array('on foo bar', null, 'on accepts 0 or 1 params'),
['on', 'OnCommand', 'on accepts 0 or 1 params'],
['on foo', 'OnCommand', 'on accepts 0 or 1 params'],
['on foo bar', null, 'on accepts 0 or 1 params'],
array('join', null),
array('join foo', 'JoinCommand'),
array('join foo bar', null),
['join', null],
['join foo', 'JoinCommand'],
['join foo bar', null],
array('drop', null),
array('drop foo', 'DropCommand'),
array('drop foo bar', null),
['drop', null],
['drop foo', 'DropCommand'],
['drop foo bar', null],
array('follow', null),
array('follow foo', 'SubCommand'),
array('follow foo bar', null),
['follow', null],
['follow foo', 'SubCommand'],
['follow foo bar', null],
array('sub', null),
array('sub foo', 'SubCommand'),
array('sub foo bar', null),
['sub', null],
['sub foo', 'SubCommand'],
['sub foo bar', null],
array('leave', null),
array('leave foo', 'UnsubCommand'),
array('leave foo bar', null),
['leave', null],
['leave foo', 'UnsubCommand'],
['leave foo bar', null],
array('unsub', null),
array('unsub foo', 'UnsubCommand'),
array('unsub foo bar', null),
['unsub', null],
['unsub foo', 'UnsubCommand'],
['unsub foo bar', null],
array('leave', null),
array('leave foo', 'UnsubCommand'),
array('leave foo bar', null),
['leave', null],
['leave foo', 'UnsubCommand'],
['leave foo bar', null],
array('d', null),
array('d foo', null),
array('d foo bar', 'MessageCommand'),
['d', null],
['d foo', null],
['d foo bar', 'MessageCommand'],
array('dm', null),
array('dm foo', null),
array('dm foo bar', 'MessageCommand'),
['dm', null],
['dm foo', null],
['dm foo bar', 'MessageCommand'],
array('r', null),
array('r foo', null),
array('r foo bar', 'ReplyCommand'),
['r', null],
['r foo', null],
['r foo bar', 'ReplyCommand'],
array('reply', null),
array('reply foo', null),
array('reply foo bar', 'ReplyCommand'),
['reply', null],
['reply foo', null],
['reply foo bar', 'ReplyCommand'],
array('repeat', null),
array('repeat foo', 'RepeatCommand'),
array('repeat foo bar', null),
['repeat', null],
['repeat foo', 'RepeatCommand'],
['repeat foo bar', null],
array('rp', null),
array('rp foo', 'RepeatCommand'),
array('rp foo bar', null),
['rp', null],
['rp foo', 'RepeatCommand'],
['rp foo bar', null],
array('rt', null),
array('rt foo', 'RepeatCommand'),
array('rt foo bar', null),
['rt', null],
['rt foo', 'RepeatCommand'],
['rt foo bar', null],
array('rd', null),
array('rd foo', 'RepeatCommand'),
array('rd foo bar', null),
['rd', null],
['rd foo', 'RepeatCommand'],
['rd foo bar', null],
array('whois', null),
array('whois foo', 'WhoisCommand'),
array('whois foo bar', null),
['whois', null],
['whois foo', 'WhoisCommand'],
['whois foo bar', null],
/* array('fav', null),
array('fav foo', 'FavCommand'),
array('fav foo bar', null),*/
array('nudge', null),
array('nudge foo', 'NudgeCommand'),
array('nudge foo bar', null),
['nudge', null],
['nudge foo', 'NudgeCommand'],
['nudge foo bar', null],
array('stats', 'StatsCommand'),
array('stats foo', null),
['stats', 'StatsCommand'],
['stats foo', null],
array('invite', null),
array('invite foo', 'InviteCommand'),
array('invite foo bar', null),
['invite', null],
['invite foo', 'InviteCommand'],
['invite foo bar', null],
array('track', null),
array('track foo', 'SearchSubTrackCommand'),
array('track off', 'SearchSubTrackOffCommand'),
array('track foo bar', null),
array('track off foo', null),
['track', null],
['track foo', 'SearchSubTrackCommand'],
['track off', 'SearchSubTrackOffCommand'],
['track foo bar', null],
['track off foo', null],
array('untrack', null),
array('untrack foo', 'SearchSubUntrackCommand'),
array('untrack all', 'SearchSubTrackOffCommand'),
array('untrack foo bar', null),
array('untrack all foo', null),
['untrack', null],
['untrack foo', 'SearchSubUntrackCommand'],
['untrack all', 'SearchSubTrackOffCommand'],
['untrack foo bar', null],
['untrack all foo', null],
array('tracking', 'SearchSubTrackingCommand'),
array('tracking foo', null),
['tracking', 'SearchSubTrackingCommand'],
['tracking foo', null],
array('tracks', 'SearchSubTrackingCommand'),
array('tracks foo', null),
['tracks', 'SearchSubTrackingCommand'],
['tracks foo', null],
);
];
return $sets;
}
}

View File

@ -37,50 +37,51 @@ final class HashTagDetectionTests extends TestCase
{
/**
* @dataProvider provider
*
* @param $content
* @param $expected
*/
public function testProduction($content, $expected)
{
$rendered = common_render_text($content);
$this->assertEquals($expected, $rendered);
static::assertSame($expected, $rendered);
}
static public function provider()
public static function provider()
{
return array(
array('hello',
'hello'),
array('#hello people',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span> people'),
array('"#hello" people',
'&quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
array('say "#hello" people',
'say &quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
array('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'),
array('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'),
array('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'),
array('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'),
return [
['hello',
'hello',],
['#hello people',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span> people',],
['"#hello" people',
'&quot;#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>&quot; people',],
['say "#hello" people',
'say &quot;#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>&quot; people',],
['say (#hello) people',
'say (#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>) people',],
['say [#hello] people',
'say [#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>] people',],
['say {#hello} people',
'say {#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>} people',],
['say \'#hello\' 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
array('#éclair yummy',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('éclair'))) . '" rel="tag">éclair</a></span> yummy'),
array('#维基百科 zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span> zh.wikipedia!'),
array('#Россия russia',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('Россия'))) . '" rel="tag">Россия</a></span> russia'),
['#éclair yummy',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('éclair')]) . '" rel="tag">éclair</a></span> yummy',],
['#维基百科 zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span> zh.wikipedia!',],
['#Россия 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
array('#维基百科,zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),
array('#维基百科zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>zh.wikipedia!'),
['#维基百科,zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span>,zh.wikipedia!',],
['#维基百科zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span>zh.wikipedia!',],
);
];
}
}

View File

@ -42,86 +42,85 @@ addPlugin('Geonames');
final class LocationTest extends TestCase
{
/**
* @dataProvider locationNames
*
* @param $name
* @param $language
* @param $location
*/
public function testLocationFromName($name, $language, $location)
{
$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),
array('San Francisco, CA', 'en', null),
array('Paris, France', 'en', null),
array('Paris, Texas', 'en', null));
return [['Montreal', 'en', null],
['San Francisco, CA', 'en', null],
['Paris, France', 'en', null],
['Paris, Texas', 'en', null],];
}
/**
* @dataProvider locationIds
*
* @param $id
* @param $ns
* @param $language
* @param $location
*/
public function testLocationFromId($id, $ns, $language, $location)
{
$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),
array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
return [[6077243, GeonamesPlugin::LOCATION_NS, 'en', null],
[5391959, GeonamesPlugin::LOCATION_NS, 'en', null],];
}
/**
* @dataProvider locationLatLons
*
* @param $lat
* @param $lon
* @param $language
* @param $location
*/
public function testLocationFromLatLon($lat, $lon, $language, $location)
{
$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),
array(45.509, -73.588, 'en', null));
return [[37.77493, -122.41942, 'en', null],
[45.509, -73.588, 'en', null],];
}
/**
* @dataProvider nameOfLocation
*
* @param $location
* @param $language
* @param $name
*/
public function testLocationGetName($location, $language, $name)
{
$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');
return array(array($loc, 'en', null), //'Montreal'),
array($loc, 'fr', null));//'Montréal'));
return [[$loc, 'en', null], //'Montreal'),
[$loc, 'fr', null],]; //'Montréal'));
}
}

View File

@ -50,6 +50,7 @@ final class NicknameTest extends TestCase
* Basic test using Nickname::normalize()
*
* @dataProvider provider
*
* @param $input
* @param $expected
* @param null $expectedException
@ -71,25 +72,25 @@ final class NicknameTest extends TestCase
} else {
$stuff = var_export($exception, true);
}
$this->assertTrue(
static::assertTrue(
$exception && $exception instanceof $expectedException,
"invalid input '$input' expected to fail with $expectedException, " .
"got $stuff"
"invalid input '{$input}' expected to fail with {$expectedException}, " .
"got {$stuff}"
);
} else {
$this->assertTrue(
static::assertTrue(
$normalized == false,
"invalid input '$input' expected to fail"
"invalid input '{$input}' expected to fail"
);
}
} 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) {
$msg .= get_class($exception) . ': ' . $exception->getMessage();
} 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)
*
* @dataProvider provider
*
* @param $input
* @param $expected
* @param null $expectedException
*
* @throws NicknameBlacklistedException
* @throws NicknameEmptyException
* @throws NicknameException
@ -117,47 +120,47 @@ final class NicknameTest extends TestCase
} else {
$text = "@{$input} awesome! :)";
$matches = common_find_mentions_raw($text);
$this->assertCount(1, $matches);
$this->assertEquals($expected, Nickname::normalize($matches[0][0]));
static::assertCount(1, $matches);
static::assertSame($expected, Nickname::normalize($matches[0][0]));
}
}
public static function provider()
{
return array(
array('evan', 'evan'),
return [
['evan', 'evan'],
// Case and underscore variants
array('Evan', 'evan'),
array('EVAN', 'evan'),
array('ev_an', 'evan'),
array('E__V_an', 'evan'),
array('evan1', 'evan1'),
array('evan_1', 'evan1'),
array('0x20', '0x20'),
array('1234', '1234'), // should this be allowed though? :)
array('12__34', '1234'),
['Evan', 'evan'],
['EVAN', 'evan'],
['ev_an', 'evan'],
['E__V_an', 'evan'],
['evan1', 'evan1'],
['evan_1', 'evan1'],
['0x20', '0x20'],
['1234', '1234'], // should this be allowed though? :)
['12__34', '1234'],
// Some (currently) invalid chars...
array('^#@&^#@', false, 'NicknameInvalidException'), // all invalid :D
array('ev.an', false, 'NicknameInvalidException'),
array('ev/an', false, 'NicknameInvalidException'),
array('ev an', false, 'NicknameInvalidException'),
array('ev-an', false, 'NicknameInvalidException'),
['^#@&^#@', false, 'NicknameInvalidException'], // all invalid :D
['ev.an', false, 'NicknameInvalidException'],
['ev/an', false, 'NicknameInvalidException'],
['ev an', false, 'NicknameInvalidException'],
['ev-an', false, 'NicknameInvalidException'],
// Non-ASCII letters; currently not allowed, in future
// we'll add them at least with conversion to ASCII.
// Not much use until we have storage of display names,
// though.
array('évan', false, 'NicknameInvalidException'), // so far...
array('Évan', false, 'NicknameInvalidException'), // so far...
['évan', false, 'NicknameInvalidException'], // so far...
['Évan', false, 'NicknameInvalidException'], // so far...
// Length checks
array('', false, 'NicknameEmptyException'),
array('___', false, 'NicknameEmptyException'),
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // 64 chars
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'), // the _ is too long...
array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'), // 65 chars -- too long
);
['', false, 'NicknameEmptyException'],
['___', false, 'NicknameEmptyException'],
['eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'], // 64 chars
['eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'], // the _ is too long...
['eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'], // 65 chars -- too long
];
}
}

View File

@ -40,23 +40,25 @@ final class TagURITest extends TestCase
{
/**
* @dataProvider provider
*
* @param $format
* @param $args
* @param $uri
*/
public function testProduction($format, $args, $uri)
{
$minted = call_user_func_array(array('TagURI', 'mint'),
array_merge(array($format), $args));
$minted = call_user_func_array(
['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',
array(1, 3),
'tag:example.net,' . date('Y-m-d') . ':apps:statusnet:favorite:1:3'));
return [['favorite:%d:%d',
[1, 3],
'tag:example.net,' . date('Y-m-d') . ':apps:statusnet:favorite:1:3',]];
}
}

View File

@ -37,6 +37,7 @@ final class URLDetectionTest extends TestCase
{
/**
* @dataProvider provider
*
* @param $content
* @param $expected
*/
@ -45,14 +46,16 @@ final class URLDetectionTest extends TestCase
$rendered = common_render_text($content);
// hack!
$rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered);
$this->assertEquals($expected, $rendered);
static::assertSame($expected, $rendered);
}
/**
* @dataProvider linkifyProvider
*
* @param $content
* @param $expected
* @param $config
* @throws \ServerException
*/
public function testLinkifyProduction($content, $expected, $config)
{
@ -60,321 +63,321 @@ final class URLDetectionTest extends TestCase
// hack!
$rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered);
if (common_config('linkify', $config)) {
$this->assertEquals($expected, $rendered);
static::assertSame($expected, $rendered);
} else {
$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(
array('not a link :: no way',
'not a link :: no way'),
array('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'),
array('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>'),
array('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>'),
array('http://::1/test.php',
'<a href="http://::1/test.php" title="http://::1/test.php" rel="nofollow external">http://::1/test.php</a>'),
array('http://::1',
'<a href="http://::1/" title="http://::1/" rel="nofollow external">http://::1</a>'),
array('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>'),
array('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>'),
array('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>.'),
array('/var/lib/example.so',
'/var/lib/example.so'),
array('example',
'example'),
array('mailto:user@example.com',
'<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',
'<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',
'<a href="xmpp:user@example.com" title="xmpp:user@example.com" rel="nofollow external">xmpp:user@example.com</a>'),
array('#example',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example'))) . '" rel="tag">example</a></span>'),
array('#example.com',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example.com'))) . '" rel="tag">example.com</a></span>'),
array('#.net',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('.net'))) . '" rel="tag">.net</a></span>'),
array('http://example',
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example</a>'),
array('http://3xampl3',
'<a href="http://3xampl3/" title="http://3xampl3/" rel="nofollow external">http://3xampl3</a>'),
array('http://example/',
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example/</a>'),
array('http://example/path',
'<a href="http://example/path" title="http://example/path" rel="nofollow external">http://example/path</a>'),
array('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>'),
array('https://example.com',
'<a href="https://example.com/" title="https://example.com/" rel="nofollow external">https://example.com</a>'),
array('ftp://example.com',
'<a href="ftp://example.com/" title="ftp://example.com/" rel="nofollow external">ftp://example.com</a>'),
array('ftps://example.com',
'<a href="ftps://example.com/" title="ftps://example.com/" rel="nofollow external">ftps://example.com</a>'),
array('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>'),
array('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>'),
array('http://example.com:8080',
'<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',
'<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',
'<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/',
'<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',
'<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',
'<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',
'<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',
'<a href="http://example.com/path.php?foo=bar&amp;bar=foo" title="http://example.com/path.php?foo=bar&amp;bar=foo" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.php?foo=bar&amp;bar=foo</a>'),
array('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>.'),
array('http://müllärör.de',
'<a href="http://m&#xFC;ll&#xE4;r&#xF6;r.de/" title="http://m&#xFC;ll&#xE4;r&#xF6;r.de/" rel="nofollow external">http://müllärör.de</a>'),
array('http://ﺱﺲﺷ.com',
'<a href="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" title="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" rel="nofollow external">http://ﺱﺲﺷ.com</a>'),
array('http://сделаткартинки.com',
'<a href="http://&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x43A;&#x430;&#x440;&#x442;&#x438;&#x43D;&#x43A;&#x438;.com/" title="http://&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x43A;&#x430;&#x440;&#x442;&#x438;&#x43D;&#x43A;&#x438;.com/" rel="nofollow external">http://сделаткартинки.com</a>'),
array('http://tūdaliņ.lv',
'<a href="http://t&#x16B;dali&#x146;.lv/" title="http://t&#x16B;dali&#x146;.lv/" rel="nofollow external">http://tūdaliņ.lv</a>'),
array('http://brændendekærlighed.com',
'<a href="http://br&#xE6;ndendek&#xE6;rlighed.com/" title="http://br&#xE6;ndendek&#xE6;rlighed.com/" rel="nofollow external">http://brændendekærlighed.com</a>'),
array('http://あーるいん.com',
'<a href="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" title="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" rel="nofollow external">http://あーるいん.com</a>'),
array('http://예비교사.com',
'<a href="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" title="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" rel="nofollow external">http://예비교사.com</a>'),
array('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>.'),
array('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>?'),
array('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>!'),
array('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>,'),
array('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>;'),
array('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>:'),
array('\'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>\''),
array('"http://example.com"',
'&quot;<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>&quot;'),
array('"http://example.com/"',
'&quot;<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>&quot;'),
array('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>'),
array('(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>)'),
array('[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>]'),
array('<http://example.com>',
'&lt;<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>&gt;'),
array('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'),
array('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'),
array('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)'),
return [
['not a link :: no way',
'not a link :: no way',],
['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',],
['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>',],
['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>',],
['http://::1/test.php',
'<a href="http://::1/test.php" title="http://::1/test.php" rel="nofollow external">http://::1/test.php</a>',],
['http://::1',
'<a href="http://::1/" title="http://::1/" rel="nofollow external">http://::1</a>',],
['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>',],
['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>',],
['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>.',],
['/var/lib/example.so',
'/var/lib/example.so',],
['example',
'example',],
['mailto:user@example.com',
'<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">mailto:user@example.com</a>',],
['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>',],
['xmpp:user@example.com',
'<a href="xmpp:user@example.com" title="xmpp:user@example.com" rel="nofollow external">xmpp:user@example.com</a>',],
['#example',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('example')]) . '" rel="tag">example</a></span>',],
['#example.com',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('example.com')]) . '" rel="tag">example.com</a></span>',],
['#.net',
'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('.net')]) . '" rel="tag">.net</a></span>',],
['http://example',
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example</a>',],
['http://3xampl3',
'<a href="http://3xampl3/" title="http://3xampl3/" rel="nofollow external">http://3xampl3</a>',],
['http://example/',
'<a href="http://example/" title="http://example/" rel="nofollow external">http://example/</a>',],
['http://example/path',
'<a href="http://example/path" title="http://example/path" rel="nofollow external">http://example/path</a>',],
['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>',],
['https://example.com',
'<a href="https://example.com/" title="https://example.com/" rel="nofollow external">https://example.com</a>',],
['ftp://example.com',
'<a href="ftp://example.com/" title="ftp://example.com/" rel="nofollow external">ftp://example.com</a>',],
['ftps://example.com',
'<a href="ftps://example.com/" title="ftps://example.com/" rel="nofollow external">ftps://example.com</a>',],
['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>',],
['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>',],
['http://example.com:8080',
'<a href="http://example.com:8080/" title="http://example.com:8080/" rel="nofollow external">http://example.com:8080</a>',],
['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>',],
['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>',],
['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>',],
['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>',],
['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>',],
['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>',],
['http://example.com/path.php?foo=bar&bar=foo',
'<a href="http://example.com/path.php?foo=bar&amp;bar=foo" title="http://example.com/path.php?foo=bar&amp;bar=foo" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/path.php?foo=bar&amp;bar=foo</a>',],
['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>.',],
['http://müllärör.de',
'<a href="http://m&#xFC;ll&#xE4;r&#xF6;r.de/" title="http://m&#xFC;ll&#xE4;r&#xF6;r.de/" rel="nofollow external">http://müllärör.de</a>',],
['http://ﺱﺲﺷ.com',
'<a href="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" title="http://&#xFEB1;&#xFEB2;&#xFEB7;.com/" rel="nofollow external">http://ﺱﺲﺷ.com</a>',],
['http://сделаткартинки.com',
'<a href="http://&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x43A;&#x430;&#x440;&#x442;&#x438;&#x43D;&#x43A;&#x438;.com/" title="http://&#x441;&#x434;&#x435;&#x43B;&#x430;&#x442;&#x43A;&#x430;&#x440;&#x442;&#x438;&#x43D;&#x43A;&#x438;.com/" rel="nofollow external">http://сделаткартинки.com</a>',],
['http://tūdaliņ.lv',
'<a href="http://t&#x16B;dali&#x146;.lv/" title="http://t&#x16B;dali&#x146;.lv/" rel="nofollow external">http://tūdaliņ.lv</a>',],
['http://brændendekærlighed.com',
'<a href="http://br&#xE6;ndendek&#xE6;rlighed.com/" title="http://br&#xE6;ndendek&#xE6;rlighed.com/" rel="nofollow external">http://brændendekærlighed.com</a>',],
['http://あーるいん.com',
'<a href="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" title="http://&#x3042;&#x30FC;&#x308B;&#x3044;&#x3093;.com/" rel="nofollow external">http://あーるいん.com</a>',],
['http://예비교사.com',
'<a href="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" title="http://&#xC608;&#xBE44;&#xAD50;&#xC0AC;.com/" rel="nofollow external">http://예비교사.com</a>',],
['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>.',],
['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>?',],
['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>!',],
['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>,',],
['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>;',],
['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>:',],
['\'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>\'',],
['"http://example.com"',
'&quot;<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>&quot;',],
['"http://example.com/"',
'&quot;<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com/</a>&quot;',],
['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>',],
['(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>)',],
['[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>]',],
['<http://example.com>',
'&lt;<a href="http://example.com/" title="http://example.com/" rel="nofollow external noreferrer" class="attachment" id="attachment-XXX">http://example.com</a>&gt;',],
['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',],
['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',],
['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)',],
//Not a valid url - urls cannot contain unencoded square brackets
array('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]'),
array('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?'),
array('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))?'),
array('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)?'),
array('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).)?'),
['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]',],
['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?',],
['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. 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. 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).)?',],
//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. <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. <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. <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. <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. <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'),
array('file.html',
'file.html'),
array('file.php',
'file.php'),
['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)?',],
['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. 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. 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. 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))))?',],
['file.ext',
'file.ext',],
['file.html',
'file.html',],
['file.php',
'file.php',],
// scheme-less HTTP URLs with @ in the path: http://status.net/open-source/issues/2248
array('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>'),
);
['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>',],
];
}
static public function linkifyProvider()
public static function linkifyProvider()
{
return array(
return [
//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>',
'bare_ipv4'),
array('127.0.0.1:99',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/Name:test.php',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/~test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/+test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/$test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/\'test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/"test',
'bare_ipv4',],
['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>&quot;test',
'bare_ipv4'),
array('127.0.0.1/test"test',
'bare_ipv4',],
['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>&quot;test',
'bare_ipv4'),
array('127.0.0.1/-test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/_test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/!test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/*test',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('127.0.0.1/test%20stuff',
'bare_ipv4',],
['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>',
'bare_ipv4'),
array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
'bare_ipv4',],
['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>',
'bare_ipv6'),
array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
'bare_ipv6',],
['[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>',
'bare_ipv6'),
array('2001:4978:1b5:0:21d:e0ff:fe66:59ab',
'bare_ipv6',],
['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>',
'bare_ipv6'),
array('example.com',
'bare_ipv6',],
['example.com',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
'bare_domains'),
array('flickr.com/photos/34807140@N05/3838905434',
'bare_domains',],
['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>',
'bare_domains'),
array('What about parens (e.g. example.com/path/foo/(bar))?',
'bare_domains',],
['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>)?',
'bare_domains'),
array('What about parens (e.g. example.com/path/foo/(bar)?',
'bare_domains',],
['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>?',
'bare_domains'),
array('What about parens (e.g. example.com/path/foo/(bar).)?',
'bare_domains',],
['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>.?',
'bare_domains'),
array('What about parens (e.g. example.com/path/(foo,bar)?',
'bare_domains',],
['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>?',
'bare_domains'),
array('example.com',
'bare_domains',],
['example.com',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
'bare_domains'),
array('example.org',
'bare_domains',],
['example.org',
'<a href="http://example.org/" title="http://example.org/" rel="nofollow external">example.org</a>',
'bare_domains'),
array('example.co.uk',
'bare_domains',],
['example.co.uk',
'<a href="http://example.co.uk/" title="http://example.co.uk/" rel="nofollow external">example.co.uk</a>',
'bare_domains'),
array('www.example.co.uk',
'bare_domains',],
['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>',
'bare_domains'),
array('farm1.images.example.co.uk',
'bare_domains',],
['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>',
'bare_domains'),
array('example.museum',
'bare_domains',],
['example.museum',
'<a href="http://example.museum/" title="http://example.museum/" rel="nofollow external">example.museum</a>',
'bare_domains'),
array('example.travel',
'bare_domains',],
['example.travel',
'<a href="http://example.travel/" title="http://example.travel/" rel="nofollow external">example.travel</a>',
'bare_domains'),
array('example.com.',
'bare_domains',],
['example.com.',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>.',
'bare_domains'),
array('example.com?',
'bare_domains',],
['example.com?',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>?',
'bare_domains'),
array('example.com!',
'bare_domains',],
['example.com!',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>!',
'bare_domains'),
array('example.com,',
'bare_domains',],
['example.com,',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>,',
'bare_domains'),
array('example.com;',
'bare_domains',],
['example.com;',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>;',
'bare_domains'),
array('example.com:',
'bare_domains',],
['example.com:',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>:',
'bare_domains'),
array('\'example.com\'',
'bare_domains',],
['\'example.com\'',
'\'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>\'',
'bare_domains'),
array('"example.com"',
'bare_domains',],
['"example.com"',
'&quot;<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>&quot;',
'bare_domains'),
array('example.com',
'bare_domains',],
['example.com',
'<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>',
'bare_domains'),
array('(example.com)',
'bare_domains',],
['(example.com)',
'(<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>)',
'bare_domains'),
array('[example.com]',
'bare_domains',],
['[example.com]',
'[<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>]',
'bare_domains'),
array('<example.com>',
'bare_domains',],
['<example.com>',
'&lt;<a href="http://example.com/" title="http://example.com/" rel="nofollow external">example.com</a>&gt;',
'bare_domains'),
array('Hey, check out my cool site example.com okay?',
'bare_domains',],
['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?',
'bare_domains'),
array('Hey, check out my cool site example.com.I made it.',
'bare_domains',],
['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.',
'bare_domains'),
array('Hey, check out my cool site example.com.Funny thing...',
'bare_domains',],
['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...',
'bare_domains'),
array('Hey, check out my cool site example.com.You will love it.',
'bare_domains',],
['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.',
'bare_domains'),
array('example.com:8080/test.php',
'bare_domains',],
['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>',
'bare_domains'),
array('user_name+other@example.com',
'bare_domains',],
['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>',
'bare_domains'),
array('user@example.com',
'bare_domains',],
['user@example.com',
'<a href="mailto:user@example.com" title="mailto:user@example.com" rel="nofollow external">user@example.com</a>',
'bare_domains'),
);
'bare_domains',],
];
}
}

View File

@ -39,23 +39,24 @@ final class UUIDTest extends TestCase
public function testGenerate()
{
$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}$/',
$result);
static::assertRegExp(
'/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
$result
);
// Check version number
$this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
$this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
static::assertSame(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
static::assertSame(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
}
public function testUnique()
{
$reps = 100;
$ids = array();
$ids = [];
for ($i = 0; $i < $reps; $i++) {
for ($i = 0; $i < $reps; ++$i) {
$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');
}
}

View File

@ -36,71 +36,69 @@ use PHPUnit\Framework\TestCase;
require_once INSTALLDIR . '/lib/util/common.php';
final class UserFeedParseTests extends TestCase
final class UserFeedParseTest extends TestCase
{
public function testFeed1()
{
global $_testfeed1;
$dom = new DOMDocument();
$dom->loadXML($_testfeed1);
$this->assertFalse(empty($dom));
static::assertFalse(empty($dom));
$entries = $dom->getElementsByTagName('entry');
$entry1 = $entries->item(0);
$this->assertFalse(empty($entry1));
static::assertFalse(empty($entry1));
$feedEl = $dom->getElementsByTagName('feed')->item(0);
$this->assertFalse(empty($feedEl));
static::assertFalse(empty($feedEl));
// Test actor (from activity:subject)
$act1 = new Activity($entry1, $feedEl);
$this->assertFalse(empty($act1));
$this->assertFalse(empty($act1->actor));
$this->assertEquals($act1->actor->type, ActivityObject::PERSON);
$this->assertEquals($act1->actor->title, 'Zach Copley');
$this->assertEquals($act1->actor->id, 'http://localhost/statusnet/user/1');
$this->assertEquals($act1->actor->link, 'http://localhost/statusnet/zach');
static::assertFalse(empty($act1));
static::assertFalse(empty($act1->actor));
static::assertSame($act1->actor->type, ActivityObject::PERSON);
static::assertSame($act1->actor->title, 'Zach Copley');
static::assertSame($act1->actor->id, 'http://localhost/statusnet/user/1');
static::assertSame($act1->actor->link, 'http://localhost/statusnet/zach');
$avatars = $act1->actor->avatarLinks;
$this->assertEquals(
static::assertSame(
$avatars[0]->url,
'http://localhost/statusnet/theme/default/default-avatar-profile.png'
);
$this->assertEquals(
static::assertSame(
$avatars[1]->url,
'http://localhost/statusnet/theme/default/default-avatar-stream.png'
);
$this->assertEquals(
static::assertSame(
$avatars[2]->url,
'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;
$this->assertEquals($poco->preferredUsername, 'zach');
$this->assertEquals($poco->address->formatted, 'El Cerrito, CA');
$this->assertEquals($poco->urls[0]->type, 'homepage');
$this->assertEquals($poco->urls[0]->value, 'http://zach.copley.name');
$this->assertEquals($poco->urls[0]->primary, true);
$this->assertEquals($poco->note, 'Zach Hack Attack');
static::assertSame($poco->preferredUsername, 'zach');
static::assertSame($poco->address->formatted, 'El Cerrito, CA');
static::assertSame($poco->urls[0]->type, 'homepage');
static::assertSame($poco->urls[0]->value, 'http://zach.copley.name');
static::assertSame($poco->urls[0]->primary, true);
static::assertSame($poco->note, 'Zach Hack Attack');
// test the post
//var_export($act1);
$this->assertEquals($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
$this->assertEquals($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]->type, 'http://activitystrea.ms/schema/1.0/note');
static::assertSame($act1->objects[0]->title, 'And now for something completely insane...');
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

View File

@ -37,9 +37,9 @@ require_once INSTALLDIR . '/lib/util/common.php';
final class UserRightsTest extends TestCase
{
protected $user = null;
protected $user;
function setUp(): void
protected function setUp(): void
{
$user = User::getKV('nickname', 'userrightstestuser');
if ($user) {
@ -48,13 +48,13 @@ final class UserRightsTest extends TestCase
$user->delete();
$profile->delete();
}
$this->user = User::register(array('nickname' => 'userrightstestuser'));
$this->user = User::register(['nickname' => 'userrightstestuser']);
if (!$this->user) {
throw new Exception("Couldn't register userrightstestuser");
}
}
function tearDown(): void
protected function tearDown(): void
{
if ($this->user) {
$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'),
array('moderator'));
return [['admin'],
['moderator'],];
}
/**
* @dataProvider standardRoles
*
* @param $role
*/
function testUngrantedRole($role)
public function testUngrantedRole($role)
{
$this->assertFalse($this->user->hasRole($role));
static::assertFalse($this->user->hasRole($role));
}
/**
* @dataProvider standardRoles
*
* @param $role
*/
function testGrantedRole($role)
public function testGrantedRole($role)
{
$this->user->grantRole($role);
$this->assertTrue($this->user->hasRole($role));
static::assertTrue($this->user->hasRole($role));
}
}

View File

@ -29,7 +29,6 @@ if (!defined('STATUSNET')) { // Compatibility
define('STATUSNET', true);
}
use GNUsocial;
use PHPUnit\Framework\TestCase;
use PluginList;
use XmppPlugin;
@ -39,15 +38,16 @@ require_once INSTALLDIR . '/plugins/Xmpp/XmppPlugin.php';
final class XmppValidateTest extends TestCase
{
public function setUp(): void
protected function setUp(): void
{
if (!PluginList::isPluginActive('Xmpp')) {
$this->markTestSkipped('XmppPlugin is not enabled.');
static::markTestSkipped('XmppPlugin is not enabled.');
}
}
/**
* @dataProvider validationCases
*
* @param $jid
* @param $validFull
* @param $validBase
@ -55,24 +55,26 @@ final class XmppValidateTest extends TestCase
public function testValidate($jid, $validFull, $validBase)
{
$xmpp = new TestXmppPlugin();
$this->assertEquals($validFull || $validBase, $xmpp->validate($jid));
$this->assertEquals($validFull, $xmpp->validateFullJid($jid), "validating as full or base JID");
$this->assertEquals($validBase, $xmpp->validateBaseJid($jid), "validating as base JID only");
static::assertSame($validFull || $validBase, $xmpp->validate($jid));
static::assertSame($validFull, $xmpp->validateFullJid($jid), 'validating as full or base JID');
static::assertSame($validBase, $xmpp->validateBaseJid($jid), 'validating as base JID only');
}
/**
* @dataProvider normalizationCases
*
* @param $jid
* @param $expected
*/
public function testNormalize($jid, $expected)
{
$xmpp = new XmppPlugin();
$this->assertEquals($expected, $xmpp->normalize($jid));
static::assertSame($expected, $xmpp->normalize($jid));
}
/**
* @dataProvider domainCheckCases()
*
* @param $domain
* @param $expected
* @param $note
@ -80,69 +82,69 @@ final class XmppValidateTest extends TestCase
public function testDomainCheck($domain, $expected, $note)
{
$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);
$long1024 = "long1024" . str_repeat('x', 1024 - 8);
return array(
$long1023 = 'long1023' . str_repeat('x', 1023 - 8);
$long1024 = 'long1024' . str_repeat('x', 1024 - 8);
return [
// Our own test cases for standard things & those mentioned in bug reports
// (jid, valid_full, valid_base)
array('user@example.com', true, true),
array('user@example.com/resource', true, false),
array('user with spaces@example.com', false, false), // not kosher
['user@example.com', true, true],
['user@example.com/resource', true, false],
['user with spaces@example.com', false, false], // not kosher
array('user.@example.com', true, true), // "common in intranets"
array('example.com', true, true),
array('example.com/resource', true, false),
array('jabchat', true, true),
['user.@example.com', true, true], // "common in intranets"
['example.com', true, true],
['example.com/resource', true, false],
['jabchat', true, true],
array("$long1023@$long1023/$long1023", true, false), // max 1023 "bytes" per portion per spec. Do they really mean bytes though?
array("$long1024@$long1023/$long1023", false, false),
array("$long1023@$long1024/$long1023", false, false),
array("$long1023@$long1023/$long1024", false, false),
["{$long1023}@{$long1023}/{$long1023}", true, false], // max 1023 "bytes" per portion per spec. Do they really mean bytes though?
["{$long1024}@{$long1023}/{$long1023}", false, false],
["{$long1023}@{$long1024}/{$long1023}", false, false],
["{$long1023}@{$long1023}/{$long1024}", false, false],
// Borrowed from test_jabber_jutil.c in libpurple
array("gmail.com", true, true),
array("gmail.com/Test", true, false),
array("gmail.com/Test@", true, false),
array("gmail.com/@", true, false),
array("gmail.com/Test@alkjaweflkj", true, false),
array("mark.doliner@gmail.com", true, true),
array("mark.doliner@gmail.com/Test12345", true, false),
array("mark.doliner@gmail.com/Test@12345", true, false),
array("mark.doliner@gmail.com/Te/st@12@//345", true, false),
array("わいど@conference.jabber.org", true, true),
array("まりるーむ@conference.jabber.org", true, true),
array("mark.doliner@gmail.com/まりるーむ", true, false),
array("mark.doliner@gmail/stuff.org", true, false),
array("stuart@nödåtXäYZ.se", true, true),
array("stuart@nödåtXäYZ.se/まりるーむ", true, false),
array("mark.doliner@わいど.org", true, true),
array("nick@まつ.おおかみ.net", true, true),
array("paul@10.0.42.230/s", true, false),
array("paul@[::1]", true, true), /* IPv6 */
array("paul@[2001:470:1f05:d58::2]", true, true),
array("paul@[2001:470:1f05:d58::2]/foo", true, false),
array("pa=ul@10.0.42.230", true, true),
array("pa,ul@10.0.42.230", true, true),
['gmail.com', true, true],
['gmail.com/Test', true, false],
['gmail.com/Test@', true, false],
['gmail.com/@', true, false],
['gmail.com/Test@alkjaweflkj', true, false],
['mark.doliner@gmail.com', true, true],
['mark.doliner@gmail.com/Test12345', true, false],
['mark.doliner@gmail.com/Test@12345', true, false],
['mark.doliner@gmail.com/Te/st@12@//345', true, false],
['わいど@conference.jabber.org', true, true],
['まりるーむ@conference.jabber.org', true, true],
['mark.doliner@gmail.com/まりるーむ', true, false],
['mark.doliner@gmail/stuff.org', true, false],
['stuart@nödåtXäYZ.se', true, true],
['stuart@nödåtXäYZ.se/まりるーむ', true, false],
['mark.doliner@わいど.org', true, true],
['nick@まつ.おおかみ.net', true, true],
['paul@10.0.42.230/s', true, false],
['paul@[::1]', true, true], // IPv6
['paul@[2001:470:1f05:d58::2]', true, true],
['paul@[2001:470:1f05:d58::2]/foo', true, false],
['pa=ul@10.0.42.230', true, true],
['pa,ul@10.0.42.230', true, true],
array("@gmail.com", false, false),
array("@@gmail.com", false, false),
array("mark.doliner@@gmail.com/Test12345", false, false),
array("mark@doliner@gmail.com/Test12345", false, false),
array("@gmail.com/Test@12345", false, false),
array("/Test@12345", false, false),
array("mark.doliner@", false, false),
array("mark.doliner/", false, false),
array("mark.doliner@gmail_stuff.org", false, false),
array("mark.doliner@gmail[stuff.org", false, false),
array("mark.doliner@gmail\\stuff.org", false, false),
array("paul@[::1]124", false, false),
array("paul@2[::1]124/as", false, false),
array("paul@まつ.おおかみ/\x01", false, false),
['@gmail.com', false, false],
['@@gmail.com', false, false],
['mark.doliner@@gmail.com/Test12345', false, false],
['mark@doliner@gmail.com/Test12345', false, false],
['@gmail.com/Test@12345', false, false],
['/Test@12345', false, false],
['mark.doliner@', false, false],
['mark.doliner/', false, false],
['mark.doliner@gmail_stuff.org', false, false],
['mark.doliner@gmail[stuff.org', false, false],
['mark.doliner@gmail\\stuff.org', false, false],
['paul@[::1]124', false, false],
['paul@2[::1]124/as', false, false],
["paul@まつ.おおかみ/\x01", false, false],
/*
* RFC 3454 Section 6 reads, in part,
@ -153,34 +155,32 @@ final class XmppValidateTest extends TestCase
// Leaving this one commented out for the moment
// as it shouldn't hurt anything for our purposes.
//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
array('PaUL@DaRkRain42.org', 'paul@darkrain42.org'),
array('PaUL@DaRkRain42.org/', 'paul@darkrain42.org'),
array('PaUL@DaRkRain42.org/resource', 'paul@darkrain42.org'),
['PaUL@DaRkRain42.org', 'paul@darkrain42.org'],
['PaUL@DaRkRain42.org/', 'paul@darkrain42.org'],
['PaUL@DaRkRain42.org/resource', 'paul@darkrain42.org'],
// Also adapted from libpurple tests...
array('Ф@darkrain42.org', 'ф@darkrain42.org'),
array('paul@Өarkrain.org', 'paul@өarkrain.org'),
);
['Ф@darkrain42.org', 'ф@darkrain42.org'],
['paul@Өarkrain.org', 'paul@өarkrain.org'],
];
}
static public function domainCheckCases()
public static function domainCheckCases()
{
return array(
array('gmail.com', true, 'known SRV record'),
array('jabber.org', true, 'known SRV record'),
array('status.net', true, 'known SRV record'),
array('status.leuksman.com', true, 'known no SRV record but valid domain'),
);
return [
['gmail.com', true, 'known SRV record'],
['jabber.org', true, 'known SRV record'],
['status.net', true, 'known SRV record'],
['status.leuksman.com', true, 'known no SRV record but valid domain'],
];
}
}
class TestXmppPlugin extends XmppPlugin

View File

@ -39,87 +39,89 @@ require_once INSTALLDIR . '/lib/util/common.php';
final class MediaFileTest extends TestCase
{
public function setup(): void
protected function setup(): void
{
$this->old_attachments_supported = common_config('attachments', 'supported');
$GLOBALS['config']['attachments']['supported'] = true;
}
public function tearDown(): void
protected function tearDown(): void
{
$GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported;
}
/**
* @dataProvider fileTypeCases
*
* @param $filename
* @param $expectedType
*
* @throws ClientException
* @throws ServerException
*/
public function testMimeType($filename, $expectedType)
{
if (!file_exists($filename)) {
throw new Exception("Test file $filename missing");
throw new Exception("Test file {$filename} missing");
}
$type = MediaFile::getUploadedMimeType($filename, basename($filename));
$this->assertEquals($expectedType, $type);
static::assertSame($expectedType, $type);
}
/**
* @dataProvider fileTypeCases
*
* @param $filename
* @param $expectedType
*
* @throws ClientException
* @throws ServerException
*/
public function testUploadedMimeType($filename, $expectedType)
{
if (!file_exists($filename)) {
throw new Exception("WTF? $filename test file missing");
throw new Exception("WTF? {$filename} test file missing");
}
$tmp = tmpfile();
fwrite($tmp, file_get_contents($filename));
$tmp_metadata = stream_get_meta_data($tmp);
$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__);
$dir = "$base/sample-uploads";
$files = array(
"image.png" => "image/png",
"image.gif" => "image/gif",
"image.jpg" => "image/jpeg",
"image.jpeg" => "image/jpeg",
"office.pdf" => "application/pdf",
"wordproc.odt" => "application/vnd.oasis.opendocument.text",
"wordproc.ott" => "application/vnd.oasis.opendocument.text-template",
"wordproc.doc" => "application/msword",
"wordproc.docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"wordproc.rtf" => "text/rtf",
"spreadsheet.ods" => "application/vnd.oasis.opendocument.spreadsheet",
"spreadsheet.ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
"spreadsheet.xls" => "application/vnd.ms-excel",
"spreadsheet.xlt" => "application/vnd.ms-excel",
"spreadsheet.xlsx" =>"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"presentation.odp" => "application/vnd.oasis.opendocument.presentation",
"presentation.otp" => "application/vnd.oasis.opendocument.presentation-template",
"presentation.ppt" => "application/vnd.ms-powerpoint",
"presentation.pptx" => 'application/zip', //"application/vnd.openxmlformats-officedocument.presentationml.presentation",
);
$base = __DIR__;
$dir = "{$base}/sample-uploads";
$files = [
'image.png' => 'image/png',
'image.gif' => 'image/gif',
'image.jpg' => 'image/jpeg',
'image.jpeg' => 'image/jpeg',
'office.pdf' => 'application/pdf',
'wordproc.odt' => 'application/vnd.oasis.opendocument.text',
'wordproc.ott' => 'application/vnd.oasis.opendocument.text-template',
'wordproc.doc' => 'application/msword',
'wordproc.docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'wordproc.rtf' => 'text/rtf',
'spreadsheet.ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'spreadsheet.ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'spreadsheet.xls' => 'application/vnd.ms-excel',
'spreadsheet.xlt' => 'application/vnd.ms-excel',
'spreadsheet.xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'presentation.odp' => 'application/vnd.oasis.opendocument.presentation',
'presentation.otp' => 'application/vnd.oasis.opendocument.presentation-template',
'presentation.ppt' => 'application/vnd.ms-powerpoint',
'presentation.pptx' => 'application/zip', //"application/vnd.openxmlformats-officedocument.presentationml.presentation",
];
$dataset = array();
$dataset = [];
foreach ($files as $file => $type) {
$dataset[] = array("$dir/$file", $type);
$dataset[] = ["{$dir}/{$file}", $type];
}
return $dataset;
}
}

View File

@ -23,7 +23,7 @@ if (!defined('INSTALLDIR')) {
}
$shortoptions = 'n:p:';
$longoptions = array('nickname=', 'password=', 'dry-run');
$longoptions = ['nickname=', 'password=', 'dry-run'];
$helptext = <<<END_OF_HELP
USAGE: atompub_test.php [options]
@ -39,7 +39,7 @@ Options:
END_OF_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/scripts/commandline.inc';
$user = get_option_value('n', 'nickname');
$pass = get_option_value('p', 'password');
@ -53,15 +53,15 @@ if (!$pass) {
// discover the feed...
// @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);
// confirm the feed has edit links ..... ?
echo "Posting an empty message (should fail)... ";
echo 'Posting an empty message (should fail)... ';
try {
$noticeUrl = $collection->post('');
die("FAILED, succeeded!\n");
@ -69,7 +69,7 @@ try {
echo "ok\n";
}
echo "Posting an invalid XML message (should fail)... ";
echo 'Posting an invalid XML message (should fail)... ';
try {
$noticeUrl = $collection->post('<feed<entry>barf</yomomma>');
die("FAILED, succeeded!\n");
@ -77,7 +77,7 @@ try {
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 {
$noticeUrl = $collection->post('<feed xmlns="http://notatom.com"><id>arf</id><entry><id>barf</id></entry></feed>');
die("FAILED, succeeded!\n");
@ -89,37 +89,37 @@ try {
$rand = mt_rand(0, 99999);
$atom = <<<END_ATOM
<entry xmlns="http://www.w3.org/2005/Atom">
<title>This is an AtomPub test post title ($rand)</title>
<content>This is an AtomPub test post content ($rand)</content>
<title>This is an AtomPub test post title ({$rand})</title>
<content>This is an AtomPub test post content ({$rand})</content>
</entry>
END_ATOM;
echo "Posting a new message... ";
echo 'Posting a new message... ';
$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);
$body = $notice->get();
AtomPubClient::validateAtomEntry($body);
echo "ok\n";
echo "Getting the notice ID URI... ";
echo 'Getting the notice ID URI... ';
$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);
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 "Refetching the collection... ";
echo 'Refetching the collection... ';
$feed = $collection->get();
echo "ok\n";
echo "Confirming new entry is in the feed... ";
echo 'Confirming new entry is in the feed... ';
$entry = AtomPubClient::getEntryInFeed($feed, $noticeUri);
if (!$entry) {
die("missing!\n");
@ -127,7 +127,7 @@ if (!$entry) {
// edit URL should match
echo "ok\n";
echo "Editing notice (should fail)... ";
echo 'Editing notice (should fail)... ';
try {
$notice->put($target, $atom2);
die("ERROR: editing a notice should have failed.\n");
@ -135,7 +135,7 @@ try {
echo "ok (failed as expected)\n";
}
echo "Deleting notice... ";
echo 'Deleting notice... ';
$notice->delete();
echo "ok\n";
@ -148,11 +148,11 @@ try {
echo "ok\n";
}
echo "Refetching the collection.. ";
echo 'Refetching the collection.. ';
$feed = $collection->get();
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);
if ($entry) {
die("still there!\n");
@ -167,9 +167,6 @@ echo "ok\n";
// group memberships too
// make sure we can't post to someone else's feed!
// make sure we can't delete someone else's messages
// make sure we can't create/delete someone else's subscriptions

View File

@ -18,17 +18,17 @@
* 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 . '/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
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])) {
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);
}
}
@ -36,7 +36,7 @@ foreach(array('consumer_key', 'consumer_secret', 'apiroot', 'request_token_url')
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
$endpoint = $ini['apiroot'] . $ini['request_token_url'];
$parsed = parse_url($endpoint);
$params = array();
$params = [];
parse_str($parsed['query'], $params);
$params['oauth_callback'] = 'oob'; // out-of-band
@ -47,22 +47,22 @@ try {
$req = OAuthRequest::from_consumer_and_token(
$consumer,
null,
"POST",
'POST',
$endpoint,
$params
);
$req->sign_request($hmac_method, $consumer, NULL);
$req->sign_request($hmac_method, $consumer, null);
$r = httpRequest($endpoint, $req->to_postdata());
} catch (Exception $e) {
// oh noez
print $e->getMessage();
print "\nOAuth Request:\n";
echo $e->getMessage();
echo "\nOAuth Request:\n";
var_dump($req);
exit(1);
}
$body = $r->getBody();
$tokenStuff = array();
$tokenStuff = [];
parse_str($body, $tokenStuff);
@ -72,32 +72,31 @@ $confirmed = $tokenStuff['oauth_callback_confirmed'];
if (empty($tokenStuff['oauth_token'])
|| empty($tokenStuff['oauth_token_secret'])
|| empty($confirmed)
|| $confirmed != 'true')
{
print "Error! HTTP response body: $body\n";
|| $confirmed != 'true') {
echo "Error! HTTP response body: {$body}\n";
exit(1);
}
$authurl = $ini['apiroot'] . $ini['authorize_url'] . '?oauth_token=' . $tok;
print "Request Token\n";
print ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
print ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
print "Authorize URL\n $authurl\n\n";
print "Now paste the Authorize URL into your browser and authorize your temporary credentials.\n";
echo "Request Token\n";
echo ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
echo ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
echo "Authorize URL\n {$authurl}\n\n";
echo "Now paste the Authorize URL into your browser and authorize your temporary credentials.\n";
function httpRequest($endpoint, $poststr)
{
$request = HTTPClient::start();
$request->setConfig(
array(
[
'follow_redirects' => true,
'connect_timeout' => 120,
'timeout' => 120,
'ssl_verify_peer' => false,
'ssl_verify_host' => false
)
'ssl_verify_host' => false,
]
);
// Turn signed request query string back into an array

View File

@ -18,16 +18,16 @@
* 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';
$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
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])) {
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);
}
}
@ -37,7 +37,7 @@ $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
$endpoint = $ini['apiroot'] . $ini['access_token_url'];
$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
fetch_token_creds.php [options]
@ -69,17 +69,17 @@ if (have_option('v', 'oauth_verifier')) {
}
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);
}
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);
}
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);
}
@ -92,11 +92,10 @@ $params['oauth_verifier'] = $verifier; // 1.0a
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
try {
$oauthReq = OAuthRequest::from_consumer_and_token(
$consumer,
$rtok,
"POST",
'POST',
$endpoint,
$params
);
@ -105,39 +104,38 @@ try {
$httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
$body = $httpReq->getBody();
} catch (Exception $e) {
// oh noez
print $e->getMessage();
print "\nOAuth Request:\n";
echo $e->getMessage();
echo "\nOAuth Request:\n";
var_dump($oauthReq);
exit(1);
}
$tokenStuff = array();
$tokenStuff = [];
parse_str($body, $tokenStuff);
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);
}
print "Access Token\n";
print ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
print ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
echo "Access Token\n";
echo ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n";
echo ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n";
function httpRequest($endpoint, $poststr)
{
$request = HTTPClient::start();
$request->setConfig(
array(
[
'follow_redirects' => true,
'connect_timeout' => 120,
'timeout' => 120,
'ssl_verify_peer' => false,
'ssl_verify_host' => false
)
'ssl_verify_host' => false,
]
);
parse_str($poststr, $postdata);

View File

@ -16,14 +16,14 @@
*
* 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/>.
**/
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
define('INSTALLDIR', realpath(__DIR__ . '/../..'));
require_once INSTALLDIR . '/extlib/OAuth.php';
$shortoptions = 't:s:u:';
$longoptions = array('oauth_token=', 'oauth_token_secret=', 'update=');
$longoptions = ['oauth_token=', 'oauth_token_secret=', 'update='];
$helptext = <<<END_OF_VERIFY_HELP
oauth_post_notice.php [options]
@ -55,21 +55,21 @@ if (have_option('u', 'update')) {
}
if (empty($token)) {
print "Please specify an access token.\n";
echo "Please specify an access token.\n";
exit(1);
}
if (empty($token_secret)) {
print "Please specify an access token secret.\n";
echo "Please specify an access token secret.\n";
exit(1);
}
if (empty($update)) {
print "You forgot to update your status!\n";
echo "You forgot to update your status!\n";
exit(1);
}
$ini = parse_ini_file("oauth.ini");
$ini = parse_ini_file('oauth.ini');
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
$endpoint = $ini['apiroot'] . '/statuses/update.xml';
@ -83,7 +83,6 @@ $params['status'] = $update;
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
try {
$oauthReq = OAuthRequest::from_consumer_and_token(
$consumer,
$atok,
@ -96,10 +95,9 @@ try {
$httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
print $httpReq->getBody();
echo $httpReq->getBody();
} catch (Exception $e) {
print "Error! . $e->getMessage() . 'HTTP reponse body: " . $httpReq->getBody();
echo "Error! . {$e->getMessage}() . 'HTTP reponse body: " . $httpReq->getBody();
exit(1);
}
@ -108,13 +106,13 @@ function httpRequest($endpoint, $poststr)
$request = HTTPClient::start();
$request->setConfig(
array(
[
'follow_redirects' => true,
'connect_timeout' => 120,
'timeout' => 120,
'ssl_verify_peer' => false,
'ssl_verify_host' => false
)
'ssl_verify_host' => false,
]
);
// Turn signed request query string back into an array

View File

@ -18,12 +18,12 @@
* 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';
$shortoptions = 't:s:';
$longoptions = array('oauth_token=', 'oauth_token_secret=');
$longoptions = ['oauth_token=', 'oauth_token_secret='];
$helptext = <<<END_OF_VERIFY_HELP
oauth_verify_creds.php [options]
@ -48,16 +48,16 @@ if (have_option('s', 'oauth_token_secret')) {
}
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);
}
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);
}
$ini = parse_ini_file("oauth.ini");
$ini = parse_ini_file('oauth.ini');
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
$endpoint = $ini['apiroot'] . '/account/verify_credentials.xml';
@ -67,13 +67,12 @@ $parsed = parse_url($endpoint);
parse_str($parsed['query'], $params);
try {
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
$oauthReq = OAuthRequest::from_consumer_and_token(
$consumer,
$atok,
"GET",
'GET',
$endpoint,
$params
);
@ -81,26 +80,25 @@ try {
$oauthReq->sign_request($hmac_method, $consumer, $atok);
$httpReq = httpRequest($oauthReq->to_url());
} catch (Exception $e) {
print "Error! HTTP response body: " . $httpReq->getBody();
echo 'Error! HTTP response body: ' . $httpReq->getBody();
exit(1);
}
print $httpReq->getBody();
echo $httpReq->getBody();
function httpRequest($url)
{
$request = HTTPClient::start();
$request->setConfig(
array(
[
'follow_redirects' => true,
'connect_timeout' => 120,
'timeout' => 120,
'ssl_verify_peer' => false,
'ssl_verify_host' => false
)
'ssl_verify_host' => false,
]
);
return $request->get($url);