[TESTS][DataFixtures] Add user, self follows, group member and group scope note

This commit is contained in:
Hugo Sales 2021-08-18 17:26:37 +01:00
parent 365afb7ba8
commit e392a9c90c
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 12 additions and 4 deletions

View File

@ -3,7 +3,9 @@
namespace App\DataFixtures;
use App\Core\VisibilityScope;
use App\Entity\Follow;
use App\Entity\GroupInbox;
use App\Entity\GroupMember;
use App\Entity\GSActor;
use App\Entity\LocalGroup;
use App\Entity\LocalUser;
@ -17,17 +19,21 @@ class CoreFixtures extends Fixture
{
$actors = [];
$local_entities = [];
foreach (['taken_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'email@provider']],
foreach ([
'taken_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'email@provider']],
'some_user' => [LocalUser::class, 'setId', []],
'form_personal_info_test_user' => [LocalUser::class, 'setId', []],
'form_account_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('some password')]],
'taken_group' => [LocalGroup::class, 'setGroupId', []], ]
as $nick => [$entity, $method, $extra_create]) {
'taken_group' => [LocalGroup::class, 'setGroupId', []],
] as $nick => [$entity, $method, $extra_create]) {
$actor = GSActor::create(['nickname' => $nick]);
$manager->persist($actor);
$ent = $entity::create(array_merge(['nickname' => $nick], $extra_create)); // cannot use array spread for arrays with string keys
$ent->{$method}($actor->getId());
$local_entities[$nick] = $ent;
$manager->persist($ent);
// Add self follows
$manager->persist(Follow::create(['follower' => $actor->getId(), 'followed' => $actor->getId()]));
$actors[$nick] = $actor;
}
@ -35,11 +41,13 @@ class CoreFixtures extends Fixture
$manager->persist($n);
$notes[] = Note::create(['gsactor_id' => $actors['taken_user']->getId(), 'content' => 'some other content', 'reply_to' => $n->getId()]);
$notes[] = Note::create(['gsactor_id' => $actors['taken_user']->getId(), 'content' => 'private note', 'scope' => VisibilityScope::FOLLOWER]);
$notes[] = $group_note = Note::create(['gsactor_id' => $actors['taken_user']->getId(), 'content' => 'group note', 'scope' => VisibilityScope::GROUP]);
foreach ($notes as $note) {
$manager->persist($note);
}
$manager->persist(GroupInbox::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'activity_id' => $note->getId()]));
$manager->persist(GroupMember::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'gsactor_id' => $actors['some_user']->getId()]));
$manager->persist(GroupInbox::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'activity_id' => $group_note->getId()]));
$manager->flush();
}
}