Phalcon\Test\Unit\Security\RandomTest::testRandomBase64Safe PHP Метод

testRandomBase64Safe() публичный Метод

Tests the random base64 generation
С версии: 2015-08-17
Автор: Serghei Iakovlev ([email protected])
    public function testRandomBase64Safe()
    {
        $this->specify("base64Safe does not generate a valid string", function () {
            $lens = [2, 12, 16, 24, 48, 100];
            $random = new Random();
            $isValid = function ($base64, $padding = false) {
                $pattern = $padding ? "a-z0-9_=-" : "a-z0-9_-";
                return preg_match("#[^{$pattern}]+#i", $base64) === 0;
            };
            foreach ($lens as $len) {
                $actual = $random->base64Safe($len);
                expect($isValid($actual))->true();
            }
            $actual = $random->base64Safe();
            expect($isValid($actual))->true();
            $actual = $random->base64Safe(null, true);
            expect($isValid($actual, true))->true();
        });
    }