Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2021-11-06 17:08:49 +0300
committerAleksander Machniak <alec@alec.pl>2021-11-06 17:08:49 +0300
commit9871b04b1390f883f0379677672b7f0af57a95cc (patch)
tree7bf0bec9f39981afb8e2a439f9dea51094852850 /tests
parentd4cfb94c3db7b2719315ca596a59b777943c8d21 (diff)
Fix an infinite loop when parsing environment variables with float/integer values (#8293)
Diffstat (limited to 'tests')
-rw-r--r--tests/Framework/Config.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/Framework/Config.php b/tests/Framework/Config.php
index 5c521cf09..700e8f3f8 100644
--- a/tests/Framework/Config.php
+++ b/tests/Framework/Config.php
@@ -26,4 +26,71 @@ class Framework_Config extends PHPUnit\Framework\TestCase
$this->assertSame('UTC', rcube_config::resolve_timezone_alias('Etc/GMT'));
$this->assertSame('UTC', rcube_config::resolve_timezone_alias('Etc/Zulu'));
}
+
+ /**
+ * Test get() and set()
+ */
+ function test_get_and_set()
+ {
+ $object = new rcube_config();
+
+ $this->assertSame(null, $object->get('test'));
+ $this->assertSame('def', $object->get('test', 'def'));
+
+ $object->set('test', 'val');
+
+ $this->assertSame('val', $object->get('test'));
+
+ putenv('ROUNDCUBE_TEST_INT=4190');
+
+ $this->assertSame(4190, $object->get('test_int'));
+
+ // TODO: test more code paths in get() and set()
+ }
+
+ /**
+ * Test guess_type()
+ */
+ function test_guess_type()
+ {
+ $object = new rcube_config();
+
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['true']));
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['false']));
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['t']));
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['f']));
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['TRUE']));
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['FALSE']));
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['T']));
+ $this->assertSame('bool', invokeMethod($object, 'guess_type', ['F']));
+
+ $this->assertSame('float', invokeMethod($object, 'guess_type', ['1.5']));
+ $this->assertSame('float', invokeMethod($object, 'guess_type', ['1.0']));
+ $this->assertSame('float', invokeMethod($object, 'guess_type', ['1.2e3']));
+ $this->assertSame('float', invokeMethod($object, 'guess_type', ['7E-10']));
+
+ $this->assertSame('int', invokeMethod($object, 'guess_type', ['1']));
+ $this->assertSame('int', invokeMethod($object, 'guess_type', ['123456789']));
+
+ $this->assertSame('string', invokeMethod($object, 'guess_type', ['ON']));
+ $this->assertSame('string', invokeMethod($object, 'guess_type', ['1-0']));
+ }
+
+ /**
+ * Test parse_env()
+ */
+ function test_parse_env()
+ {
+ $object = new rcube_config();
+
+ $this->assertSame(true, invokeMethod($object, 'parse_env', ['true']));
+ $this->assertSame(1, invokeMethod($object, 'parse_env', ['1']));
+ $this->assertSame(1.5, invokeMethod($object, 'parse_env', ['1.5']));
+ $this->assertSame(true, invokeMethod($object, 'parse_env', ['1', 'bool']));
+ $this->assertSame(1.0, invokeMethod($object, 'parse_env', ['1', 'float']));
+ $this->assertSame(1, invokeMethod($object, 'parse_env', ['1', 'int']));
+ $this->assertSame('1', invokeMethod($object, 'parse_env', ['1', 'string']));
+ $this->assertSame([1], invokeMethod($object, 'parse_env', ['[1]', 'array']));
+ $this->assertSame(['test' => 1], (array) invokeMethod($object, 'parse_env', ['{"test":1}', 'object']));
+ }
}