[TESTS][Nickname] Update tests to reflect new usage. Normalization functionality will be moved to a plugin

This commit is contained in:
Hugo Sales 2021-07-28 21:22:31 +00:00
parent adf0897527
commit 6b4b3e90fb
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -19,7 +19,6 @@
namespace App\Tests\Util; namespace App\Tests\Util;
use App\Entity\GSActor;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\NicknameEmptyException; use App\Util\Exception\NicknameEmptyException;
use App\Util\Exception\NicknameInvalidException; use App\Util\Exception\NicknameInvalidException;
@ -45,14 +44,15 @@ class NicknameTest extends GNUsocialTestCase
->willReturnMap([['gnusocial', $conf], ['gnusocial_defaults', $conf]]); ->willReturnMap([['gnusocial', $conf], ['gnusocial_defaults', $conf]]);
Common::setupConfig($cb); Common::setupConfig($cb);
static::assertThrows(NicknameTooLongException::class, fn () => Nickname::normalize(serialize(random_bytes(128)), check_already_used: false)); static::assertThrows(NicknameTooLongException::class, fn () => Nickname::normalize(str_repeat('longstring-', 128), check_already_used: false));
static::assertThrows(NicknameInvalidException::class, fn () => Nickname::normalize('null\0', check_already_used: false));
static::assertSame('foobar', Nickname::normalize('foobar', check_already_used: false)); static::assertSame('foobar', Nickname::normalize('foobar', check_already_used: false));
static::assertSame('foobar', Nickname::normalize(' foobar ', check_already_used: false)); static::assertSame('foobar', Nickname::normalize(' foobar ', check_already_used: false));
static::assertSame('foobar', Nickname::normalize('foo_bar', check_already_used: false)); // static::assertSame('foobar', Nickname::normalize('foo_bar', check_already_used: false));
static::assertSame('foobar', Nickname::normalize('FooBar', check_already_used: false)); // static::assertSame('foobar', Nickname::normalize('FooBar', check_already_used: false));
static::assertThrows(NicknameTooShortException::class, fn () => Nickname::normalize('foo', check_already_used: false)); static::assertThrows(NicknameTooShortException::class, fn () => Nickname::normalize('foo', check_already_used: false));
static::assertThrows(NicknameEmptyException::class, fn () => Nickname::normalize('', check_already_used: false)); static::assertThrows(NicknameEmptyException::class, fn () => Nickname::normalize('', check_already_used: false));
static::assertThrows(NicknameInvalidException::class, fn () => Nickname::normalize('FóóBár', check_already_used: false)); // static::assertThrows(NicknameInvalidException::class, fn () => Nickname::normalize('FóóBár', check_already_used: false));
static::assertThrows(NicknameReservedException::class, fn () => Nickname::normalize('this_nickname_is_reserved', check_already_used: false)); static::assertThrows(NicknameReservedException::class, fn () => Nickname::normalize('this_nickname_is_reserved', check_already_used: false));
static::bootKernel(); static::bootKernel();
@ -88,14 +88,4 @@ class NicknameTest extends GNUsocialTestCase
Common::setupConfig($cb); Common::setupConfig($cb);
static::assertFalse(Nickname::isReserved('this_nickname_is_reserved')); static::assertFalse(Nickname::isReserved('this_nickname_is_reserved'));
} }
public function testCheckTaken()
{
static::bootKernel();
static::assertNull(Nickname::checkTaken('not_taken_user'));
static::assertTrue(Nickname::checkTaken('taken_user') instanceof GSActor);
static::assertNull(Nickname::checkTaken('not_taken_group'));
static::assertTrue(Nickname::checkTaken('taken_group') instanceof GSActor);
}
} }