[TESTS] Fix tests by adding missing is_local columns and by login in the admin user in the admin panel test

This commit is contained in:
Hugo Sales 2021-11-23 22:34:35 +00:00
parent d9544c6edb
commit 0194b6b14c
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
6 changed files with 18 additions and 14 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types = 1);
namespace App\DataFixtures; namespace App\DataFixtures;
use App\Core\UserRoles;
use App\Core\VisibilityScope; use App\Core\VisibilityScope;
use App\Entity\Actor; use App\Entity\Actor;
use App\Entity\GroupInbox; use App\Entity\GroupInbox;
@ -22,14 +23,15 @@ class CoreFixtures extends Fixture
$actors = []; $actors = [];
$local_entities = []; $local_entities = [];
foreach ([ foreach ([
'taken_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'email@provider']], 'taken_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar'), 'outgoing_email' => 'email@provider'], []],
'some_user' => [LocalUser::class, 'setId', []], 'some_user' => [LocalUser::class, 'setId', [], []],
'local_user_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar')]], 'admin' => [LocalUser::class, 'setId', [], ['roles' => UserRoles::ADMIN | UserRoles::USER]],
'form_personal_info_test_user' => [LocalUser::class, 'setId', []], 'local_user_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('foobar')], []],
'form_account_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('some password')]], 'form_personal_info_test_user' => [LocalUser::class, 'setId', [], []],
'taken_group' => [LocalGroup::class, 'setGroupId', []], 'form_account_test_user' => [LocalUser::class, 'setId', ['password' => LocalUser::hashPassword('some password')], []],
] as $nick => [$entity, $method, $extra_create]) { 'taken_group' => [LocalGroup::class, 'setGroupId', [], []],
$actor = Actor::create(['nickname' => $nick, 'is_local' => true]); ] as $nick => [$entity, $method, $extra_create, $extra_create_actor]) {
$actor = Actor::create(array_merge(['nickname' => $nick, 'is_local' => true], $extra_create_actor));
$manager->persist($actor); $manager->persist($actor);
$ent = $entity::create(array_merge(['nickname' => $nick], $extra_create)); // cannot use array spread for arrays with string keys $ent = $entity::create(array_merge(['nickname' => $nick], $extra_create)); // cannot use array spread for arrays with string keys
$ent->{$method}($actor->getId()); $ent->{$method}($actor->getId());

View File

@ -21,8 +21,9 @@ declare(strict_types = 1);
// }}} // }}}
namespace App\Tests\Core; namespace App\Tests\Controller;
use App\Core\DB\DB;
use App\Util\Common; use App\Util\Common;
use App\Util\Formatting; use App\Util\Formatting;
use App\Util\GNUsocialTestCase; use App\Util\GNUsocialTestCase;
@ -36,6 +37,7 @@ class AdminTest extends GNUsocialTestCase
private function test(array $setting, callable $get_value) private function test(array $setting, callable $get_value)
{ {
$client = static::createClient(); $client = static::createClient();
$client->loginUser(DB::findOneBy('local_user', ['nickname' => 'admin']));
copy(INSTALLDIR . '/social.local.yaml', INSTALLDIR . '/social.local.yaml.back'); copy(INSTALLDIR . '/social.local.yaml', INSTALLDIR . '/social.local.yaml.back');
$old = Common::config(...$setting); $old = Common::config(...$setting);
$value = $get_value(); $value = $get_value();

View File

@ -37,8 +37,8 @@ class SecurityTest extends GNUsocialTestCase
$this->assertResponseIsSuccessful(); $this->assertResponseIsSuccessful();
// $form = $crawler->selectButton('Sign in')->form(); // $form = $crawler->selectButton('Sign in')->form();
$crawler = $client->submitForm('Sign in', [ $crawler = $client->submitForm('Sign in', [
'nickname_or_email' => $nickname, '_username' => $nickname,
'password' => $password, '_password' => $password,
]); ]);
$this->assertResponseStatusCodeSame(302); $this->assertResponseStatusCodeSame(302);
$crawler = $client->followRedirect(); $crawler = $client->followRedirect();

View File

@ -80,7 +80,7 @@ class DBTest extends GNUsocialTestCase
public function testPersistWithSameId() public function testPersistWithSameId()
{ {
$actor = Actor::create(['nickname' => 'test', 'bio' => 'some very interesting bio']); $actor = Actor::create(['nickname' => 'test', 'bio' => 'some very interesting bio', 'is_local' => false]);
$user = LocalUser::create(['nickname' => 'test']); $user = LocalUser::create(['nickname' => 'test']);
$id = DB::persistWithSameId($actor, $user, fn ($id) => $id); $id = DB::persistWithSameId($actor, $user, fn ($id) => $id);
static::assertTrue($id != 0); static::assertTrue($id != 0);

View File

@ -118,7 +118,7 @@ class FormTest extends GNUsocialTestCase
$ret = Form::handle(form_definition: [/* not normal usage */], request: $mock_request, target: null, extra_args: [], extra_step: null, create_args: [], testing_only_form: $mock_form); $ret = Form::handle(form_definition: [/* not normal usage */], request: $mock_request, target: null, extra_args: [], extra_step: null, create_args: [], testing_only_form: $mock_form);
static::assertSame($data, $ret); static::assertSame($data, $ret);
$actor = Actor::create(['nickname' => 'form_testing_new_user']); $actor = Actor::create(['nickname' => 'form_testing_new_user', 'is_local' => false]);
DB::persist($actor); DB::persist($actor);
$ret = Form::handle(form_definition: [/* not normal usage */], request: $mock_request, target: $actor, extra_args: [], extra_step: null, create_args: [], testing_only_form: $mock_form); $ret = Form::handle(form_definition: [/* not normal usage */], request: $mock_request, target: $actor, extra_args: [], extra_step: null, create_args: [], testing_only_form: $mock_form);
static::assertSame($mock_form, $ret); static::assertSame($mock_form, $ret);

View File

@ -106,7 +106,7 @@ class AttachmentTest extends GNUsocialTestCase
$attachment->setFilename($filename); $attachment->setFilename($filename);
$actor = DB::findOneBy('actor', ['nickname' => 'taken_user']); $actor = DB::findOneBy('actor', ['nickname' => 'taken_user']);
DB::persist($note = Note::create(['actor_id' => $actor->getId(), 'content' => 'attachment: some content', 'content_type' => 'text/plain'])); DB::persist($note = Note::create(['actor_id' => $actor->getId(), 'content' => 'attachment: some content', 'content_type' => 'text/plain', 'is_local' => true]));
DB::persist(AttachmentToNote::create(['attachment_id' => $attachment->getId(), 'note_id' => $note->getId(), 'title' => 'A title'])); DB::persist(AttachmentToNote::create(['attachment_id' => $attachment->getId(), 'note_id' => $note->getId(), 'title' => 'A title']));
DB::flush(); DB::flush();