mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-23 11:28:33 +01:00
Due to the usage of `__DIR__` for the file includes the tests can't be ran on systems with PHP < 5.3. Replace all occurances of `__DIR__` with `dirname(__FILE__)`. PHPBB3-10011
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* @package testing
|
|
* @copyright (c) 2010 phpBB Group
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
*
|
|
*/
|
|
|
|
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
|
|
|
class phpbb_random_gen_rand_string_test extends phpbb_test_case
|
|
{
|
|
const TEST_COUNT = 100;
|
|
const MIN_STRING_LENGTH = 1;
|
|
const MAX_STRING_LENGTH = 15;
|
|
|
|
public function setUp()
|
|
{
|
|
global $config;
|
|
|
|
if (!is_array($config))
|
|
{
|
|
$config = array();
|
|
}
|
|
|
|
$config['rand_seed'] = '';
|
|
$config['rand_seed_last_update'] = time() + 600;
|
|
}
|
|
|
|
public function test_gen_rand_string()
|
|
{
|
|
for ($tests = 0; $tests <= self::TEST_COUNT; ++$tests)
|
|
{
|
|
for ($num_chars = self::MIN_STRING_LENGTH; $num_chars <= self::MAX_STRING_LENGTH; ++$num_chars)
|
|
{
|
|
$random_string = gen_rand_string($num_chars);
|
|
$random_string_length = strlen($random_string);
|
|
|
|
$this->assertTrue($random_string_length >= self::MIN_STRING_LENGTH);
|
|
$this->assertTrue($random_string_length <= $num_chars);
|
|
$this->assertRegExp('#^[A-Z0-9]+$#', $random_string);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_gen_rand_string_friendly()
|
|
{
|
|
for ($tests = 0; $tests <= self::TEST_COUNT; ++$tests)
|
|
{
|
|
for ($num_chars = self::MIN_STRING_LENGTH; $num_chars <= self::MAX_STRING_LENGTH; ++$num_chars)
|
|
{
|
|
$random_string = gen_rand_string_friendly($num_chars);
|
|
$random_string_length = strlen($random_string);
|
|
|
|
$this->assertTrue($random_string_length >= self::MIN_STRING_LENGTH);
|
|
$this->assertTrue($random_string_length <= $num_chars);
|
|
$this->assertRegExp('#^[A-NP-Z1-9]+$#', $random_string);
|
|
}
|
|
}
|
|
}
|
|
}
|