mirror of
https://github.com/php/php-src.git
synced 2025-01-18 09:43:36 +08:00
many new enhancements to run-tests that allow for testing cgi and other
sapi modules via http. see README.TESTING2 for more details several sapi tests added
This commit is contained in:
parent
56210b8921
commit
b671380b6b
137
README.TESTING2
Normal file
137
README.TESTING2
Normal file
@ -0,0 +1,137 @@
|
||||
[IMPORTANT NOTICE]
|
||||
------------------
|
||||
This is an addendum to README.TESTING with additional information
|
||||
specific to run-tests2.php.
|
||||
|
||||
run-tests2.php is backward compatible with tests developed for
|
||||
the original run-tests.php script. run-tests2 is *not* used by
|
||||
'make test'. run-tests2 was developed to provide support for
|
||||
testing PHP under it's primary environment, HTTP, and can run the
|
||||
PHP tests under any of the SAPI modules that are direct executables,
|
||||
or are accessable via HTTP.
|
||||
|
||||
[New features]
|
||||
----------------
|
||||
* Command line interface:
|
||||
You can run 'php run-tests2.php -h' to get all the possible options.
|
||||
* Configuration file:
|
||||
the -c argument will allow you to use a configuration file. This is
|
||||
handy if you are testing multiple environments and need various options
|
||||
depending on the environment.
|
||||
see run-tests-config.php for details.
|
||||
* CGI Emulation:
|
||||
Will emulate a CGI environment when testing with the cgi sapi executable.
|
||||
* HTTP testing:
|
||||
can be configured to run test scripts through an HTTP server running
|
||||
on localhost. localhost is required since either the web server must
|
||||
alias a directory to the php source directory, or the test scripts
|
||||
must be copied to a directory under the web server
|
||||
(see config options TEST_WEB_BASE_URL, TEST_BASE_PATH, and TEST_WEB_EXT)
|
||||
* New sections supported for test files (see below)
|
||||
|
||||
When running tests over http, tests that require ini settings different that what
|
||||
the web server runs under will be skipped. Since the test harness defines a number
|
||||
of ini settings by default, the web server may require special configuration to
|
||||
make testing work.
|
||||
|
||||
[Example Usage]
|
||||
----------------
|
||||
Some (but not all!) examples of usage:
|
||||
|
||||
1. run tests from the php source directory
|
||||
php run-tests2.php -p /path/to/php-cli
|
||||
|
||||
2. run tests using cgi emulation
|
||||
php run-tests2.php -p /path/to/php-cgi
|
||||
|
||||
3. run tests over http, copying test files into document root
|
||||
php run-tests2.php -w -u http://localhost/test -m /path/to/htdocs/test
|
||||
|
||||
4. run tests over http, php sources have been aliased in web server
|
||||
php run-tests2.php -w -u http://localhost/test
|
||||
|
||||
5. run tests using configuration file
|
||||
php run-tests2.php -c /path/to/run-tests-config.php
|
||||
|
||||
6. run tests using configuration file, but overriding some settings:
|
||||
(config file must be first)
|
||||
php run-tests2.php -c /path/to/run-tests-config.php -w -t 3 -d /path/to/testdir
|
||||
|
||||
NOTE: configuration as described in README.TESTING still works.
|
||||
|
||||
[New Test Sections]
|
||||
----------------
|
||||
In addition to the traditional test sections
|
||||
(see http://qa.php.net/write-test.php), several new sections are available
|
||||
under run-tests2.
|
||||
|
||||
--POST--
|
||||
This is not a new section, but not multipart posts are supported for testing
|
||||
file uploads, or other types of POST data.
|
||||
|
||||
--CGI--
|
||||
This section takes no value. It merely provides a simple marker for tests
|
||||
that MUST be run as CGI, even if there is no --POST-- or --GET-- sections
|
||||
in the test file.
|
||||
|
||||
--DESCRIPTION--
|
||||
Not used for anything, just a section for documenting the test
|
||||
|
||||
--ENV--
|
||||
This section get's eval()'d to help build an environment for the
|
||||
execution of the test. This can be used to change environment
|
||||
vars that are used for CGI emulation, or simply to set env vars
|
||||
for cli testing. A full example looks like:
|
||||
|
||||
--ENV--
|
||||
return <<<END
|
||||
PATH_TRANSLATED=$filename
|
||||
PATH_INFO=$scriptname
|
||||
SCRIPT_NAME=$scriptname
|
||||
END;
|
||||
|
||||
Some variables are made easily available for use in this section, they
|
||||
include:
|
||||
$filename full native path to file, will become PATH_TRANSLATED
|
||||
$filepath =dirname($filename)
|
||||
$scriptname this is what will become SCRIPT_NAME unless you override it
|
||||
$docroot the equivelant of DOCUMENT_ROOT under Apache
|
||||
$cwd the directory that the test is being initiated from
|
||||
$this->conf all run-tests2 configuration vars
|
||||
$this->env all environment variables that will get passed to the test
|
||||
|
||||
|
||||
--REQUEST--
|
||||
This section is also eval'd, and is similar in nature to --ENV--. However,
|
||||
this section is used to build the url used in an HTTP request. Valid values
|
||||
to set in this section would include:
|
||||
SCRIPT_NAME The inital part of the request url
|
||||
PATH_INFO The pathinfo part of a request url
|
||||
FRAGMENT The fragment section of a url (after #)
|
||||
QUERY_STRING The query part of a url (after ?)
|
||||
|
||||
--REQUEST--
|
||||
return <<<END
|
||||
PATH_INFO=/path/info
|
||||
END;
|
||||
|
||||
--HEADERS--
|
||||
This section is also eval'd. It is used to provide additional headers sent
|
||||
in an HTTP request, such as content type for multipart posts, cookies, etc.
|
||||
|
||||
--HEADERS--
|
||||
return <<<END
|
||||
Content-Type=multipart/form-data; boundary=---------------------------240723202011929
|
||||
Content-Length=100
|
||||
END;
|
||||
|
||||
--EXPECTHEADERS--
|
||||
This section can be used to define what headers are required to be
|
||||
received back from a request, and is checked in addition to the
|
||||
regular expect sections. For example:
|
||||
|
||||
--EXPECTHEADERS--
|
||||
Status: 404
|
||||
|
||||
|
||||
|
74
run-tests-config.php
Normal file
74
run-tests-config.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/* this file may be duplicated to provide testing for
|
||||
multiple php binaries or configurations. It is used
|
||||
with the -c option on run_tests2.php. All these
|
||||
settings will also go into the environment for tests
|
||||
that are directly executed, so you can also set things
|
||||
like PHPRC here to force an executable to use a
|
||||
specific php.ini file. */
|
||||
|
||||
$conf = array(
|
||||
/* path to the php source tree */
|
||||
'TEST_PHP_SRCDIR' => NULL,
|
||||
|
||||
/* executable that will be tested. Not used for
|
||||
web based tests */
|
||||
'TEST_PHP_EXECUTABLE' => NULL,
|
||||
|
||||
/* php.ini to use when executing php */
|
||||
'PHPRC' => NULL,
|
||||
|
||||
/* log format */
|
||||
'TEST_PHP_LOG_FORMAT' => 'LEODC',
|
||||
|
||||
/* debugging detail in output. */
|
||||
'TEST_PHP_DETAILED' => 0,
|
||||
|
||||
/* error style for editors or IDE's */
|
||||
'TEST_PHP_ERROR_STYLE' => 'EMACS',
|
||||
|
||||
'REPORT_EXIT_STATUS' => 0,
|
||||
'NO_PHPTEST_SUMMARY' => 0,
|
||||
|
||||
/* don't ask, and don't send results to QA if true */
|
||||
'NO_INTERACTION' => true,
|
||||
|
||||
/* base url prefixed to any requests */
|
||||
'TEST_WEB_BASE_URL' => NULL,
|
||||
|
||||
/* if set, copy phpt files into this directory,
|
||||
which should be accessable via an http server. The
|
||||
TEST_WEB_BASE_URL setting should be the base url
|
||||
to access this path. If this is not used,
|
||||
TEST_WEB_BASE_URL should be the base url pointing
|
||||
to TEST_PHP_SRCDIR, which should then be accessable via
|
||||
an http server.
|
||||
|
||||
An example would be:
|
||||
TEST_WEB_BASE_URL=http://localhost/test
|
||||
TEST_BASE_PATH=/path/to/htdocs/test
|
||||
*/
|
||||
'TEST_BASE_PATH' => NULL,
|
||||
|
||||
/* file extension of pages requested via http
|
||||
this allows for php to be configured to parse
|
||||
extensions other than php, usefull for multiple
|
||||
configurations under a single webserver */
|
||||
'TEST_WEB_EXT' => 'php',
|
||||
|
||||
/* if true doesn't run tests, just outputs executable info */
|
||||
'TEST_CONTEXT_INFO' => false,
|
||||
|
||||
/* : or ; seperated list of paths */
|
||||
'TEST_PATHS' => NULL
|
||||
/* additional configuration items that may be set
|
||||
to provide proxy support for testes:
|
||||
timeout
|
||||
proxy_host
|
||||
proxy_port
|
||||
proxy_user
|
||||
proxy_pass
|
||||
*/
|
||||
);
|
||||
|
||||
?>
|
1618
run-tests2.php
1618
run-tests2.php
File diff suppressed because it is too large
Load Diff
17
sapi/tests/test001.phpt
Normal file
17
sapi/tests/test001.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
IIS style CGI missing SCRIPT_FILENAME
|
||||
--DESCRIPTION--
|
||||
This would be similar to what IIS produces for a simple query.
|
||||
--ENV--
|
||||
return <<<END
|
||||
PATH_TRANSLATED=$filename
|
||||
PATH_INFO=$scriptname
|
||||
SCRIPT_NAME=$scriptname
|
||||
END;
|
||||
--CGI--
|
||||
--FILE--
|
||||
<?php
|
||||
echo "HELLO";
|
||||
?>
|
||||
--EXPECT--
|
||||
HELLO
|
23
sapi/tests/test002.phpt
Normal file
23
sapi/tests/test002.phpt
Normal file
@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
Apache style CGI
|
||||
--DESCRIPTION--
|
||||
Apache likes to set SCRIPT_FILENAME to the php executable
|
||||
if you use ScriptAlias configurations, and the proper
|
||||
path is in PATH_TRANSLATED. SCRIPT_NAME in this is faked,
|
||||
but that is ok, Apache sets SCRIPT_NAME to the ScriptAlias
|
||||
of the executable.
|
||||
--ENV--
|
||||
return <<<END
|
||||
REDIRECT_URL=$scriptname
|
||||
PATH_TRANSLATED=$filename
|
||||
PATH_INFO=$scriptname
|
||||
SCRIPT_NAME=/scriptalias/php
|
||||
SCRIPT_FILENAME=$this->conf['TEST_PHP_EXECUTABLE']
|
||||
END;
|
||||
--CGI--
|
||||
--FILE--
|
||||
<?php
|
||||
echo "HELLO";
|
||||
?>
|
||||
--EXPECT--
|
||||
HELLO
|
22
sapi/tests/test003.phpt
Normal file
22
sapi/tests/test003.phpt
Normal file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
IIS style CGI missing SCRIPT_FILENAME, has PATH_INFO
|
||||
--DESCRIPTION--
|
||||
This would be similar to what IIS produces for a simple query
|
||||
that also has PATH_INFO.
|
||||
--REQUEST--
|
||||
return <<<END
|
||||
PATH_INFO=/path/info
|
||||
END;
|
||||
--ENV--
|
||||
return <<<END
|
||||
PATH_TRANSLATED=$filename/path/info
|
||||
PATH_INFO=$scriptname/path/info
|
||||
SCRIPT_NAME=$scriptname
|
||||
END;
|
||||
--CGI--
|
||||
--FILE--
|
||||
<?php
|
||||
echo $_SERVER['PATH_INFO'];
|
||||
?>
|
||||
--EXPECT--
|
||||
/path/info
|
27
sapi/tests/test004.phpt
Normal file
27
sapi/tests/test004.phpt
Normal file
@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
Apache style CGI with PATH_INFO
|
||||
--DESCRIPTION--
|
||||
Apache likes to set SCRIPT_FILENAME to the php executable
|
||||
if you use ScriptAlias configurations, and the proper
|
||||
path is in PATH_TRANSLATED. SCRIPT_NAME in this is faked,
|
||||
but that is ok, Apache sets SCRIPT_NAME to the ScriptAlias
|
||||
of the executable.
|
||||
--REQUEST--
|
||||
return <<<END
|
||||
PATH_INFO=/path/info
|
||||
END;
|
||||
--ENV--
|
||||
return <<<END
|
||||
REDIRECT_URL=$scriptname
|
||||
PATH_TRANSLATED=$filename/path/info
|
||||
PATH_INFO=$scriptname/path/info
|
||||
SCRIPT_NAME=/scriptalias/php
|
||||
SCRIPT_FILENAME=$this->conf['TEST_PHP_EXECUTABLE']
|
||||
END;
|
||||
--CGI--
|
||||
--FILE--
|
||||
<?php
|
||||
echo $_SERVER['PATH_INFO'];
|
||||
?>
|
||||
--EXPECT--
|
||||
/path/info
|
28
sapi/tests/test005.phpt
Normal file
28
sapi/tests/test005.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
QUERY_STRING Security Bug
|
||||
--DESCRIPTION--
|
||||
This bug was present in PHP 4.3.0 only.
|
||||
A failure should print HELLO.
|
||||
--REQUEST--
|
||||
return <<<END
|
||||
SCRIPT_NAME=/nothing.php
|
||||
QUERY_STRING=$filename
|
||||
END;
|
||||
--ENV--
|
||||
return <<<END
|
||||
REDIRECT_URL=$scriptname
|
||||
PATH_TRANSLATED=c:\apache\1.3.27\htdocs\nothing.php
|
||||
QUERY_STRING=$filename
|
||||
PATH_INFO=/nothing.php
|
||||
SCRIPT_NAME=/phpexe/php.exe/nothing.php
|
||||
SCRIPT_FILENAME=c:\apache\1.3.27\htdocs\nothing.php
|
||||
END;
|
||||
--CGI--
|
||||
--FILE--
|
||||
<?php
|
||||
echo "HELLO";
|
||||
?>
|
||||
--EXPECTHEADERS--
|
||||
Status: 404
|
||||
--EXPECT--
|
||||
No input file specified.
|
75
sapi/tests/test006.phpt
Normal file
75
sapi/tests/test006.phpt
Normal file
@ -0,0 +1,75 @@
|
||||
--TEST--
|
||||
Multipart Form POST Data
|
||||
--CGI--
|
||||
--HEADERS--
|
||||
return <<<END
|
||||
Content-Type=multipart/form-data; boundary=---------------------------240723202011929
|
||||
Content-Length=862
|
||||
END;
|
||||
--ENV--
|
||||
return <<<END
|
||||
CONTENT_TYPE=multipart/form-data; boundary=---------------------------240723202011929
|
||||
CONTENT_LENGTH=862
|
||||
END;
|
||||
--POST--
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="entry"
|
||||
|
||||
entry box
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="password"
|
||||
|
||||
password box
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="radio1"
|
||||
|
||||
test 1
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="checkbox1"
|
||||
|
||||
test 1
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="choices"
|
||||
|
||||
Choice 1
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="choices"
|
||||
|
||||
Choice 2
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="file"; filename="info.php"
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
<?php
|
||||
phpinfo();
|
||||
?>
|
||||
-----------------------------240723202011929--
|
||||
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
error_reporting(0);
|
||||
print_r($_POST);
|
||||
print_r($_FILES);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Array
|
||||
(
|
||||
[entry] => entry box
|
||||
[password] => password box
|
||||
[radio1] => test 1
|
||||
[checkbox1] => test 1
|
||||
[choices] => Choice 2
|
||||
)
|
||||
Array
|
||||
(
|
||||
[file] => Array
|
||||
(
|
||||
[name] => info.php
|
||||
[type] => application/octet-stream
|
||||
[tmp_name] => %s
|
||||
[error] => 0
|
||||
[size] => 21
|
||||
)
|
||||
|
||||
)
|
48
sapi/tests/test007.phpt
Normal file
48
sapi/tests/test007.phpt
Normal file
@ -0,0 +1,48 @@
|
||||
--TEST--
|
||||
Multipart Form POST Data, incorrect content length
|
||||
--CGI--
|
||||
--HEADERS--
|
||||
return <<<END
|
||||
Content-Type=multipart/form-data; boundary=---------------------------240723202011929
|
||||
Content-Length=100
|
||||
END;
|
||||
--POST--
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="entry"
|
||||
|
||||
entry box
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="password"
|
||||
|
||||
password box
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="radio1"
|
||||
|
||||
test 1
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="checkbox1"
|
||||
|
||||
test 1
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="choices"
|
||||
|
||||
Choice 1
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="choices"
|
||||
|
||||
Choice 2
|
||||
-----------------------------240723202011929
|
||||
Content-Disposition: form-data; name="file"; filename="info.php"
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
<?php
|
||||
phpinfo();
|
||||
?>
|
||||
-----------------------------240723202011929--
|
||||
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
print @$_POST['choices'];
|
||||
?>
|
||||
--EXPECT--
|
Loading…
Reference in New Issue
Block a user