[TESTS] Fix Nickname test
This commit is contained in:
		@@ -138,30 +138,29 @@ class Nickname
 | 
				
			|||||||
     * @throws NicknameTooLongException
 | 
					     * @throws NicknameTooLongException
 | 
				
			||||||
     * @throws NicknameTooShortException
 | 
					     * @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) {
 | 
					        if (mb_strlen($nickname) > self::MAX_LEN) {
 | 
				
			||||||
            // Display forms must also fit!
 | 
					            // Display forms must also fit!
 | 
				
			||||||
            throw new NicknameTooLongException();
 | 
					            throw new NicknameTooLongException();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $original_nickname = $nickname;
 | 
					 | 
				
			||||||
        $nickname = trim($nickname);
 | 
					        $nickname = trim($nickname);
 | 
				
			||||||
        $nickname = str_replace('_', '', $nickname);
 | 
					        $nickname = str_replace('_', '', $nickname);
 | 
				
			||||||
        $nickname = mb_strtolower($nickname);
 | 
					        $nickname = mb_strtolower($nickname);
 | 
				
			||||||
        $nickname = Normalizer::normalize($nickname, Normalizer::FORM_C);
 | 
					        $nickname = Normalizer::normalize($nickname, Normalizer::FORM_C);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!$checking_reserved) {
 | 
					        if (!$checking_reserved) {
 | 
				
			||||||
            if (mb_strlen($original_nickname) < 1) {
 | 
					            if (mb_strlen($nickname) < 1) {
 | 
				
			||||||
                throw new NicknameEmptyException();
 | 
					                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();
 | 
					                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();
 | 
					                throw new NicknameInvalidException();
 | 
				
			||||||
            } elseif (self::isReserved($original_nickname) || Common::isSystemPath($original_nickname)) {
 | 
					            } elseif (self::isReserved($nickname) || Common::isSystemPath($nickname)) {
 | 
				
			||||||
                throw new NicknameReservedException();
 | 
					                throw new NicknameReservedException();
 | 
				
			||||||
            } elseif ($check_already_used) {
 | 
					            } elseif ($check_already_used) {
 | 
				
			||||||
                $actor = self::isTaken($original_nickname);
 | 
					                $actor = self::isTaken($nickname);
 | 
				
			||||||
                if ($actor instanceof GSActor) {
 | 
					                if ($actor instanceof GSActor) {
 | 
				
			||||||
                    throw new NicknameTakenException($actor);
 | 
					                    throw new NicknameTakenException($actor);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -208,7 +207,7 @@ class Nickname
 | 
				
			|||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return in_array($nickname, array_merge($reserved, F\map($reserved, function ($n) {
 | 
					        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);
 | 
				
			||||||
        })));
 | 
					        })));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,6 +36,14 @@ class I18nTest extends KernelTestCase
 | 
				
			|||||||
        I18n::setTranslator($translator);
 | 
					        I18n::setTranslator($translator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        static::assertSame('test string', _m('test string'));
 | 
					        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'];
 | 
					        $apples = [1 => '1 apple', '# apples'];
 | 
				
			||||||
        static::assertSame('-42 apples',  _m($apples, ['count' => -42]));
 | 
					        static::assertSame('-42 apples',  _m($apples, ['count' => -42]));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,8 +18,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Tests\Entity;
 | 
					namespace App\Tests\Entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\Entity\Poll;
 | 
					 | 
				
			||||||
use PHPUnit\Framework\TestCase;
 | 
					use PHPUnit\Framework\TestCase;
 | 
				
			||||||
 | 
					use Plugin\Poll\Entity\Poll;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PollTest extends TestCase
 | 
					class PollTest extends TestCase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user