|
The test allows testing html page generated by php script.
There are three things used as input parameters for php page:
As a result, php page returns usually:
The test uses features of standard console runner for php.
Full specification of the test looks like:<php> <spec> <sname>test_short_name</sname> <fname>test full name</fname> <descr>test description</descr> </spec> <before> .. script items to run before php .. </before> <script>a.php</script> <out>a.html</out> <get> <par><name>get name 1</name><value>get value 1</value></par> <par><name>get name 2</name><value>get value 2</value></par> ... </get> <post> <par><name>post name 1</name><value>post value 1</value></par> <par><name>post name 2</name><value>post value 2</value></par> ... </post> <session> <par><name>session name 1</name><value>session value 1</value></par> <par><name>session name 2</name><value>session value 2</value></par> ... </session> <check_session>false</check_session> <after> .. script items to run before php .. </after> </php> |
script | Path to file with source code of php-script. izh_test adds %test_dir% to it automatically. |
get | Parameters passed to the php-script by method GET. |
post | Parameters passed to the php-script by method POST. |
session | Variables stored in session with their values which passed to the php script in test mode. |
par | Description of variable/parameter. |
name | Name of variable/parameter. |
value | Value of variable/parameter. |
out |
Base file name for storing of result php page. If the file name looks like [name].htm then
Before using of these file names izh_test adds path to the directory with file description of the test to it so you don't have to use %test_dir% . |
check_session |
Flag saying if izh_test should check values of session variables after finishing of php-script. By default false If value of this flag is true then values of session variables are written in a file to compare it with etalon. If the file name out (see above description of parameter out) looks like [name].htm then
Before using of these file names izh_test adds path to the directory with file description of the test to it so you don't have to use %test_dir% . |
before | Test commands executed before running of php script. (Usually preparation of DBMS state) |
after | Test commands executed after running of php script. (Usually return DBMS to its initial state) |
spec | Identification information for the test (names, descriptions) |
sname | Short name for test, that is used as test name in GUI-runner and as component of path to the test in console runner . The sname should not contain line breaks. It is better if the sname is short and without white spaces. |
fname | Full name of test is used as test name in console runner . The fname should not contain line breaks. The fname is placed in one line/screen. So it would be better if the fname is less than 60 symbols. |
descr | Full description of test. It can be as long as you need and contain any number of line breaks. The description can be shown in the console and GUI runner by special command only. |
To use this command you have to initialize value of substitution variable %php% which should contain right path and file name for the console client of php with all the parameters
The test inside is the test script containing 4 parts:
To use the test you have to do number of actions:
$filename_to_out_session= ""; $root_path= ""; $use_test_time= false; $test_time_count= 0; function prepare_root_path() { global $query_params, $root_path; if ($query_params["test_depth"]=="") { $root_path=""; } else { $root_path="htdocs/"; for ($i= 0; $i<$query_params["test_depth"]; $i++) { $root_path= "../".$root_path; } } } function mysql_get_time() { global $use_test_time, $test_time_count; if (!$use_test_time) { return "now()"; } else { $test_time_count++; return "DATE_ADD('2000-01-01 23:59:59',INTERVAL ".$test_time_count." DAY)"; } } function prepare_params() { global $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_SESSION_VARS; global $argv, $argc; global $query_params; global $test_mode; global $filename_to_out_session, $use_test_time; $query_params= array_merge($HTTP_GET_VARS,$HTTP_POST_VARS); if ($argc>1) { $test_mode= 1; for ($i= 1; $i<$argc; $i++) { $arg= $argv[$i]; if ($arg=="use_test_time") { $use_test_time= true; } else { $pos= strpos($arg,"="); if (is_integer($pos)) { $name= substr($arg,0,$pos); $value= substr($arg,$pos+1); if ($name=="outs") { $filename_to_out_session= $value; } else if ($name{0}=="s") { $name= substr($name,1); $HTTP_SESSION_VARS[$name]= $value; } else if ($name{0}=="p") { $name= substr($name,1); $query_params[$name]= $value; $HTTP_POST_VARS[$name]= $value; } else if ($name{0}=="g") { $name= substr($name,1); $query_params[$name]= $value; $HTTP_GET_VARS[$name]= $value; } } } } } prepare_root_path(); } function safe_trace_session() { global $filename_to_out_session; global $HTTP_SESSION_VARS; if ($filename_to_out_session!="") { $fp= fopen($filename_to_out_session, "wb"); if ($fp!=-1) { if (sizeof($HTTP_SESSION_VARS)!=0) { ob_start(); ob_flush(); print_r($HTTP_SESSION_VARS); $session_text= str_replace("\n","\r\n",ob_get_contents()); fwrite($fp,$session_text); ob_clean(); } fclose($fp); } } } |
prepare_params(); |
safe_trace_session(); |
See completed example of testing for php-page below .
|