aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-06-11 16:02:11 -0400
committerOleg Pudeyev <oleg@bsdpower.com>2012-06-11 16:02:11 -0400
commit300b420e01b7fc800122d9d12c10679d077e2f8a (patch)
tree0eb2158c64ce42365c9e5a4b9f0826c408553458 /tests
parent4af503e11bc2c42654cf783f031bdb074fdd91ed (diff)
parent4468847107103c44936468e6e3c1badeb333ff52 (diff)
downloadforums-300b420e01b7fc800122d9d12c10679d077e2f8a.tar
forums-300b420e01b7fc800122d9d12c10679d077e2f8a.tar.gz
forums-300b420e01b7fc800122d9d12c10679d077e2f8a.tar.bz2
forums-300b420e01b7fc800122d9d12c10679d077e2f8a.tar.xz
forums-300b420e01b7fc800122d9d12c10679d077e2f8a.zip
Merge PR #834 branch 'bantu/ticket/10931' into develop
* bantu/ticket/10931: [ticket/10931] Apply strtolower() correctly, i.e. not on false. [ticket/10931] Also test get_bytes() and get_string() with false. [ticket/10931] Make to_numeric function globally available. [ticket/10931] Make sure get_bytes() always returns either an int or a float. [ticket/10931] Correctly handle inputs such as '-k' as invalid in get_bytes(). [ticket/10931] Use strict assertSame() instead of assertEquals(). [ticket/10931] Also test for negative values. [ticket/10931] Also test lower case units in test_get_bytes(). [ticket/10931] Correctly use GNU GPL version 2. [ticket/10931] Make it clear that we are mocking the ini_get() function. [ticket/10931] Document that false is also returned if value is not well formed [ticket/10931] Correct method description of get_string(). [ticket/10931] Let us try ini_get() without error suppression. [ticket/10931] Unit tests for phpbb_php_ini class. [ticket/10931] Add wrapper class for ini_get function.
Diffstat (limited to 'tests')
-rw-r--r--tests/wrapper/phpbb_php_ini_fake.php16
-rw-r--r--tests/wrapper/phpbb_php_ini_test.php86
2 files changed, 102 insertions, 0 deletions
diff --git a/tests/wrapper/phpbb_php_ini_fake.php b/tests/wrapper/phpbb_php_ini_fake.php
new file mode 100644
index 0000000000..49bc5936e5
--- /dev/null
+++ b/tests/wrapper/phpbb_php_ini_fake.php
@@ -0,0 +1,16 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_php_ini_fake extends phpbb_php_ini
+{
+ function get($varname)
+ {
+ return $varname;
+ }
+}
diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php
new file mode 100644
index 0000000000..8e08d5c204
--- /dev/null
+++ b/tests/wrapper/phpbb_php_ini_test.php
@@ -0,0 +1,86 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/phpbb_php_ini_fake.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case
+{
+ protected $php_ini;
+
+ public function setUp()
+ {
+ $this->php_ini = new phpbb_php_ini_fake;
+ }
+
+ public function test_get_string()
+ {
+ $this->assertSame(false, $this->php_ini->get_string(false));
+ $this->assertSame('phpbb', $this->php_ini->get_string(' phpbb '));
+ }
+
+ public function test_get_bool()
+ {
+ $this->assertSame(true, $this->php_ini->get_bool('ON'));
+ $this->assertSame(true, $this->php_ini->get_bool('on'));
+ $this->assertSame(true, $this->php_ini->get_bool('1'));
+
+ $this->assertSame(false, $this->php_ini->get_bool('OFF'));
+ $this->assertSame(false, $this->php_ini->get_bool('off'));
+ $this->assertSame(false, $this->php_ini->get_bool('0'));
+ $this->assertSame(false, $this->php_ini->get_bool(''));
+ }
+
+ public function test_get_int()
+ {
+ $this->assertSame(1234, $this->php_ini->get_int('1234'));
+ $this->assertSame(-12345, $this->php_ini->get_int('-12345'));
+ $this->assertSame(false, $this->php_ini->get_int('phpBB'));
+ }
+
+ public function test_get_float()
+ {
+ $this->assertSame(1234.0, $this->php_ini->get_float('1234'));
+ $this->assertSame(-12345.0, $this->php_ini->get_float('-12345'));
+ $this->assertSame(false, $this->php_ini->get_float('phpBB'));
+ }
+
+ public function test_get_bytes_invalid()
+ {
+ $this->assertSame(false, $this->php_ini->get_bytes(false));
+ $this->assertSame(false, $this->php_ini->get_bytes('phpBB'));
+ $this->assertSame(false, $this->php_ini->get_bytes('k'));
+ $this->assertSame(false, $this->php_ini->get_bytes('-k'));
+ $this->assertSame(false, $this->php_ini->get_bytes('M'));
+ $this->assertSame(false, $this->php_ini->get_bytes('-M'));
+ }
+
+ /**
+ * @dataProvider get_bytes_data
+ */
+ public function test_get_bytes($expected, $value)
+ {
+ $actual = $this->php_ini->get_bytes($value);
+
+ $this->assertTrue(is_float($actual) || is_int($actual));
+ $this->assertEquals($expected, $actual);
+ }
+
+ static public function get_bytes_data()
+ {
+ return array(
+ array(32 * pow(2, 20), '32m'),
+ array(- 32 * pow(2, 20), '-32m'),
+ array(8 * pow(2, 30), '8G'),
+ array(- 8 * pow(2, 30), '-8G'),
+ array(1234, '1234'),
+ array(-12345, '-12345'),
+ );
+ }
+}