2021-08-18 17:33:13 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 09:26:18 +01:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-08-18 17:33:13 +01:00
|
|
|
// {{{ License
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
|
2022-03-07 16:17:44 +00:00
|
|
|
use App\Core\Cache;
|
2022-03-27 15:19:09 +01:00
|
|
|
use App\Core\DB;
|
2022-03-07 16:17:44 +00:00
|
|
|
use App\Entity\Actor;
|
2021-08-18 17:33:13 +01:00
|
|
|
use App\Util\GNUsocialTestCase;
|
2022-01-04 22:22:48 +00:00
|
|
|
use Component\Circle\Entity\ActorTag;
|
2022-03-07 16:17:44 +00:00
|
|
|
use Component\Tag\Tag as CompTag;
|
2021-08-18 17:33:13 +01:00
|
|
|
use Jchook\AssertThrows\AssertThrows;
|
|
|
|
|
2021-09-18 03:22:27 +01:00
|
|
|
class ActorTest extends GNUsocialTestCase
|
2021-08-18 17:33:13 +01:00
|
|
|
{
|
|
|
|
use AssertThrows;
|
|
|
|
|
|
|
|
public function testGetAvatarUrl()
|
|
|
|
{
|
2022-03-07 16:17:44 +00:00
|
|
|
$actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
|
2021-11-16 14:10:19 +00:00
|
|
|
static::assertSame('/avatar/default', $actor->getAvatarUrl());
|
2021-08-18 17:33:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSelfTags()
|
|
|
|
{
|
2022-03-07 16:17:44 +00:00
|
|
|
$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,
|
|
|
|
]));
|
2021-08-18 17:33:13 +01:00
|
|
|
DB::flush();
|
2022-03-07 16:17:44 +00:00
|
|
|
Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
|
2022-03-08 00:21:12 +00:00
|
|
|
$actual = $actor->getSelfTags();
|
|
|
|
static::assertCount(1, $actual);
|
|
|
|
static::assertObjectEquals(expected: $actor_tag_foo, actual: $actual[0]);
|
2022-03-07 16:17:44 +00:00
|
|
|
// 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,
|
|
|
|
]));
|
2021-08-18 17:33:13 +01:00
|
|
|
DB::flush();
|
2022-03-07 16:17:44 +00:00
|
|
|
Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
|
2022-03-08 00:21:12 +00:00
|
|
|
$actual = $actor->getSelfTags();
|
|
|
|
static::assertCount(2, $actual);
|
|
|
|
foreach ([$actor_tag_bar, $actor_tag_foo] as $expected) {
|
|
|
|
$a = array_shift($actual);
|
|
|
|
if ($expected->equals($a) !== true) {
|
|
|
|
dd($expected, $a);
|
|
|
|
}
|
|
|
|
static::assertObjectEquals($expected, $a);
|
|
|
|
}
|
2021-08-18 17:33:13 +01:00
|
|
|
}
|
|
|
|
}
|