Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
'moo',
'0' => 'foobar',
'abc' => '-1',
'ab"c"' => '2.0',
'ab"c"2' => 'k"lm"',
'ab\'c\'' => 'nop',
"ab\'c\'2" => "qr\'s\'"
);
$_COOKIE = array(
'somecookie' => '"a var"',
'another"value"' => "isn't it cool"
);
$_POST = array(
'nest' => array(
'foobar' => '"test"',
'"hi"' => 'test\'ing'
)
);
// simulate magic quotes GPC
/*foreach (array($_GET, $_COOKIE) as $array)
{
foreach ($array as $var => $value)
{
$array["$var"] = addslashes($value);
}
}*/
require_once ISSO . '/App.php';
require_once ISSO . '/Input.php';
$this->fixture = new BSInput();
}
public function testSanitizeInputData()
{
$this->assertEquals(10, sizeof($this->fixture->in));
$this->assertEquals(2, sizeof($this->fixture->in['nest']));
$this->assertEquals('"a var"', $this->fixture->in['somecookie']);
$this->assertEquals('test\'ing', $this->fixture->in['nest']['"hi"']);
}
public function testEntityEncode()
{
$this->assertEquals('<a href="http://www.something.com/test.php?do=run&moo=foo">', $this->fixture->entityEncode(''));
}
public function testUnsanitize()
{
$this->assertEquals('', $this->fixture->unsanitize(''));
$this->assertEquals('', $this->fixture->unsanitize('<script type="text/javascript"> alert("XSS is fun!"); </script>'));
$this->assertEquals('', $this->fixture->unsanitize($this->fixture->sanitize('')));
}
public function testClean()
{
$this->assertEquals(0, $this->fixture->clean('abc', TYPE_INT));
$this->assertEquals(-1, $this->fixture->clean('-1', TYPE_INT));
$this->assertEquals(4, $this->fixture->clean('4def', TYPE_INT));
$this->assertEquals(0, $this->fixture->clean('abc', TYPE_UINT));
$this->assertEquals(0, $this->fixture->clean(-100, TYPE_UINT));
$this->assertEquals(40, $this->fixture->clean('40.965', TYPE_UINT));
$this->assertEquals(0, $this->fixture->clean('0.0', TYPE_FLOAT));
$this->assertNotEquals(0, $this->fixture->clean('0.032', TYPE_FLOAT));
$this->assertEquals(true, $this->fixture->clean('aafsdfa', TYPE_BOOL));
$this->assertEquals(false, $this->fixture->clean('', TYPE_BOOL));
$this->assertEquals(false, $this->fixture->clean('0', TYPE_BOOL));
$this->assertEquals(true, $this->fixture->clean('0.0', TYPE_BOOL));
$this->assertEquals('', $this->fixture->clean('', TYPE_STR));
$this->assertEquals('', $this->fixture->clean('', TYPE_STRUN));
$this->assertEquals('', $this->fixture->clean($this->fixture->sanitize(''), TYPE_STRUN));
$this->assertEquals('', $this->fixture->clean('', TYPE_NONE));
$this->assertEquals('åß∂ƒ(c)˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', $this->fixture->clean('åß∂ƒ(c)˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', TYPE_BIN));
try
{
$this->fixture->clean('asdfa', TYPE_THIS_DOES_NOT_EXIST);
$this->fail('exception expected');
}
catch (Exception $e)
{}
}
public function testCleanArray()
{
$array = array(
'a' => '1',
'b' => '2.7',
'c' => 'adfasdf',
'd' => '-12'
);
$newarray = $this->fixture->clean($array, TYPE_UINT);
$this->assertEquals(4, sizeof($newarray));
$this->assertEquals(1, $newarray['a']);
$this->assertEquals(2, $newarray['b']);
$this->assertEquals(0, $newarray['c']);
$this->assertEquals(0, $newarray['d']);
}
public function testInputClean()
{
$this->assertEquals(-1.0, $this->fixture->inputClean('abc', TYPE_FLOAT));
$this->assertEquals(-1.0, $this->fixture->in['abc']);
$this->assertEquals('', $this->fixture->inputClean(':does:not:exist', TYPE_STR));
}
public function testInputCleanArray()
{
$this->fixture->inputCleanArray(array(
'abc' => TYPE_FLOAT,
'ab"c"' => TYPE_INT
));
$this->assertEquals(-1.0, $this->fixture->in['abc']);
$this->assertEquals(2, $this->fixture->in['ab"c"']);
}
public function testEscape()
{
$this->assertEquals("this isn\'t a test", $this->fixture->escape("this isn't a test", true));
}
public function testInputEscape()
{
$this->assertEquals("isn\'t it cool", $this->fixture->inputEscape('another"value"'));
$this->assertEquals('', $this->fixture->inputEscape(':will:never:exist'));
}
public function testPostCheck()
{
}
}
?>