aboutsummaryrefslogtreecommitdiffstats
path: root/tests/random
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2010-08-20 21:12:18 +0200
committerAndreas Fischer <bantu@phpbb.com>2010-08-20 21:36:56 +0200
commite09d6c6d7139375d8b645664bef295c82d585653 (patch)
treeadac210bb4b597ad822feb7429b61b35d97b47b8 /tests/random
parentd53312174169f311714da389b6a36fe6a4bc8f9a (diff)
downloadforums-e09d6c6d7139375d8b645664bef295c82d585653.tar
forums-e09d6c6d7139375d8b645664bef295c82d585653.tar.gz
forums-e09d6c6d7139375d8b645664bef295c82d585653.tar.bz2
forums-e09d6c6d7139375d8b645664bef295c82d585653.tar.xz
forums-e09d6c6d7139375d8b645664bef295c82d585653.zip
[ticket/9780] Adding unit tests for gen_rand_string().
PHPBB3-9780
Diffstat (limited to 'tests/random')
-rw-r--r--tests/random/all_tests.php40
-rw-r--r--tests/random/gen_rand_string.php63
2 files changed, 103 insertions, 0 deletions
diff --git a/tests/random/all_tests.php b/tests/random/all_tests.php
new file mode 100644
index 0000000000..c6ffe78024
--- /dev/null
+++ b/tests/random/all_tests.php
@@ -0,0 +1,40 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+if (!defined('PHPUnit_MAIN_METHOD'))
+{
+ define('PHPUnit_MAIN_METHOD', 'phpbb_random_all_tests::main');
+}
+
+require_once 'test_framework/framework.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+
+require_once 'random/gen_rand_string.php';
+
+class phpbb_random_all_tests
+{
+ public static function main()
+ {
+ PHPUnit_TextUI_TestRunner::run(self::suite());
+ }
+
+ public static function suite()
+ {
+ $suite = new PHPUnit_Framework_TestSuite('phpBB Random Functions');
+
+ $suite->addTestSuite('phpbb_random_gen_rand_string_test');
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'phpbb_random_all_tests::main')
+{
+ phpbb_random_all_tests::main();
+}
diff --git a/tests/random/gen_rand_string.php b/tests/random/gen_rand_string.php
new file mode 100644
index 0000000000..cd58d14ed3
--- /dev/null
+++ b/tests/random/gen_rand_string.php
@@ -0,0 +1,63 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once 'test_framework/framework.php';
+require_once '../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);
+ }
+ }
+ }
+}