summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-09-23 20:08:09 +0200
committerAndreas Gohr <andi@splitbrain.org>2014-09-23 20:08:09 +0200
commit37abef5f8744159697aa2dc18cc468477f2ca965 (patch)
treef159c6c82dcaf4b20f2133db0480d4b084d3d95c /_test
parent1ee9b48eeac0acdc23d10bc12e2efa22a01f9989 (diff)
downloadrpg-37abef5f8744159697aa2dc18cc468477f2ca965.tar.gz
rpg-37abef5f8744159697aa2dc18cc468477f2ca965.tar.bz2
added filter method to INPUT class
the filter() function can be chained between the accessor and the value function to get a filtered value. When no filter allable is given in the filter() function, stripctl() is used to strip all control chars (ASCII<32) Examples: $INPUT->post->filter()->str('foobar'); $INPUT->get->filter('myfilter')->int('baz');
Diffstat (limited to '_test')
-rw-r--r--_test/tests/inc/input.test.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/_test/tests/inc/input.test.php b/_test/tests/inc/input.test.php
index cec0b80f6..4a8fb8d71 100644
--- a/_test/tests/inc/input.test.php
+++ b/_test/tests/inc/input.test.php
@@ -14,8 +14,58 @@ class input_test extends DokuWikiTest {
'empty' => '',
'emptya' => array(),
'do' => array('save' => 'Speichern'),
+
);
+ /**
+ * custom filter function
+ *
+ * @param $string
+ * @return mixed
+ */
+ public function myfilter($string) {
+ $string = str_replace('foo', 'bar', $string);
+ $string = str_replace('baz', '', $string);
+ return $string;
+ }
+
+ public function test_filter() {
+ $_GET = array(
+ 'foo' => 'foo',
+ 'zstring'=> "foo\0bar",
+ 'znull' => "\0",
+ 'zint' => '42'."\0".'42',
+ 'zintbaz'=> "baz42",
+ );
+ $_POST = $_GET;
+ $_REQUEST = $_GET;
+ $INPUT = new Input();
+
+ $filter = array($this,'myfilter');
+
+ $this->assertNotSame('foobar', $INPUT->str('zstring'));
+ $this->assertSame('foobar', $INPUT->filter()->str('zstring'));
+ $this->assertSame('bar', $INPUT->filter($filter)->str('foo'));
+ $this->assertSame('bar', $INPUT->filter()->str('znull', 'bar', true));
+ $this->assertNotSame('foobar', $INPUT->str('zstring')); // make sure original input is unmodified
+
+ $this->assertNotSame('foobar', $INPUT->get->str('zstring'));
+ $this->assertSame('foobar', $INPUT->get->filter()->str('zstring'));
+ $this->assertSame('bar', $INPUT->get->filter($filter)->str('foo'));
+ $this->assertSame('bar', $INPUT->get->filter()->str('znull', 'bar', true));
+ $this->assertNotSame('foobar', $INPUT->get->str('zstring')); // make sure original input is unmodified
+
+ $this->assertNotSame(4242, $INPUT->int('zint'));
+ $this->assertSame(4242, $INPUT->filter()->int('zint'));
+ $this->assertSame(42, $INPUT->filter($filter)->int('zintbaz'));
+ $this->assertSame(42, $INPUT->filter()->str('znull', 42, true));
+
+ $this->assertSame(true, $INPUT->bool('znull'));
+ $this->assertSame(false, $INPUT->filter()->bool('znull'));
+
+ $this->assertSame('foobar', $INPUT->filter()->valid('zstring', array('foobar', 'bang')));
+ }
+
public function test_str() {
$_REQUEST = $this->data;
$_POST = $this->data;