From ae0e4109868dbac8f4bf96faf0a520dff7cc13bf Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Fri, 23 Apr 2021 15:38:26 +0000 Subject: [PATCH] [TESTS] Fix Nickname test --- src/Util/Nickname.php | 23 +++++++++++------------ tests/Core/I18n/I18nTest.php | 8 ++++++++ tests/Entity/PollTest.php | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Util/Nickname.php b/src/Util/Nickname.php index 7f1b6f0cfb..bee4e37ed8 100644 --- a/src/Util/Nickname.php +++ b/src/Util/Nickname.php @@ -138,30 +138,29 @@ class Nickname * @throws NicknameTooLongException * @throws NicknameTooShortException */ - public static function normalize(string $nickname, bool $check_already_used = true, bool $checking_reserved = true): string + public static function normalize(string $nickname, bool $check_already_used = true, bool $checking_reserved = false): string { if (mb_strlen($nickname) > self::MAX_LEN) { // Display forms must also fit! throw new NicknameTooLongException(); } - $original_nickname = $nickname; - $nickname = trim($nickname); - $nickname = str_replace('_', '', $nickname); - $nickname = mb_strtolower($nickname); - $nickname = Normalizer::normalize($nickname, Normalizer::FORM_C); + $nickname = trim($nickname); + $nickname = str_replace('_', '', $nickname); + $nickname = mb_strtolower($nickname); + $nickname = Normalizer::normalize($nickname, Normalizer::FORM_C); if (!$checking_reserved) { - if (mb_strlen($original_nickname) < 1) { + if (mb_strlen($nickname) < 1) { throw new NicknameEmptyException(); - } elseif (mb_strlen($original_nickname) < Common::config('nickname', 'min_length')) { + } elseif (mb_strlen($nickname) < Common::config('nickname', 'min_length')) { throw new NicknameTooShortException(); - } elseif (!self::isCanonical($original_nickname) && !filter_var($original_nickname, FILTER_VALIDATE_EMAIL)) { + } elseif (!self::isCanonical($nickname) && !filter_var($nickname, FILTER_VALIDATE_EMAIL)) { throw new NicknameInvalidException(); - } elseif (self::isReserved($original_nickname) || Common::isSystemPath($original_nickname)) { + } elseif (self::isReserved($nickname) || Common::isSystemPath($nickname)) { throw new NicknameReservedException(); } elseif ($check_already_used) { - $actor = self::isTaken($original_nickname); + $actor = self::isTaken($nickname); if ($actor instanceof GSActor) { throw new NicknameTakenException($actor); } @@ -208,7 +207,7 @@ class Nickname return false; } return in_array($nickname, array_merge($reserved, F\map($reserved, function ($n) { - return self::normalize($n, check_already_used: false, check_reserved: false); + return self::normalize($n, check_already_used: false, checking_reserved: true); }))); } diff --git a/tests/Core/I18n/I18nTest.php b/tests/Core/I18n/I18nTest.php index 66be1556fb..3bfa0eb033 100644 --- a/tests/Core/I18n/I18nTest.php +++ b/tests/Core/I18n/I18nTest.php @@ -36,6 +36,14 @@ class I18nTest extends KernelTestCase I18n::setTranslator($translator); static::assertSame('test string', _m('test string')); + static::assertSame('test string', _m('test {thing}', ['thing' => 'string'])); + } + + public function testICU() + { + static::bootKernel(); + $translator = static::$container->get('translator'); + I18n::setTranslator($translator); $apples = [1 => '1 apple', '# apples']; static::assertSame('-42 apples', _m($apples, ['count' => -42])); diff --git a/tests/Entity/PollTest.php b/tests/Entity/PollTest.php index 391eac00d2..53e7318539 100644 --- a/tests/Entity/PollTest.php +++ b/tests/Entity/PollTest.php @@ -18,8 +18,8 @@ namespace App\Tests\Entity; -use App\Entity\Poll; use PHPUnit\Framework\TestCase; +use Plugin\Poll\Entity\Poll; class PollTest extends TestCase {