. // }}} namespace App\Tests\Entity; use App\Core\Cache; use App\Core\DB\DB; use App\Entity\Actor; use App\Util\GNUsocialTestCase; use Component\Circle\Entity\ActorTag; use Component\Tag\Tag as CompTag; use Jchook\AssertThrows\AssertThrows; class ActorTest extends GNUsocialTestCase { use AssertThrows; public function testGetAvatarUrl() { $actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']); static::assertSame('/avatar/default', $actor->getAvatarUrl()); } public function testSelfTags() { $actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']); // Start with no self-tags static::assertSame( expected: [], actual: $actor->getSelfTags(), ); // Add one self-tag 'foo' $tag = CompTag::sanitize('foo'); DB::persist($actor_tag_foo = ActorTag::create([ 'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag 'tagged' => $actor->getId(), 'tag' => $tag, ])); DB::flush(); Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']); static::assertSame( expected: [$actor_tag_foo], actual: $actor->getSelfTags(), ); // Add a second self-tag 'foo' $tag = CompTag::sanitize('bar'); DB::persist($actor_tag_bar = ActorTag::create([ 'tagger' => $actor->getId(), // self tag means tagger = tagger in ActorTag 'tagged' => $actor->getId(), 'tag' => $tag, ])); DB::flush(); Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']); static::assertSame( expected: [$actor_tag_bar, $actor_tag_foo], actual: $actor->getSelfTags(), ); } }