diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-09-27 12:40:03 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-09-27 12:40:03 +0200 |
commit | 3c7cda8a8cf885aedbb44731a16e9d32e606dea8 (patch) | |
tree | 431655d4171246c62aa66ed16cdfd35c1ccd9dde /_test | |
parent | 3df1d4a6fec3db26f0cb9888fdbf9fe67359c9ee (diff) | |
parent | 1dc0e65fa0933a1ad6ef9a73c35feb81c96f2961 (diff) | |
download | rpg-3c7cda8a8cf885aedbb44731a16e9d32e606dea8.tar.gz rpg-3c7cda8a8cf885aedbb44731a16e9d32e606dea8.tar.bz2 |
Merge pull request #869 from splitbrain/filter
added filter method to INPUT class
Diffstat (limited to '_test')
-rw-r--r-- | _test/tests/inc/input.test.php | 50 |
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; |