3 // Copyright (c) 2013 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite
\test
;
18 use hoplite\http\Input
;
20 require_once HOPLITE_ROOT
. '/http/input.php';
23 * @backupGlobals enabled
25 class InputTest
extends \PHPUnit_Framework_TestCase
27 public function setUp()
32 'gstr' => '"Hello World"',
33 'ghtml' => '<blink>"Hello World"</blink>',
37 'pstr' => '<script type="text/javascript"> alert("Hello world"); </script>',
39 'parray' => array('13', 15, '19', '22.23'),
41 $_REQUEST = array_merge($_GET, $_POST);
44 public function testDefaultMode()
47 $this->assertEquals('"Hello World"', $input->in
['gstr']);
49 $input = new Input(Input
::TYPE_RAW
);
50 $this->assertArrayNotHasKey('gstr', $input->in
);
53 public function testClean()
56 $this->assertSame(12, $input->Clean('gint', Input
::TYPE_INT
));
57 $this->assertSame(12, $input->in
['gint']);
60 public function testCleanArray()
63 $input->CleanArray(array(
64 'gfloat' => Input
::TYPE_FLOAT
,
65 'pbool' => Input
::TYPE_BOOL
,
67 $this->assertSame(3.14, $input->in
['gfloat']);
68 $this->assertSame(TRUE
, $input->in
['pbool']);
71 public function testInputCleanDeep()
74 $test = $input->InputCleanDeep('p', 'parray', Input
::TYPE_UINT
);
75 $this->assertSame(array(13, 15, 19, 22), $test);
76 $this->assertSame($test, $input->in
['parray']);