2021-08-19 01:33:13 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-08-19 01:33:13 +09: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-08 01:17:44 +09:00
|
|
|
use App\Core\Cache;
|
2021-08-19 01:33:13 +09:00
|
|
|
use App\Core\DB\DB;
|
2022-03-08 01:17:44 +09:00
|
|
|
use App\Entity\Actor;
|
2021-08-19 01:33:13 +09:00
|
|
|
use App\Util\GNUsocialTestCase;
|
2022-01-05 07:22:48 +09:00
|
|
|
use Component\Circle\Entity\ActorTag;
|
2022-03-08 01:17:44 +09:00
|
|
|
use Component\Tag\Tag as CompTag;
|
2021-08-19 01:33:13 +09:00
|
|
|
use Jchook\AssertThrows\AssertThrows;
|
|
|
|
|
2021-09-18 11:22:27 +09:00
|
|
|
class ActorTest extends GNUsocialTestCase
|
2021-08-19 01:33:13 +09:00
|
|
|
{
|
|
|
|
use AssertThrows;
|
|
|
|
|
|
|
|
public function testGetAvatarUrl()
|
|
|
|
{
|
2022-03-08 01:17:44 +09:00
|
|
|
$actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
|
2021-11-16 23:10:19 +09:00
|
|
|
static::assertSame('/avatar/default', $actor->getAvatarUrl());
|
2021-08-19 01:33:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSelfTags()
|
|
|
|
{
|
2022-03-08 01:17:44 +09: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-19 01:33:13 +09:00
|
|
|
DB::flush();
|
2022-03-08 01:17:44 +09:00
|
|
|
Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
|
2022-03-08 09:21:12 +09:00
|
|
|
$actual = $actor->getSelfTags();
|
|
|
|
static::assertCount(1, $actual);
|
|
|
|
static::assertObjectEquals(expected: $actor_tag_foo, actual: $actual[0]);
|
2022-03-08 01:17:44 +09: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-19 01:33:13 +09:00
|
|
|
DB::flush();
|
2022-03-08 01:17:44 +09:00
|
|
|
Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
|
2022-03-08 09:21:12 +09: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-19 01:33:13 +09:00
|
|
|
}
|
|
|
|
}
|