diff options
author | Igor Wiedler <igor@wiedler.ch> | 2011-01-10 00:18:37 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2011-01-10 00:18:37 +0100 |
commit | 01fe91c5c4e897801f5c179cd4060e686762f105 (patch) | |
tree | 178535f1cecfa2fd5748b21f9d59d1d471d1bd35 /tests/random/gen_rand_string_test.php | |
parent | 0a945100fd285658f1c3c936d413939eb11a6e16 (diff) | |
download | forums-01fe91c5c4e897801f5c179cd4060e686762f105.tar forums-01fe91c5c4e897801f5c179cd4060e686762f105.tar.gz forums-01fe91c5c4e897801f5c179cd4060e686762f105.tar.bz2 forums-01fe91c5c4e897801f5c179cd4060e686762f105.tar.xz forums-01fe91c5c4e897801f5c179cd4060e686762f105.zip |
[ticket/9987] Rename test files to include a _test suffix
PHPBB3-9987
Diffstat (limited to 'tests/random/gen_rand_string_test.php')
-rw-r--r-- | tests/random/gen_rand_string_test.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/random/gen_rand_string_test.php b/tests/random/gen_rand_string_test.php new file mode 100644 index 0000000000..fa519f134c --- /dev/null +++ b/tests/random/gen_rand_string_test.php @@ -0,0 +1,62 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once __DIR__ . '/../../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); + } + } + } +} |