From a2e302efb4dba9a6cdb976c82d0b476b1f39b6ea Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 18 Aug 2021 17:33:13 +0100 Subject: [PATCH] [TESTS] Raise GSActor test coverage to 100% --- tests/Entity/GSActorTest.php | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/Entity/GSActorTest.php diff --git a/tests/Entity/GSActorTest.php b/tests/Entity/GSActorTest.php new file mode 100644 index 0000000000..7896ef822f --- /dev/null +++ b/tests/Entity/GSActorTest.php @@ -0,0 +1,60 @@ +. +// }}} + +namespace App\Tests\Entity; + +use App\Core\DB\DB; +use App\Entity\GSActor; +use App\Entity\GSActorTag; +use App\Util\GNUsocialTestCase; +use Functional as F; +use Jchook\AssertThrows\AssertThrows; + +class GSActorTest extends GNUsocialTestCase +{ + use AssertThrows; + + public function testGetAvatarUrl() + { + $actor = DB::findOneBy('gsactor', ['nickname' => 'taken_user']); + static::assertSame('/assets/default-avatar.svg', $actor->getAvatarUrl()); + + // $actor = DB::findOneBy('gsactor', ['nickname' => 'taken_user']); + // $id = $actor->getId(); + // static::assertSame("/avatar/{$id}", $actor->getAvatarUrl()); + } + + public function testGetFromNickname() + { + static::assertNotNull(GSActor::getFromNickname('taken_user')); + } + + public function testSelfTags() + { + $actor = DB::findOneBy('gsactor', ['nickname' => 'taken_user']); + $tags = $actor->getSelfTags(); + $actor->setSelfTags(['foo'], $tags); + DB::flush(); + $get_tags = fn ($tags) => F\map($tags, fn (GSActorTag $t) => (string) $t); + static::assertSame(['foo'], $get_tags($tags = $actor->getSelfTags())); + $actor->setSelfTags(['bar'], $tags); + DB::flush(); + static::assertSame(['bar'], $get_tags($tags = $actor->getSelfTags())); + } +}