aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functions')
-rw-r--r--tests/functions/clean_path_test.php44
-rw-r--r--tests/functions/get_formatted_filesize_test.php71
2 files changed, 115 insertions, 0 deletions
diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php
new file mode 100644
index 0000000000..bcbe9838d9
--- /dev/null
+++ b/tests/functions/clean_path_test.php
@@ -0,0 +1,44 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_clean_path_test extends phpbb_test_case
+{
+ public function clean_path_test_data()
+ {
+ return array(
+ array('foo', 'foo'),
+ array('foo/bar', 'foo/bar'),
+ array('foo/bar/', 'foo/bar/'),
+ array('foo/./bar', 'foo/bar'),
+ array('foo/./././bar', 'foo/bar'),
+ array('foo/bar/.', 'foo/bar'),
+ array('./foo/bar', './foo/bar'),
+ array('../foo/bar', '../foo/bar'),
+ array('one/two/three', 'one/two/three'),
+ array('one/two/../three', 'one/three'),
+ array('one/../two/three', 'two/three'),
+ array('one/two/..', 'one'),
+ array('one/two/../', 'one/'),
+ array('one/two/../three/../four', 'one/four'),
+ array('one/two/three/../../four', 'one/four'),
+ );
+ }
+
+ /**
+ * @dataProvider clean_path_test_data
+ */
+ public function test_clean_path($input, $expected)
+ {
+ $output = phpbb_clean_path($input);
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php
new file mode 100644
index 0000000000..96ea2be132
--- /dev/null
+++ b/tests/functions/get_formatted_filesize_test.php
@@ -0,0 +1,71 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_get_formatted_filesize_test extends phpbb_test_case
+{
+ public function get_formatted_filesize_test_data()
+ {
+ return array(
+ // exact powers of 2
+ array(1, '1 BYTES'),
+ array(1024, '1 KIB'),
+ array(1048576, '1 MIB'),
+ array(1073741824, '1 GIB'),
+ array(1099511627776, '1 TIB'),
+
+ // exact powers of 10
+ array(1000, '1000 BYTES'),
+ array(1000000, '976.56 KIB'),
+ array(1000000000, '953.67 MIB'),
+ array(1000000000000, '931.32 GIB'),
+ array(100000000000000, '90.95 TIB'),
+
+ array(0, '0 BYTES'),
+ array(2, '2 BYTES'),
+
+ array(1023, '1023 BYTES'),
+ array(1025, '1 KIB'),
+ array(1048575, '1024 KIB'),
+
+ // String values
+ // exact powers of 2
+ array('1', '1 BYTES'),
+ array('1024', '1 KIB'),
+ array('1048576', '1 MIB'),
+ array('1073741824', '1 GIB'),
+ array('1099511627776', '1 TIB'),
+
+ // exact powers of 10
+ array('1000', '1000 BYTES'),
+ array('1000000', '976.56 KIB'),
+ array('1000000000', '953.67 MIB'),
+ array('1000000000000', '931.32 GIB'),
+ array('100000000000000', '90.95 TIB'),
+
+ array('0', '0 BYTES'),
+ array('2', '2 BYTES'),
+
+ array('1023', '1023 BYTES'),
+ array('1025', '1 KIB'),
+ array('1048575', '1024 KIB'),
+ );
+ }
+
+ /**
+ * @dataProvider get_formatted_filesize_test_data
+ */
+ public function test_get_formatted_filesize($input, $expected)
+ {
+ $output = get_formatted_filesize($input);
+
+ $this->assertEquals($expected, $output);
+ }
+}