. namespace hoplite\test; use hoplite\http\Input; require_once HOPLITE_ROOT . '/http/input.php'; /** * @backupGlobals enabled */ class InputTest extends \PHPUnit_Framework_TestCase { public function setUp() { $_GET = array( 'gint' => '12', 'gfloat' => '3.14', 'gstr' => '"Hello World"', 'ghtml' => '"Hello World"', 'gbool' => 'True', ); $_POST = array( 'pstr' => '', 'pbool' => 'YES', 'parray' => array('13', 15, '19', '22.23'), ); $_REQUEST = array_merge($_GET, $_POST); } public function testDefaultMode() { $input = new Input(); $this->assertEquals('"Hello World"', $input->in['gstr']); $input = new Input(Input::TYPE_RAW); $this->assertArrayNotHasKey('gstr', $input->in); } public function testClean() { $input = new Input(); $this->assertSame(12, $input->Clean('gint', Input::TYPE_INT)); $this->assertSame(12, $input->in['gint']); } public function testCleanArray() { $input = new Input(); $input->CleanArray(array( 'gfloat' => Input::TYPE_FLOAT, 'pbool' => Input::TYPE_BOOL, )); $this->assertSame(3.14, $input->in['gfloat']); $this->assertSame(TRUE, $input->in['pbool']); } public function testInputCleanDeep() { $input = new Input(); $test = $input->InputCleanDeep('p', 'parray', Input::TYPE_UINT); $this->assertSame(array(13, 15, 19, 22), $test); $this->assertSame($test, $input->in['parray']); } }