diff --git a/tests/Core/ActivityGenerationTests.php b/tests/Core/ActivityGenerationTests.php index 57fa335681..96931c528f 100644 --- a/tests/Core/ActivityGenerationTests.php +++ b/tests/Core/ActivityGenerationTests.php @@ -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)); // is obsolete, no longer added + static::assertFalse(is_null($author)); + static::assertTrue(is_null($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) diff --git a/tests/Core/ActivityParseTests.php b/tests/Core/ActivityParseTests.php index fcba03363b..efc14ca833 100644 --- a/tests/Core/ActivityParseTests.php +++ b/tests/Core/ActivityParseTests.php @@ -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 correctly with a typical payload? - $this->assertEquals("

Geraldine posted a Photo on PhotoPanic

\n " . - "", trim($act->content)); + static::assertSame("

Geraldine posted a Photo on PhotoPanic

\n " . + '', 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, - '@evan now is the time for all good men to come to the aid of their country. #'); + static::assertFalse(empty($act->objects[0])); + static::assertSame( + $act->objects[0]->content, + '@evan now is the time for all good men to come to the aid of their country. #' + ); - $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("Some regular plain text.", - "Some regular plain text."), - array("<b>this is not HTML</b>", - "<b>this is not HTML</b>"), - array("Some regular plain HTML.", - "Some regular plain HTML."), - array("<b>this is too HTML</b>", - "this is too HTML"), - array("&lt;b&gt;but this is not HTML!&lt;/b&gt;", - "<b>but this is not HTML!</b>"), - array("
Some regular plain XHTML.
", - "Some regular plain XHTML."), - array("
This is some XHTML!
", - "This is some XHTML!"), - array("
<b>This is not some XHTML!</b>
", - "<b>This is not some XHTML!</b>"), - array("
&lt;b&gt;This is not some XHTML either!&lt;/b&gt;
", - "&lt;b&gt;This is not some XHTML either!&lt;/b&gt;")); + $tests = [['Some regular plain text.', + 'Some regular plain text.',], + ['<b>this is not HTML</b>', + '<b>this is not HTML</b>',], + ["Some regular plain HTML.", + 'Some regular plain HTML.',], + ["<b>this is too HTML</b>", + 'this is too HTML',], + ["&lt;b&gt;but this is not HTML!&lt;/b&gt;", + '<b>but this is not HTML!</b>',], + ["
Some regular plain XHTML.
", + 'Some regular plain XHTML.',], + ["
This is some XHTML!
", + 'This is some XHTML!',], + ["
<b>This is not some XHTML!</b>
", + '<b>This is not some XHTML!</b>',], + ["
&lt;b&gt;This is not some XHTML either!&lt;/b&gt;
", + '&lt;b&gt;This is not some XHTML either!&lt;/b&gt;',],]; foreach ($tests as $data) { list($source, $output) = $data; $xml = "" . - "http://example.com/fakeid" . - "Test" . - "Atom content tests" . + 'http://example.com/fakeid' . + 'Test' . + 'Atom content tests' . $source . - ""; + ''; $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("Some regular plain HTML.", - "Some regular plain HTML."), - array("Some <b>exciting bold HTML</b>", - "Some exciting bold HTML"), - array("Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;", - "Some <b>escaped non-HTML.</b>"), - array("Some plain text.", - "Some plain text."), - array("Some <b>non-HTML text</b>", - "Some <b>non-HTML text</b>"), - array("Some &lt;b&gt;double-escaped text&lt;/b&gt;", - "Some &lt;b&gt;double-escaped text&lt;/b&gt;")); + $tests = [['Some regular plain HTML.', + 'Some regular plain HTML.',], + ['Some <b>exciting bold HTML</b>', + 'Some exciting bold HTML',], + ['Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;', + 'Some <b>escaped non-HTML.</b>',], + ['Some plain text.', + 'Some plain text.',], + ['Some <b>non-HTML text</b>', + 'Some <b>non-HTML text</b>',], + ['Some &lt;b&gt;double-escaped text&lt;/b&gt;', + 'Some &lt;b&gt;double-escaped text&lt;/b&gt;',],]; foreach ($tests as $data) { list($source, $output) = $data; $xml = "" . - "http://example.com/fakeid" . - "RSS content tests" . + 'http://example.com/fakeid' . + 'RSS content tests' . $source . - ""; + ''; $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 // 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 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); } } diff --git a/tests/Core/CallableLeftCurryTest.php b/tests/Core/CallableLeftCurryTest.php index e0b8743eef..7ca9e6a9ce 100644 --- a/tests/Core/CallableLeftCurryTest.php +++ b/tests/Core/CallableLeftCurryTest.php @@ -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; } diff --git a/tests/Core/CommandInterperterTest.php b/tests/Core/CommandInterperterTest.php index c176357e21..8988f114d3 100644 --- a/tests/Core/CommandInterperterTest.php +++ b/tests/Core/CommandInterperterTest.php @@ -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; } - } diff --git a/tests/Core/HashTagDetectionTests.php b/tests/Core/HashTagDetectionTests.php index 7d5086e4e2..069076d4c1 100644 --- a/tests/Core/HashTagDetectionTests.php +++ b/tests/Core/HashTagDetectionTests.php @@ -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', - '# people'), - array('"#hello" people', - '"#" people'), - array('say "#hello" people', - 'say "#" people'), - array('say (#hello) people', - 'say (#) people'), - array('say [#hello] people', - 'say [#] people'), - array('say {#hello} people', - 'say {#} people'), - array('say \'#hello\' people', - 'say \'#\' people'), + return [ + ['hello', + 'hello',], + ['#hello people', + '# people',], + ['"#hello" people', + '"#" people',], + ['say "#hello" people', + 'say "#" people',], + ['say (#hello) people', + 'say (#) people',], + ['say [#hello] people', + 'say [#] people',], + ['say {#hello} people', + 'say {#} people',], + ['say \'#hello\' people', + 'say \'#\' people',], // Unicode legit letters - array('#éclair yummy', - '# yummy'), - array('#维基百科 zh.wikipedia!', - '# zh.wikipedia!'), - array('#Россия russia', - '# russia'), + ['#éclair yummy', + '# yummy',], + ['#维基百科 zh.wikipedia!', + '# zh.wikipedia!',], + ['#Россия russia', + '# russia',], // Unicode punctuators -- the ideographic "," separates the tag, just as "," does - array('#维基百科,zh.wikipedia!', - '#,zh.wikipedia!'), - array('#维基百科,zh.wikipedia!', - '#,zh.wikipedia!'), + ['#维基百科,zh.wikipedia!', + '#,zh.wikipedia!',], + ['#维基百科,zh.wikipedia!', + '#,zh.wikipedia!',], - ); + ]; } } diff --git a/tests/Core/LocationTest.php b/tests/Core/LocationTest.php index 9293e75b95..5910ab900b 100644 --- a/tests/Core/LocationTest.php +++ b/tests/Core/LocationTest.php @@ -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')); } } diff --git a/tests/Core/NicknameTest.php b/tests/Core/NicknameTest.php index 5e66ad37c1..0c33c105da 100644 --- a/tests/Core/NicknameTest.php +++ b/tests/Core/NicknameTest.php @@ -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 + ]; } } diff --git a/tests/Core/TagURITest.php b/tests/Core/TagURITest.php index a1e852b6cf..ab81849d38 100644 --- a/tests/Core/TagURITest.php +++ b/tests/Core/TagURITest.php @@ -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',]]; } } - diff --git a/tests/Core/URLDetectionTest.php b/tests/Core/URLDetectionTest.php index 0557d9e68f..f32e6640d5 100644 --- a/tests/Core/URLDetectionTest.php +++ b/tests/Core/URLDetectionTest.php @@ -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 http://www.somesite.com/xyz/35637563@N00/52803365/ link'), - array('http://127.0.0.1', - 'http://127.0.0.1'), - array('http://[::1]:99/test.php', - 'http://[::1]:99/test.php'), - array('http://::1/test.php', - 'http://::1/test.php'), - array('http://::1', - 'http://::1'), - array('http://127.0.0.1', - 'http://127.0.0.1'), - array('http://example.com', - 'http://example.com'), - array('http://example.com.', - 'http://example.com.'), - array('/var/lib/example.so', - '/var/lib/example.so'), - array('example', - 'example'), - array('mailto:user@example.com', - 'mailto:user@example.com'), - array('mailto:user@example.com?subject=test', - 'mailto:user@example.com?subject=test'), - array('xmpp:user@example.com', - 'xmpp:user@example.com'), - array('#example', - '#'), - array('#example.com', - '#'), - array('#.net', - '#'), - array('http://example', - 'http://example'), - array('http://3xampl3', - 'http://3xampl3'), - array('http://example/', - 'http://example/'), - array('http://example/path', - 'http://example/path'), - array('http://example.com', - 'http://example.com'), - array('https://example.com', - 'https://example.com'), - array('ftp://example.com', - 'ftp://example.com'), - array('ftps://example.com', - 'ftps://example.com'), - array('http://user@example.com', - 'http://user@example.com'), - array('http://user:pass@example.com', - 'http://user:pass@example.com'), - array('http://example.com:8080', - 'http://example.com:8080'), - array('http://example.com:8080/test.php', - 'http://example.com:8080/test.php'), - array('http://www.example.com', - 'http://www.example.com'), - array('http://example.com/', - 'http://example.com/'), - array('http://example.com/path', - 'http://example.com/path'), - array('http://example.com/path.html', - 'http://example.com/path.html'), - array('http://example.com/path.html#fragment', - 'http://example.com/path.html#fragment'), - array('http://example.com/path.php?foo=bar&bar=foo', - 'http://example.com/path.php?foo=bar&bar=foo'), - array('http://example.com.', - 'http://example.com.'), - array('http://müllärör.de', - 'http://müllärör.de'), - array('http://ﺱﺲﺷ.com', - 'http://ﺱﺲﺷ.com'), - array('http://сделаткартинки.com', - 'http://сделаткартинки.com'), - array('http://tūdaliņ.lv', - 'http://tūdaliņ.lv'), - array('http://brændendekærlighed.com', - 'http://brændendekærlighed.com'), - array('http://あーるいん.com', - 'http://あーるいん.com'), - array('http://예비교사.com', - 'http://예비교사.com'), - array('http://example.com.', - 'http://example.com.'), - array('http://example.com?', - 'http://example.com?'), - array('http://example.com!', - 'http://example.com!'), - array('http://example.com,', - 'http://example.com,'), - array('http://example.com;', - 'http://example.com;'), - array('http://example.com:', - 'http://example.com:'), - array('\'http://example.com\'', - '\'http://example.com\''), - array('"http://example.com"', - '"http://example.com"'), - array('"http://example.com/"', - '"http://example.com/"'), - array('http://example.com', - 'http://example.com'), - array('(http://example.com)', - '(http://example.com)'), - array('[http://example.com]', - '[http://example.com]'), - array('', - '<http://example.com>'), - array('http://example.com/path/(foo)/bar', - 'http://example.com/path/(foo)/bar'), - array('http://example.com/path/[foo]/bar', - 'http://example.com/path/[foo]/bar'), - array('http://example.com/path/foo/(bar)', - 'http://example.com/path/foo/(bar)'), + return [ + ['not a link :: no way', + 'not a link :: no way',], + ['link http://www.somesite.com/xyz/35637563@N00/52803365/ link', + 'link http://www.somesite.com/xyz/35637563@N00/52803365/ link',], + ['http://127.0.0.1', + 'http://127.0.0.1',], + ['http://[::1]:99/test.php', + 'http://[::1]:99/test.php',], + ['http://::1/test.php', + 'http://::1/test.php',], + ['http://::1', + 'http://::1',], + ['http://127.0.0.1', + 'http://127.0.0.1',], + ['http://example.com', + 'http://example.com',], + ['http://example.com.', + 'http://example.com.',], + ['/var/lib/example.so', + '/var/lib/example.so',], + ['example', + 'example',], + ['mailto:user@example.com', + 'mailto:user@example.com',], + ['mailto:user@example.com?subject=test', + 'mailto:user@example.com?subject=test',], + ['xmpp:user@example.com', + 'xmpp:user@example.com',], + ['#example', + '#',], + ['#example.com', + '#',], + ['#.net', + '#',], + ['http://example', + 'http://example',], + ['http://3xampl3', + 'http://3xampl3',], + ['http://example/', + 'http://example/',], + ['http://example/path', + 'http://example/path',], + ['http://example.com', + 'http://example.com',], + ['https://example.com', + 'https://example.com',], + ['ftp://example.com', + 'ftp://example.com',], + ['ftps://example.com', + 'ftps://example.com',], + ['http://user@example.com', + 'http://user@example.com',], + ['http://user:pass@example.com', + 'http://user:pass@example.com',], + ['http://example.com:8080', + 'http://example.com:8080',], + ['http://example.com:8080/test.php', + 'http://example.com:8080/test.php',], + ['http://www.example.com', + 'http://www.example.com',], + ['http://example.com/', + 'http://example.com/',], + ['http://example.com/path', + 'http://example.com/path',], + ['http://example.com/path.html', + 'http://example.com/path.html',], + ['http://example.com/path.html#fragment', + 'http://example.com/path.html#fragment',], + ['http://example.com/path.php?foo=bar&bar=foo', + 'http://example.com/path.php?foo=bar&bar=foo',], + ['http://example.com.', + 'http://example.com.',], + ['http://müllärör.de', + 'http://müllärör.de',], + ['http://ﺱﺲﺷ.com', + 'http://ﺱﺲﺷ.com',], + ['http://сделаткартинки.com', + 'http://сделаткартинки.com',], + ['http://tūdaliņ.lv', + 'http://tūdaliņ.lv',], + ['http://brændendekærlighed.com', + 'http://brændendekærlighed.com',], + ['http://あーるいん.com', + 'http://あーるいん.com',], + ['http://예비교사.com', + 'http://예비교사.com',], + ['http://example.com.', + 'http://example.com.',], + ['http://example.com?', + 'http://example.com?',], + ['http://example.com!', + 'http://example.com!',], + ['http://example.com,', + 'http://example.com,',], + ['http://example.com;', + 'http://example.com;',], + ['http://example.com:', + 'http://example.com:',], + ['\'http://example.com\'', + '\'http://example.com\'',], + ['"http://example.com"', + '"http://example.com"',], + ['"http://example.com/"', + '"http://example.com/"',], + ['http://example.com', + 'http://example.com',], + ['(http://example.com)', + '(http://example.com)',], + ['[http://example.com]', + '[http://example.com]',], + ['', + '<http://example.com>',], + ['http://example.com/path/(foo)/bar', + 'http://example.com/path/(foo)/bar',], + ['http://example.com/path/[foo]/bar', + 'http://example.com/path/[foo]/bar',], + ['http://example.com/path/foo/(bar)', + 'http://example.com/path/foo/(bar)',], //Not a valid url - urls cannot contain unencoded square brackets - array('http://example.com/path/foo/[bar]', - 'http://example.com/path/foo/[bar]'), - array('Hey, check out my cool site http://example.com okay?', - 'Hey, check out my cool site http://example.com okay?'), - array('What about parens (e.g. http://example.com/path/foo/(bar))?', - 'What about parens (e.g. http://example.com/path/foo/(bar))?'), - array('What about parens (e.g. http://example.com/path/foo/(bar)?', - 'What about parens (e.g. http://example.com/path/foo/(bar)?'), - array('What about parens (e.g. http://example.com/path/foo/(bar).)?', - 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), + ['http://example.com/path/foo/[bar]', + 'http://example.com/path/foo/[bar]',], + ['Hey, check out my cool site http://example.com okay?', + 'Hey, check out my cool site http://example.com okay?',], + ['What about parens (e.g. http://example.com/path/foo/(bar))?', + 'What about parens (e.g. http://example.com/path/foo/(bar))?',], + ['What about parens (e.g. http://example.com/path/foo/(bar)?', + 'What about parens (e.g. http://example.com/path/foo/(bar)?',], + ['What about parens (e.g. http://example.com/path/foo/(bar).)?', + 'What about parens (e.g. http://example.com/path/foo/(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. http://example.com/path/(foo,bar)?'), - array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', - 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), - array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?', - 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), - array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?', - 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), - array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', - 'Unbalanced too (e.g. http://example.com/path/foo/(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. http://example.com/path/(foo,bar)?',], + ['Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', + 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',], + ['Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?', + 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',], + ['Unbalanced too (e.g. http://example.com/path/foo/((((bar)?', + 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',], + ['Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', + 'Unbalanced too (e.g. http://example.com/path/foo/(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', - 'http://flickr.com/photos/34807140@N05/3838905434'), - ); + ['http://flickr.com/photos/34807140@N05/3838905434', + 'http://flickr.com/photos/34807140@N05/3838905434',], + ]; } - 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', '127.0.0.1', - 'bare_ipv4'), - array('127.0.0.1:99', + 'bare_ipv4',], + ['127.0.0.1:99', '127.0.0.1:99', - 'bare_ipv4'), - array('127.0.0.1/Name:test.php', + 'bare_ipv4',], + ['127.0.0.1/Name:test.php', '127.0.0.1/Name:test.php', - 'bare_ipv4'), - array('127.0.0.1/~test', + 'bare_ipv4',], + ['127.0.0.1/~test', '127.0.0.1/~test', - 'bare_ipv4'), - array('127.0.0.1/+test', + 'bare_ipv4',], + ['127.0.0.1/+test', '127.0.0.1/+test', - 'bare_ipv4'), - array('127.0.0.1/$test', + 'bare_ipv4',], + ['127.0.0.1/$test', '127.0.0.1/$test', - 'bare_ipv4'), - array('127.0.0.1/\'test', + 'bare_ipv4',], + ['127.0.0.1/\'test', '127.0.0.1/\'test', - 'bare_ipv4'), - array('127.0.0.1/"test', + 'bare_ipv4',], + ['127.0.0.1/"test', '127.0.0.1/"test', - 'bare_ipv4'), - array('127.0.0.1/test"test', + 'bare_ipv4',], + ['127.0.0.1/test"test', '127.0.0.1/test"test', - 'bare_ipv4'), - array('127.0.0.1/-test', + 'bare_ipv4',], + ['127.0.0.1/-test', '127.0.0.1/-test', - 'bare_ipv4'), - array('127.0.0.1/_test', + 'bare_ipv4',], + ['127.0.0.1/_test', '127.0.0.1/_test', - 'bare_ipv4'), - array('127.0.0.1/!test', + 'bare_ipv4',], + ['127.0.0.1/!test', '127.0.0.1/!test', - 'bare_ipv4'), - array('127.0.0.1/*test', + 'bare_ipv4',], + ['127.0.0.1/*test', '127.0.0.1/*test', - 'bare_ipv4'), - array('127.0.0.1/test%20stuff', + 'bare_ipv4',], + ['127.0.0.1/test%20stuff', '127.0.0.1/test%20stuff', - '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', '2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', - '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', '[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php', - 'bare_ipv6'), - array('2001:4978:1b5:0:21d:e0ff:fe66:59ab', + 'bare_ipv6',], + ['2001:4978:1b5:0:21d:e0ff:fe66:59ab', '2001:4978:1b5:0:21d:e0ff:fe66:59ab', - 'bare_ipv6'), - array('example.com', + 'bare_ipv6',], + ['example.com', 'example.com', - 'bare_domains'), - array('flickr.com/photos/34807140@N05/3838905434', + 'bare_domains',], + ['flickr.com/photos/34807140@N05/3838905434', 'flickr.com/photos/34807140@N05/3838905434', - '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. example.com/path/foo/(bar))?', - '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. example.com/path/foo/(bar)?', - '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. example.com/path/foo/(bar).?', - '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. example.com/path/(foo,bar)?', - 'bare_domains'), - array('example.com', + 'bare_domains',], + ['example.com', 'example.com', - 'bare_domains'), - array('example.org', + 'bare_domains',], + ['example.org', 'example.org', - 'bare_domains'), - array('example.co.uk', + 'bare_domains',], + ['example.co.uk', 'example.co.uk', - 'bare_domains'), - array('www.example.co.uk', + 'bare_domains',], + ['www.example.co.uk', 'www.example.co.uk', - 'bare_domains'), - array('farm1.images.example.co.uk', + 'bare_domains',], + ['farm1.images.example.co.uk', 'farm1.images.example.co.uk', - 'bare_domains'), - array('example.museum', + 'bare_domains',], + ['example.museum', 'example.museum', - 'bare_domains'), - array('example.travel', + 'bare_domains',], + ['example.travel', 'example.travel', - 'bare_domains'), - array('example.com.', + 'bare_domains',], + ['example.com.', 'example.com.', - 'bare_domains'), - array('example.com?', + 'bare_domains',], + ['example.com?', 'example.com?', - 'bare_domains'), - array('example.com!', + 'bare_domains',], + ['example.com!', 'example.com!', - 'bare_domains'), - array('example.com,', + 'bare_domains',], + ['example.com,', 'example.com,', - 'bare_domains'), - array('example.com;', + 'bare_domains',], + ['example.com;', 'example.com;', - 'bare_domains'), - array('example.com:', + 'bare_domains',], + ['example.com:', 'example.com:', - 'bare_domains'), - array('\'example.com\'', + 'bare_domains',], + ['\'example.com\'', '\'example.com\'', - 'bare_domains'), - array('"example.com"', + 'bare_domains',], + ['"example.com"', '"example.com"', - 'bare_domains'), - array('example.com', + 'bare_domains',], + ['example.com', 'example.com', - 'bare_domains'), - array('(example.com)', + 'bare_domains',], + ['(example.com)', '(example.com)', - 'bare_domains'), - array('[example.com]', + 'bare_domains',], + ['[example.com]', '[example.com]', - 'bare_domains'), - array('', + 'bare_domains',], + ['', '<example.com>', - '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 example.com 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 example.com.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 example.com.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 example.com.You will love it.', - 'bare_domains'), - array('example.com:8080/test.php', + 'bare_domains',], + ['example.com:8080/test.php', 'example.com:8080/test.php', - 'bare_domains'), - array('user_name+other@example.com', + 'bare_domains',], + ['user_name+other@example.com', 'user_name+other@example.com', - 'bare_domains'), - array('user@example.com', + 'bare_domains',], + ['user@example.com', 'user@example.com', - 'bare_domains'), - ); + 'bare_domains',], + ]; } } diff --git a/tests/Core/UUIDTest.php b/tests/Core/UUIDTest.php index 88aa4dd201..658841dc7b 100644 --- a/tests/Core/UUIDTest.php +++ b/tests/Core/UUIDTest.php @@ -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'); } } - diff --git a/tests/Core/UserFeedParseTest.php b/tests/Core/UserFeedParseTest.php index 798d964d66..73105a460e 100644 --- a/tests/Core/UserFeedParseTest.php +++ b/tests/Core/UserFeedParseTest.php @@ -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 = <<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)); } } diff --git a/tests/Core/XmppValidateTest.php b/tests/Core/XmppValidateTest.php index 1d607d2dcd..37f003c3f5 100644 --- a/tests/Core/XmppValidateTest.php +++ b/tests/Core/XmppValidateTest.php @@ -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 diff --git a/tests/Media/MediaFileTest.php b/tests/Media/MediaFileTest.php index 05b00db697..db9227283a 100644 --- a/tests/Media/MediaFileTest.php +++ b/tests/Media/MediaFileTest.php @@ -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; } - } diff --git a/tests/atompub/atompub_test.php b/tests/atompub/atompub_test.php index 4df1695049..5f6fdb5eef 100755 --- a/tests/atompub/atompub_test.php +++ b/tests/atompub/atompub_test.php @@ -23,7 +23,7 @@ if (!defined('INSTALLDIR')) { } $shortoptions = 'n:p:'; -$longoptions = array('nickname=', 'password=', 'dry-run'); +$longoptions = ['nickname=', 'password=', 'dry-run']; $helptext = << '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('barf'); 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('arfbarf'); die("FAILED, succeeded!\n"); @@ -89,37 +89,37 @@ try { $rand = mt_rand(0, 99999); $atom = << - This is an AtomPub test post title ($rand) - This is an AtomPub test post content ($rand) + This is an AtomPub test post title ({$rand}) + This is an AtomPub test post content ({$rand}) 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 diff --git a/tests/oauth/fetch_temp_creds.php b/tests/oauth/fetch_temp_creds.php index bea512a914..f50c4ec01e 100755 --- a/tests/oauth/fetch_temp_creds.php +++ b/tests/oauth/fetch_temp_creds.php @@ -18,25 +18,25 @@ * along with this program. If not, see . */ -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); } } $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); $endpoint = $ini['apiroot'] . $ini['request_token_url']; -$parsed = parse_url($endpoint); -$params = array(); +$parsed = parse_url($endpoint); +$params = []; parse_str($parsed['query'], $params); $params['oauth_callback'] = 'oob'; // out-of-band @@ -47,57 +47,56 @@ 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(); +$body = $r->getBody(); +$tokenStuff = []; parse_str($body, $tokenStuff); -$tok = $tokenStuff['oauth_token']; +$tok = $tokenStuff['oauth_token']; $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 - ) + 'connect_timeout' => 120, + 'timeout' => 120, + 'ssl_verify_peer' => false, + 'ssl_verify_host' => false, + ] ); // Turn signed request query string back into an array diff --git a/tests/oauth/fetch_token_creds.php b/tests/oauth/fetch_token_creds.php index a508c7240c..aac05be984 100755 --- a/tests/oauth/fetch_token_creds.php +++ b/tests/oauth/fetch_token_creds.php @@ -18,16 +18,16 @@ * along with this program. If not, see . */ -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 = <<sign_request($hmac_method, $consumer, $rtok); - $httpReq = httpRequest($endpoint, $oauthReq->to_postdata()); - $body = $httpReq->getBody(); - + $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 - ) + 'connect_timeout' => 120, + 'timeout' => 120, + 'ssl_verify_peer' => false, + 'ssl_verify_host' => false, + ] ); parse_str($poststr, $postdata); diff --git a/tests/oauth/oauth_post_notice.php b/tests/oauth/oauth_post_notice.php index 23fc04b531..882e4c95a7 100755 --- a/tests/oauth/oauth_post_notice.php +++ b/tests/oauth/oauth_post_notice.php @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - **/ + */ -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 = <<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 - ) + 'connect_timeout' => 120, + 'timeout' => 120, + 'ssl_verify_peer' => false, + 'ssl_verify_host' => false, + ] ); // Turn signed request query string back into an array diff --git a/tests/oauth/oauth_verify_creds.php b/tests/oauth/oauth_verify_creds.php index a37538d87e..b65a79ee89 100755 --- a/tests/oauth/oauth_verify_creds.php +++ b/tests/oauth/oauth_verify_creds.php @@ -18,12 +18,12 @@ * along with this program. If not, see . */ -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 = <<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 - ) + 'connect_timeout' => 120, + 'timeout' => 120, + 'ssl_verify_peer' => false, + 'ssl_verify_host' => false, + ] ); return $request->get($url);