2014-05-07 14:05:13 -04:00
< ? php
2014-05-14 20:32:30 -04:00
use Sleepy\Core\Input ;
2014-05-07 14:05:13 -04:00
class InputTest extends Sleepy_TestCase {
public function setUp ()
{
parent :: setUp ();
// Set some http headers as test items
$_SERVER [ 'HTTP_USER_AGENT' ] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36 OPR/18.0.1284.49' ;
$_SERVER [ 'HTTP_ACCEPT' ] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' ;
$_SERVER [ 'HTTP_COOKIE' ] = 'thp_tcms_session_id=9h4nvk15tjjegbeg8uvejncc9blkd81m' ;
$_SERVER [ 'HTTP_HOST' ] = 'www.example.com' ;
$_SERVER [ 'HTTP_FOO' ] = 'foo,bar' ;
// Set test $_COOKIE array
$_COOKIE = [
'thp_tcms_session_id' => '9h4nvk15tjjegbeg8uvejncc9blkd81m'
];
// Set test $_GET array
$_GET = [
'foo' => 'bar' ,
'baz' => 'foobar'
];
// Set test $_POST array
$_POST = [
'this' => 'that' ,
'tisket' => 'tasket'
];
2014-05-14 20:32:30 -04:00
$this -> input = new Input ();
2014-05-07 14:05:13 -04:00
}
public function dataTestHeader ()
{
return [
'all' => [
'index' => NULL ,
'expected' => [
2014-05-14 10:32:31 -04:00
'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36 OPR/18.0.1284.49' ,
2014-05-07 14:05:13 -04:00
'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' ,
'cookie' => 'thp_tcms_session_id=9h4nvk15tjjegbeg8uvejncc9blkd81m' ,
'host' => 'www.example.com' ,
'foo' => 'foo,bar'
]
],
'index' => [
'index' => 'cookie' ,
'expected' => 'thp_tcms_session_id=9h4nvk15tjjegbeg8uvejncc9blkd81m'
],
'invalid' => [
'index' => 'boo' ,
'expected' => NULL
]
];
}
public function dataHeaderArray ()
{
return [
'all' => [
'index' => NULL ,
'expected' => [
2014-05-14 10:32:31 -04:00
'user-agent' => [
2014-05-07 14:05:13 -04:00
'versions' => [
'Mozilla' => '5.0' ,
'AppleWebKit' => '537.36' ,
'Chrome' => '31.0.1650.57' ,
'Safari' => '537.36' ,
'OPR' => '18.0.1284.49' ,
],
'os' => [
'Macintosh' ,
'Intel Mac OS X 10_9_0' ,
],
'misc' => 'KHTML, like Gecko'
],
'accept' => [
2014-05-14 10:32:31 -04:00
'0.8' => '*/*' ,
'0.9' => 'application/xml' ,
1 => 'application/xhtml+xml' ,
2 => 'text/html'
2014-05-07 14:05:13 -04:00
],
'cookie' => [
'thp_tcms_session_id' => '9h4nvk15tjjegbeg8uvejncc9blkd81m'
],
'host' => 'www.example.com' ,
'foo' => [
'foo' ,
'bar'
]
]
],
'index' => [
'index' => 'cookie' ,
'expected' => [
'thp_tcms_session_id' => '9h4nvk15tjjegbeg8uvejncc9blkd81m'
]
],
'invalid' => [
'index' => 'red' ,
'expected' => NULL
]
];
}
public function dataTestPost ()
{
return [
'all' => [
'index' => NULL ,
'expected' => [
'this' => 'that' ,
'tisket' => 'tasket'
]
],
'index' => [
'index' => 'this' ,
'expected' => 'that'
],
'invalid' => [
'index' => 'puppies' ,
'expected' => NULL
]
];
}
public function dataTestGet ()
{
return [
'all' => [
'index' => NULL ,
'expected' => [
'foo' => 'bar' ,
'baz' => 'foobar'
]
],
'index' => [
'index' => 'foo' ,
'expected' => 'bar'
],
'invalid' => [
'index' => 'applesauce' ,
'expected' => NULL
]
];
}
/**
* @ dataProvider dataTestHeader
*/
public function testHeader ( $index , $expected )
{
$res = $this -> input -> header ( $index );
$this -> assertEquals ( $expected , $res );
}
/**
* @ dataProvider dataHeaderArray
*/
public function testHeaderArray ( $index , $expected )
{
$result = $this -> input -> header_array ( $index );
$this -> assertEquals ( $expected , $result );
}
/**
* @ dataProvider dataTestPost
*/
public function testPost ( $index , $expected )
{
$result = $this -> input -> post ( $index );
$this -> assertEquals ( $expected , $result );
}
/**
* @ dataProvider dataTestGet
*/
public function testGet ( $index , $expected )
{
$result = $this -> input -> get ( $index );
$this -> assertEquals ( $expected , $result );
}
2014-05-14 10:32:31 -04:00
public function testBadVar ()
{
try {
$foo = $this -> input -> applesauce ();
}
catch ( DomainException $e ) {
$this -> assertTrue ( true );
}
}
2014-05-07 14:05:13 -04:00
}
// End of InputTest.php