From cfc89d8a25a188af7f5b3d7caec466fee9735895 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 18 Aug 2021 17:33:41 +0100 Subject: [PATCH] [TESTS] Raise test coverage of LocalUser to 100% --- tests/Entity/LocalUserTest.php | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/Entity/LocalUserTest.php diff --git a/tests/Entity/LocalUserTest.php b/tests/Entity/LocalUserTest.php new file mode 100644 index 0000000000..180c44515d --- /dev/null +++ b/tests/Entity/LocalUserTest.php @@ -0,0 +1,54 @@ +. +// }}} + +namespace App\Tests\Entity; + +use App\Entity\LocalUser; +use App\Util\GNUsocialTestCase; +use Jchook\AssertThrows\AssertThrows; + +class LocalUserTest extends GNUsocialTestCase +{ + use AssertThrows; + + public function testAlgoNameToConstant() + { + $if_exists = function ($name, $constant) { + if (defined($constant)) { + static::assertSame(constant($constant), LocalUser::algoNameToConstant($name)); + } else { + static::assertThrows(\Exception::class, fn () => LocalUser::algoNameToConstant($name)); + } + }; + $if_exists('bcrypt', 'PASSWORD_BCRYPT'); + $if_exists('argon2', 'PASSWORD_ARGON2'); + $if_exists('argon2i', 'PASSWORD_ARGON2I'); + $if_exists('argon2d', 'PASSWORD_ARGON2D'); + $if_exists('argon2id', 'PASSWORD_ARGON2ID'); + static::assertSame(\PASSWORD_ARGON2ID, LocalUser::algoNameToConstant('argon2id')); + } + + public function testChangePassword() + { + $user = LocalUser::findByNicknameOrEmail('form_personal_info_test_user', 'some@email'); + static::assertTrue($user->changePassword(old_password_plain_text: '', new_password_plain_text: 'password', override: true)); + static::assertTrue($user->changePassword(old_password_plain_text: 'password', new_password_plain_text: 'new_password', override: false)); + static::assertFalse($user->changePassword(old_password_plain_text: 'wrong_password', new_password_plain_text: 'new_password', override: false)); + } +}