[TESTS] Fix Circle SelfTags Setting test
This commit is contained in:
parent
ff06a2656a
commit
cc4f967186
@ -97,7 +97,7 @@ class Circle extends Component
|
||||
|
||||
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
|
||||
{
|
||||
if ($section === 'profile' && $request->get('_route') === 'settings') {
|
||||
if ($section === 'profile' && \in_array($request->get('_route'), ['person_actor_settings', 'group_actor_settings'])) {
|
||||
$tabs[] = [
|
||||
'title' => 'Self tags',
|
||||
'desc' => 'Add or remove tags on yourself',
|
||||
|
@ -23,6 +23,7 @@ class SelfTagsSettings extends Controller
|
||||
{
|
||||
/**
|
||||
* Generic settings page for an Actor's self tags
|
||||
* TODO: We should have $actor->setSelfTags(), $actor->addSelfTags(), $actor->removeSelfTags()
|
||||
*/
|
||||
public static function settingsSelfTags(Request $request, E\Actor $target, string $details_id)
|
||||
{
|
||||
|
@ -31,7 +31,6 @@ use App\Entity\Actor;
|
||||
use App\Util\Common;
|
||||
use App\Util\HTML;
|
||||
use App\Util\Nickname;
|
||||
use Component\Circle\Controller\SelfTagsSettings;
|
||||
use Component\Group\Controller as C;
|
||||
use Component\Group\Entity\LocalGroup;
|
||||
use Component\Notification\Notification;
|
||||
@ -44,7 +43,7 @@ class Group extends Component
|
||||
$r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\GroupFeed::class, 'groupViewId']);
|
||||
$r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GroupFeed::class, 'groupViewNickname']);
|
||||
$r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']);
|
||||
$r->connect(id: 'group_settings', uri_path: '/group/{id<\d+>}/settings', target: [C\Group::class, 'groupSettings']);
|
||||
$r->connect(id: 'group_actor_settings', uri_path: '/group/{id<\d+>}/settings', target: [C\Group::class, 'groupSettings']);
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
@ -65,7 +64,7 @@ class Group extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an <a href=group_settings> to the profile card for groups, if the current actor can access them
|
||||
* Add an <a href=group_actor_settings> to the profile card for groups, if the current actor can access them
|
||||
*/
|
||||
public function onAppendCardProfile(array $vars, array &$res): bool
|
||||
{
|
||||
@ -73,7 +72,7 @@ class Group extends Component
|
||||
$group = $vars['actor'];
|
||||
if (!\is_null($actor) && $group->isGroup()) {
|
||||
if ($actor->canModerate($group)) {
|
||||
$url = Router::url('group_settings', ['id' => $group->getId()]);
|
||||
$url = Router::url('group_actor_settings', ['id' => $group->getId()]);
|
||||
$res[] = HTML::html(['a' => ['attrs' => ['href' => $url, 'title' => _m('Edit group settings'), 'class' => 'profile-extra-actions'], _m('Group settings')]]);
|
||||
}
|
||||
$res[] = HTML::html(['a' => ['attrs' => ['href' => Router::url('blog_post', ['in' => $group->getId()]), 'title' => _m('Make a new blog post'), 'class' => 'profile-extra-actions'], _m('Post in blog')]]);
|
||||
@ -81,21 +80,6 @@ class Group extends Component
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
|
||||
{
|
||||
if ($section === 'profile' && $request->get('_route') === 'group_settings') {
|
||||
$group_id = (int) $request->get('id');
|
||||
$group = Actor::getById($group_id);
|
||||
$tabs[] = [
|
||||
'title' => 'Self tags',
|
||||
'desc' => 'Add or remove tags on this group',
|
||||
'id' => 'settings-self-tags',
|
||||
'controller' => SelfTagsSettings::settingsSelfTags($request, $group, 'settings-self-tags-details'),
|
||||
];
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
/**
|
||||
* If in a group route, get the current group
|
||||
*/
|
||||
|
@ -36,6 +36,7 @@ use App\Util\Exception\NotImplementedException;
|
||||
use App\Util\Formatting;
|
||||
use App\Util\Nickname;
|
||||
use Component\Avatar\Avatar;
|
||||
use Component\Circle\Entity\ActorTag;
|
||||
use Component\Group\Entity\GroupMember;
|
||||
use Component\Group\Entity\LocalGroup;
|
||||
use Component\Language\Entity\ActorLanguage;
|
||||
@ -331,7 +332,7 @@ class Actor extends Entity
|
||||
{
|
||||
return Cache::getList(
|
||||
self::cacheKeys($this->getId())['self-tags'],
|
||||
fn() => DB::findBy('actor_tag', ['tagger' => $this->getId(), 'tagged' => $this->getId()], order_by: ['modified' => 'DESC']),
|
||||
fn() => DB::findBy(ActorTag::class, ['tagger' => $this->getId(), 'tagged' => $this->getId()], order_by: ['modified' => 'DESC']),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,12 @@ declare(strict_types = 1);
|
||||
|
||||
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 Functional as F;
|
||||
use Component\Tag\Tag as CompTag;
|
||||
use Jchook\AssertThrows\AssertThrows;
|
||||
|
||||
class ActorTest extends GNUsocialTestCase
|
||||
@ -33,20 +35,43 @@ class ActorTest extends GNUsocialTestCase
|
||||
|
||||
public function testGetAvatarUrl()
|
||||
{
|
||||
$actor = DB::findOneBy('actor', ['nickname' => 'taken_user']);
|
||||
$actor = DB::findOneBy(Actor::class, ['nickname' => 'taken_user']);
|
||||
static::assertSame('/avatar/default', $actor->getAvatarUrl());
|
||||
}
|
||||
|
||||
public function testSelfTags()
|
||||
{
|
||||
$actor = DB::findOneBy('actor', ['nickname' => 'taken_user']);
|
||||
$tags = $actor->getSelfTags();
|
||||
$actor->setSelfTags(['foo'], $tags);
|
||||
$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();
|
||||
$get_tags = fn ($tags) => F\map($tags, fn (ActorTag $t) => $t->getTag());
|
||||
static::assertSame(['foo'], $get_tags($tags = $actor->getSelfTags()));
|
||||
$actor->setSelfTags(['bar'], $tags);
|
||||
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();
|
||||
static::assertSame(['bar'], $get_tags($tags = $actor->getSelfTags()));
|
||||
Cache::delete(Actor::cacheKeys($actor->getId())['self-tags']);
|
||||
static::assertSame(
|
||||
expected: [$actor_tag_bar, $actor_tag_foo],
|
||||
actual: $actor->getSelfTags(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user