diff --git a/include/filter.php b/include/filter.php index ddf30d8..de98d47 100644 --- a/include/filter.php +++ b/include/filter.php @@ -1,19 +1,39 @@ diff --git a/unit_test/run_tests.php b/unit_test/run_tests.php index 4d9a8e9..a33e830 100644 --- a/unit_test/run_tests.php +++ b/unit_test/run_tests.php @@ -20,4 +20,6 @@ echo "\n"; include_once("test_application.php"); echo "\n"; include_once("test_error_log.php"); +echo "\n"; +include_once("test_filter.php"); ?> diff --git a/unit_test/test_filter.php b/unit_test/test_filter.php new file mode 100644 index 0000000..0eaf3d5 --- /dev/null +++ b/unit_test/test_filter.php @@ -0,0 +1,133 @@ +This is some html"; + $_REQUEST['shHtml'] = $shHtml; + + // filter the variables and make sure that we don't have a return value + // ie, that filtering succeeded + $sResult = filter_gpc(); + if($sResult) + { + echo "sResult is '$sResult' but we expected success and no return value\n"; + return false; + } + + // expect that the filtered value will be equal + if($aClean['shHtml'] != $shHtml) + { + echo "Expected aClean['shHtml'] to be '".$shHtml."' but instead it was '".$aClean['shHtml']."'\n"; + return false; + } + + + //***************************************************************************** + // test that filtering strings with html results in the tags being stripped out + $_REQUEST = array(); // clear out the array + $sHtml = "
This is some html"; + $_REQUEST['sHtml'] = $sHtml; + + // filter the variables and make sure that we don't have a return value + // ie, that filtering succeeded + $sResult = filter_gpc(); + if($sResult) + { + echo "sResult is '$sResult' but we expected success and no return value\n"; + return false; + } + + // expect that $aClean value has been modified during filtering so these + // shouldn't be equal unless something has failed + if($aClean['sHtml'] == $sHtml) + { + echo "Expected aClean['shHtml'] to be '".$sHtml."' but instead it was '".$aClean['sHtml']."'\n"; + return false; + } + + // make sure all html has been stripped + if(strip_tags($aClean['sHtml']) != $aClean['sHtml']) + { + echo "Expected all html to be stripped already but we were able to strip this '".$aClean['sHtml'] + ."' into '".strip_tags($aClean['sHtml'])."'\n"; + return false; + } + + + return true; +} + + +/*************************/ +/* Main test routines */ + +if(!test_filter()) + echo "test_filter() failed!\n"; +else + echo "test_filter() passed\n"; + + +?>