- New tests (DutchUG testfest)

This commit is contained in:
Felipe Pena 2009-07-03 00:09:08 +00:00
parent 9937006ac5
commit 8715a7f12e
33 changed files with 1232 additions and 0 deletions

View File

@ -0,0 +1,45 @@
--TEST--
Test curl_setopt() CURLOPT_FILE readonly file handle
--CREDITS--
Mark van der Velden
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
/*
* Description : Adds a file which stores the received data from curl_exec();
* Source code : ext/curl/multi.c
* Test documentation: http://wiki.php.net/qa/temp/ext/curl
*/
// Figure out what handler to use
if(!empty($_ENV['PHP_CURL_HTTP_REMOTE_SERVER'])) {
// Use the set Environment variable
$url = $_ENV['PHP_CURL_HTTP_REMOTE_SERVER'];
} else {
// Create a temporary file for the test
$tempname = tempnam(sys_get_temp_dir(), 'CURL_HANDLE');
$url = 'file://'. $tempname;
// add the test data to the file
file_put_contents($tempname, "Hello World!\nHello World!");
}
$tempfile = tempnam(sys_get_temp_dir(), 'CURL_FILE_HANDLE');
$ch = curl_init($url);
$fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
is_file($tempfile) and @unlink($tempfile);
isset($tempname) and is_file($tempname) and @unlink($tempfile);
?>
--EXPECTF--
Warning: curl_setopt(): the provided file handle is not writable in %s on line %d
%S

View File

@ -0,0 +1,44 @@
--TEST--
Test CURLOPT_READDATA without a callback function
--CREDITS--
Mattijs Hoitink mattijshoitink@gmail.com
#Testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl") || empty($_ENV['PHP_CURL_HTTP_REMOTE_SERVER'])) print "skip"; ?>
--FILE--
<?php
// The URL to POST to
$url = $_ENV['PHP_CURL_HTTP_REMOTE_SERVER'] . '/get.php?test=post';
// Create a temporary file to read the data from
$tempname = tempnam(sys_get_temp_dir(), 'CURL_DATA');
file_put_contents($tempname, "hello=world&smurf=blue");
ob_start();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_READDATA, fopen($tempname, 'rb'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Transfer-Encoding: chunked'));
if (false === $response = curl_exec($ch)) {
echo 'Error #' . curl_errno($ch) . ': ' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
// Clean the temporary file
unset($tempname);
--EXPECT--
array(2) {
["hello"]=>
string(5) "world"
["smurf"]=>
string(4) "blue"
}

View File

@ -0,0 +1,16 @@
--TEST--
curl_close
--CREDITS--
Stefan Koopmanschap <stefan@php.net>
#testfest Utrecht 2009
--SKIPIF--
<?php
if (!extension_loaded('curl')) print 'skip';
?>
--FILE--
<?php
$ch = curl_init();
curl_close($ch);
var_dump($ch);
--EXPECT--
resource(4) of type (Unknown)

View File

@ -0,0 +1,42 @@
--TEST--
Test curl_copy_handle() with simple get
--CREDITS--
Rick Buitenman <rick@meritos.nl>
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
echo '*** Testing curl copy handle with simple GET ***' . "\n";
$url = "{$host}/get.php?test=getpost&get_param=Hello%20World";
$ch = curl_init();
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
$copy = curl_copy_handle($ch);
curl_close($ch);
$curl_content = curl_exec($copy);
curl_close($copy);
var_dump( $curl_content );
?>
===DONE===
--EXPECTF--
*** Testing curl copy handle with simple GET ***
string(106) "array(2) {
["test"]=>
string(7) "getpost"
["get_param"]=>
string(11) "Hello World"
}
array(0) {
}
"
===DONE===

View File

@ -0,0 +1,49 @@
--TEST--
Test curl_copy_handle() with simple POST
--CREDITS--
Rick Buitenman <rick@meritos.nl>
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
echo '*** Testing curl copy handle with simple POST ***' . "\n";
$url = "{$host}/get.php?test=getpost";
$ch = curl_init();
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "Hello=World&Foo=Bar&Person=John%20Doe");
curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
$copy = curl_copy_handle($ch);
curl_close($ch);
$curl_content = curl_exec($copy);
curl_close($copy);
var_dump( $curl_content );
?>
===DONE===
--XFAIL--
This test fails, the copy seems to be missing the CURLOPT_POSTFIELDS after the original is closed
--EXPECTF--
*** Testing curl copy handle with simple POST ***
string(163) "array(1) {
["test"]=>
string(7) "getpost"
}
array(3) {
["Hello"]=>
string(5) "World"
["Foo"]=>
string(3) "Bar"
["Person"]=>
string(8) "John Doe"
}
"
===DONE===

View File

@ -0,0 +1,44 @@
--TEST--
Test curl_copy_handle() after exec()
--CREDITS--
Rick Buitenman <rick@meritos.nl>
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
echo '*** Test curl_copy_handle() after exec() ***' . "\n";
$url = "{$host}/get.php?test=getpost&get_param=Hello%20World";
$ch = curl_init();
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
$curl_content = curl_exec($ch);
$copy = curl_copy_handle($ch);
curl_close($ch);
$curl_content_copy = curl_exec($copy);
curl_close($copy);
var_dump( $curl_content_copy );
?>
===DONE===
--EXPECTF--
*** Test curl_copy_handle() after exec() ***
string(106) "array(2) {
["test"]=>
string(7) "getpost"
["get_param"]=>
string(11) "Hello World"
}
array(0) {
}
"
===DONE===

View File

@ -0,0 +1,52 @@
--TEST--
Test curl_copy_handle() after exec() with POST
--CREDITS--
Rick Buitenman <rick@meritos.nl>
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
echo '*** Test curl_copy_handle() after exec() with POST ***' . "\n";
$url = "{$host}/get.php?test=getpost";
$ch = curl_init();
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "Hello=World&Foo=Bar&Person=John%20Doe");
curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
$curl_content = curl_exec($ch);
$copy = curl_copy_handle($ch);
curl_close($ch);
$curl_content_copy = curl_exec($copy);
curl_close($copy);
var_dump( $curl_content_copy );
?>
===DONE===
--XFAIL--
This test fails, the output of the copy seems to be corrupted if the original is closed after exec()
--EXPECTF--
*** Test curl_copy_handle() after exec() with POST ***
string(163) "array(1) {
["test"]=>
string(7) "getpost"
}
array(3) {
["Hello"]=>
string(5) "World"
["Foo"]=>
string(3) "Bar"
["Person"]=>
string(8) "John Doe"
}
"
===DONE===

View File

@ -0,0 +1,35 @@
--TEST--
Test curl_copy_handle() with User Agent
--CREDITS--
Rick Buitenman <rick@meritos.nl>
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
echo '*** Testing curl copy handle with User Agent ***' . "\n";
$url = "{$host}/get.php?test=useragent";
$ch = curl_init();
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'cURL phpt');
curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
$copy = curl_copy_handle($ch);
curl_close($ch);
$curl_content = curl_exec($copy);
curl_close($copy);
var_dump( $curl_content );
?>
===DONE===
--EXPECTF--
*** Testing curl copy handle with User Agent ***
string(9) "cURL phpt"
===DONE===

View File

@ -0,0 +1,33 @@
--TEST--
curl_error() function - basic test for curl_error using a fake url
--CREDITS--
Mattijs Hoitink mattijshoitink@gmail.com
#Testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
/*
* Prototype: string curl_error(resource $ch)
* Description: Returns a clear text error message for the last cURL operation.
* Source: ext/curl/interface.c
* Documentation: http://wiki.php.net/qa/temp/ext/curl
*/
// Fake URL to trigger an error
$url = "fakeURL";
echo "== Testing curl_error with a fake URL ==\n";
// cURL handler
$ch = curl_init($url);
ob_start(); // start output buffering
curl_exec($ch);
echo "Error: " . curl_error($ch);
curl_close($ch);
?>
--EXPECT--
== Testing curl_error with a fake URL ==
Error: Couldn't resolve host 'fakeURL'

View File

@ -0,0 +1,16 @@
--TEST--
curl_multi_close
--CREDITS--
Stefan Koopmanschap <stefan@php.net>
#testfest Utrecht 2009
--SKIPIF--
<?php
if (!extension_loaded('curl')) print 'skip';
?>
--FILE--
<?php
$ch = curl_multi_init();
curl_multi_close($ch);
var_dump($ch);
--EXPECT--
resource(4) of type (Unknown)

View File

@ -0,0 +1,59 @@
--TEST--
Curl_multi_getcontent() basic test with different sources (local file/http)
--CREDITS--
Rein Velt (rein@velt.org)
#TestFest Utrecht 20090509
--SKIPIF--
<?php
if (!extension_loaded('curl')) print 'skip';
?>
--FILE--
<?php
//CURL_MULTI_GETCONTENT TEST
//CREATE RESOURCES
$ch1=curl_init();
$ch2=curl_init();
//SET URL AND OTHER OPTIONS
curl_setopt($ch1, CURLOPT_URL, "http://php.net/robots.txt");
curl_setopt($ch2, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata2.txt");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
//CREATE MULTIPLE CURL HANDLE
$mh=curl_multi_init();
//ADD THE 2 HANDLES
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
//EXECUTE
$running=0;
do {
curl_multi_exec($mh,$running);
} while ($running>0);
$results1=curl_multi_getcontent($ch1);
$results2=curl_multi_getcontent($ch2);
//CLOSE
curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_close($mh);
echo $results1;
echo $results2;
?>
--EXPECT--
User-agent: *
Disallow: /backend/
Disallow: /distributions/
Disallow: /stats/
Disallow: /source.php
Disallow: /search.php
Disallow: /mod.php
Disallow: /manual/add-note.php
CURL2

View File

@ -0,0 +1,51 @@
--TEST--
Curl_multi_getcontent() error test
--CREDITS--
Rein Velt (rein@velt.org)
#TestFest Utrecht 20090509
--SKIPIF--
<?php
if (!extension_loaded('curl')) print 'skip';
?>
--FILE--
<?php
//CURL_MULTI_GETCONTENT TEST
//CREATE RESOURCES
$ch1=curl_init();
$ch2=curl_init();
//SET URL AND OTHER OPTIONS
curl_setopt($ch1, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata1.txt");
curl_setopt($ch2, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata2.txt");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
//CREATE MULTIPLE CURL HANDLE
$mh=curl_multi_init();
//ADD THE 2 HANDLES
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
//EXECUTE
$running=0;
do {
curl_multi_exec($mh,$running);
} while ($running>0);
$results1=curl_multi_getcontent(); //no parameter
$results2=curl_multi_getcontent($ch2);
//CLOSE
curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_close($mh);
echo $results1;
echo $results2;
?>
--EXPECTF--
Warning: curl_multi_getcontent() expects exactly 1 parameter, 0 given in %s on line %d
CURL2

View File

@ -0,0 +1,51 @@
--TEST--
Curl_multi_getcontent() error test
--CREDITS--
Rein Velt (rein@velt.org)
#TestFest Utrecht 20090509
--SKIPIF--
<?php
if (!extension_loaded('curl')) print 'skip';
?>
--FILE--
<?php
//CURL_MULTI_GETCONTENT TEST
//CREATE RESOURCES
$ch1=curl_init();
$ch2=curl_init();
//SET URL AND OTHER OPTIONS
curl_setopt($ch1, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata1.txt");
curl_setopt($ch2, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata2.txt");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
//CREATE MULTIPLE CURL HANDLE
$mh=curl_multi_init();
//ADD THE 2 HANDLES
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
//EXECUTE
$running=0;
do {
curl_multi_exec($mh,$running);
} while ($running>0);
$results1=curl_multi_getcontent($ch1,$ch2); //no parameter
$results2=curl_multi_getcontent($ch2);
//CLOSE
curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_close($mh);
echo $results1;
echo $results2;
?>
--EXPECTF--
Warning: curl_multi_getcontent() expects exactly 1 parameter, 2 given in %s on line %d
CURL2

View File

@ -0,0 +1,53 @@
--TEST--
Curl_multi_getcontent() error test
--CREDITS--
Rein Velt (rein@velt.org)
#TestFest Utrecht 20090509
--SKIPIF--
<?php
if (!extension_loaded('curl')) print 'skip';
?>
--FILE--
<?php
//CURL_MULTI_GETCONTENT TEST
//CREATE RESOURCES
$ch1=curl_init();
$ch2=curl_init();
//SET URL AND OTHER OPTIONS
curl_setopt($ch1, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata1.txt");
curl_setopt($ch2, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata2.txt");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
//CREATE MULTIPLE CURL HANDLE
$mh=curl_multi_init();
//ADD THE 2 HANDLES
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
//EXECUTE
$running=0;
do {
curl_multi_exec($mh,$running);
} while ($running>0);
$ch1="string";
$results1=curl_multi_getcontent($ch1); //incorrect parameter type
$results2=curl_multi_getcontent($ch2);
//CLOSE
//curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_close($mh);
echo $results1;
echo $results2;
?>
--EXPECTF--
Warning: curl_multi_getcontent() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
CURL2

View File

@ -0,0 +1,66 @@
--TEST--
Curl_multi_getcontent() error test with undefined handle
--CREDITS--
Rein Velt (rein@velt.org)
#TestFest Utrecht 20090509
--SKIPIF--
<?php
if (!extension_loaded('curl')) print 'skip';
?>
--FILE--
<?php
//CURL_MULTI_GETCONTENT TEST
//CREATE RESOURCES
//$ch1=undefined;
$ch2=curl_init();
//SET URL AND OTHER OPTIONS
curl_setopt($ch1, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata1.txt");
curl_setopt($ch2, CURLOPT_URL, "file://".dirname(__FILE__)."/curl_testdata2.txt");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
//CREATE MULTIPLE CURL HANDLE
$mh=curl_multi_init();
//ADD THE 2 HANDLES
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
//EXECUTE
$running=0;
do {
curl_multi_exec($mh,$running);
} while ($running>0);
$results1=curl_multi_getcontent($ch1); //incorrect parameter type
$results2=curl_multi_getcontent($ch2);
//CLOSE
//curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_close($mh);
echo $results1;
echo $results2;
?>
--EXPECTF--
Notice: Undefined variable: ch1 in %s on line %d
Warning: curl_setopt() expects parameter 1 to be resource, null given in %s on line %d
Notice: Undefined variable: ch1 in %s on line %d
Warning: curl_setopt() expects parameter 1 to be resource, null given in %s on line %d
Notice: Undefined variable: ch1 in %s on line %d
Warning: curl_multi_add_handle() expects parameter 2 to be resource, null given in %s on line %d
Notice: Undefined variable: ch1 in %s on line %d
Warning: curl_multi_getcontent() expects parameter 1 to be resource, null given in %s on line %d
CURL2

View File

@ -0,0 +1,31 @@
--TEST--
Test curl_multi_init()
--CREDITS--
Mark van der Velden
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
/* Prototype : resource curl_multi_init(void)
* Description : Returns a new cURL multi handle
* Source code : ext/curl/multi.c
* Test documentation: http://wiki.php.net/qa/temp/ext/curl
*/
// start testing
echo "*** Testing curl_multi_init(void); ***\n";
//create the multiple cURL handle
$mh = curl_multi_init();
var_dump($mh);
curl_multi_close($mh);
var_dump($mh);
?>
===DONE===
--EXPECTF--
*** Testing curl_multi_init(void); ***
resource(%d) of type (curl_multi)
resource(%d) of type (Unknown)
===DONE===

View File

@ -0,0 +1,25 @@
--TEST--
Test curl_multi_select()
--CREDITS--
Ivo Jansch <ivo@ibuildings.com>
#testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
/* Prototype : resource curl_multi_select($mh, $timeout=1.0])
* Description : Get all the sockets associated with the cURL extension, which can then be
* "selected"
* Source code : ?
* Test documentation: http://wiki.php.net/qa/temp/ext/curl
*/
//create the multiple cURL handle
$mh = curl_multi_init();
echo curl_multi_select($mh)."\n";
curl_multi_close($mh);
?>
--EXPECT--
0

View File

@ -0,0 +1,22 @@
--TEST--
CURLOPT_FOLLOWLOCATION case check safe_mode and open_basedir
--CREDITS--
WHITE new media architects - Dennis
--INI--
open_basedir = DIRECTORY_SEPARATOR."tmp";
--SKIPIF--
<?php
if (!extension_loaded("curl")) print "skip cURL not loaded";
?>
--FILE--
<?php
print (ini_get("OPEN_BASEDIR"));
$ch = curl_init();
$succes = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_close($ch);
var_dump($succes);
?>
--EXPECTF--
Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when %r(in safe_mode or an )?%ropen_basedir is set in %s.php on line %d
bool(false)

View File

@ -0,0 +1,54 @@
--TEST--
cURL option CURLOPT_READFUNCTION
--CREDITS--
WHITE new media architects - Jeroen Vermeulen
#testfest Utrecht 2009
--SKIPIF--
<?php
if (!extension_loaded("curl")) print "skip cURL extension not loaded";
?>
--FILE--
<?php
function custom_readfunction($oCurl, $hReadHandle, $iMaxOut)
{
$sData = fread($hReadHandle,$iMaxOut-10); # -10 to have space to add "custom:"
if (!empty($sData))
{
$sData = "custom:".$sData;
}
return $sData;
}
$sFileBase = dirname(__FILE__).DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION';
$sReadFile = $sFileBase.'_in.tmp';
$sWriteFile = $sFileBase.'_out.tmp';
$sWriteUrl = 'file://'.$sWriteFile;
file_put_contents($sReadFile,'contents of tempfile');
$hReadHandle = fopen($sReadFile, 'r');
$oCurl = curl_init();
curl_setopt($oCurl, CURLOPT_URL, $sWriteUrl);
curl_setopt($oCurl, CURLOPT_UPLOAD, 1);
curl_setopt($oCurl, CURLOPT_READFUNCTION, "custom_readfunction" );
curl_setopt($oCurl, CURLOPT_INFILE, $hReadHandle );
curl_exec($oCurl);
curl_close($oCurl);
fclose ($hReadHandle);
$sOutput = file_get_contents($sWriteFile);
var_dump($sOutput);
?>
===DONE===
--CLEAN--
<?php
$sFileBase = dirname(__FILE__).DIRECTORY_SEPARATOR.'curl_opt_CURLOPT_READFUNCTION';
$sReadFile = $sFileBase.'_in.tmp';
$sWriteFile = $sFileBase.'_out.tmp';
unlink($sReadFile);
unlink($sWriteFile);
?>
--EXPECT--
string(27) "custom:contents of tempfile"
===DONE===

View File

@ -0,0 +1,55 @@
--TEST--
curl_setopt_array() function - tests setting multiple cURL options with curl_setopt_array()
--CREDITS--
Mattijs Hoitink mattijshoitink@gmail.com
#Testfest Utrecht 2009
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
/*
* Prototype: bool curl_setopt_array(resource $ch, array $options)
* Description: Sets multiple options for a cURL session.
* Source: ext/curl/interface.c
* Documentation: http://wiki.php.net/qa/temp/ext/curl
*/
// Figure out what handler to use
if(!empty($_ENV['PHP_CURL_HTTP_REMOTE_SERVER'])) {
// Use the set Environment variable
$host = $_ENV['PHP_CURL_HTTP_REMOTE_SERVER'];
$url = "{$host}/get.php?test=get";
} else {
// Create a temporary file for the test
$tempname = tempnam(sys_get_temp_dir(), 'CURL_HANDLE');
$url = 'file://'. $tempname;
// add the test data to the file
file_put_contents($tempname, "Hello World!\nHello World!");
}
// Start the test
echo '== Starting test curl_setopt_array($ch, $options); ==' . "\n";
// curl handler
$ch = curl_init();
// options for the curl handler
$options = array (
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1
);
ob_start(); // start output buffering
curl_setopt_array($ch, $options);
$returnContent = curl_exec($ch);
curl_close($ch);
var_dump($returnContent);
?>
--EXPECT--
== Starting test curl_setopt_array($ch, $options); ==
string(25) "Hello World!
Hello World!"

View File

@ -0,0 +1,35 @@
--TEST--
curl_setopt basic tests.
--CREDITS--
Paul Sohier
#phptestfest utrecht
--INI--
safe_mode=On
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
// start testing
echo "*** Testing curl_setopt with CURLOPT_FOLLOWLOCATION in safemode\n";
$url = "{$host}/";
$ch = curl_init();
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$curl_content = curl_exec($ch);
curl_close($ch);
var_dump( $curl_content );
?>
--EXPECTF--
PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0
*** Testing curl_setopt with CURLOPT_FOLLOWLOCATION in safemode
Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in %s on line %d
bool(false)

View File

@ -0,0 +1,51 @@
--TEST--
curl_setopt basic tests with CURLOPT_STDERR.
--CREDITS--
Paul Sohier
#phptestfest utrecht
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
// start testing
echo "*** Testing curl_setopt with CURLOPT_STDERR\n";
$temp_file = tempnam(sys_get_temp_dir(), '');
$handle = fopen($temp_file, 'w');
$url = "{$host}/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $handle);
$curl_content = curl_exec($ch);
fclose($handle);
var_dump( curl_error($ch) );
var_dump( file_get_contents($temp_file));
@unlink ($temp_file);
$handle = fopen($temp_file, 'w');
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $handle);
curl_setopt($ch, CURLOPT_URL, $url); //set the url we want to use
$data = curl_exec($ch);
fclose($handle);
ob_end_clean();
var_dump(file_get_contents($temp_file));
curl_close($ch);
@unlink($temp_file);
?>
--EXPECTF--
*** Testing curl_setopt with CURLOPT_STDERR
string(%d) "%S"
string(%d) "%S"
string(%d) "%S"

View File

@ -0,0 +1,43 @@
--TEST--
curl_setopt() call with CURLOPT_HTTPHEADER
--CREDITS--
Paul Sohier
#phptestfest utrecht
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
// start testing
echo "*** curl_setopt() call with CURLOPT_HTTPHEADER\n";
$url = "{$host}/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, 1);
$curl_content = curl_exec($ch);
curl_close($ch);
var_dump( $curl_content );
$ch = curl_init();
ob_start(); // start output buffering
curl_setopt($ch, CURLOPT_HTTPHEADER, array());
curl_setopt($ch, CURLOPT_URL, $host);
$curl_content = curl_exec($ch);
ob_end_clean();
curl_close($ch);
var_dump( $curl_content );
?>
--EXPECTF--
*** curl_setopt() call with CURLOPT_HTTPHEADER
Warning: curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE, CURLOPT_HTTP200ALIASES and CURLOPT_POSTQUOTE arguments in %s on line %d
bool(false)
bool(true)

View File

@ -0,0 +1,44 @@
--TEST--
curl_setopt() call with CURLOPT_RETURNTRANSFER
--CREDITS--
Paul Sohier
#phptestfest utrecht
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
// start testing
echo "*** curl_setopt() call with CURLOPT_RETURNTRANSFER set to 1\n";
$url = "{$host}/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$curl_content = curl_exec($ch);
curl_close($ch);
var_dump( $curl_content );
echo "*** curl_setopt() call with CURLOPT_RETURNTRANSFER set to 0\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
ob_start();
$curl_content = curl_exec($ch);
ob_end_clean();
curl_close($ch);
var_dump( $curl_content );
?>
--EXPECTF--
*** curl_setopt() call with CURLOPT_RETURNTRANSFER set to 1
string(%d) "%a"
*** curl_setopt() call with CURLOPT_RETURNTRANSFER set to 0
bool(true)

View File

@ -0,0 +1,44 @@
--TEST--
curl_setopt() basic parameter test
--CREDITS--
Paul Sohier
#phptestfest utrecht
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
echo "*** curl_setopt() call with incorrect parameters\n";
$ch = curl_init();
curl_setopt();
curl_setopt(false);
curl_setopt($ch);
curl_setopt($ch, false);
curl_setopt($ch, -1);
curl_setopt($ch, '');
curl_setopt($ch, 1, false);
curl_setopt(false, false, false);
curl_setopt($ch, '', false);
curl_setopt($ch, 1, '');
curl_setopt($ch, -1, 0);
?>
--EXPECTF--
*** curl_setopt() call with incorrect parameters
Warning: curl_setopt() expects exactly 3 parameters, 0 given in %s on line %d
Warning: curl_setopt() expects exactly 3 parameters, 1 given in %s on line %d
Warning: curl_setopt() expects exactly 3 parameters, 1 given in %s on line %d
Warning: curl_setopt() expects exactly 3 parameters, 2 given in %s on line %d
Warning: curl_setopt() expects exactly 3 parameters, 2 given in %s on line %d
Warning: curl_setopt() expects exactly 3 parameters, 2 given in %s on line %d
Warning: curl_setopt() expects parameter 1 to be resource, boolean given in %s on line %d
Warning: curl_setopt() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d

View File

@ -0,0 +1 @@
CURL1

View File

@ -0,0 +1 @@
CURL2

View File

@ -0,0 +1,36 @@
--TEST--
Test curl option CURLOPT_WRITEFUNCTION
--CREDITS--
Mathieu Kooiman <mathieuk@gmail.com>
Dutch UG, TestFest 2009, Utrecht
--DESCRIPTION--
Writes the value 'test' to a temporary file. Use curl to access this file, passing the output into a callback. Tests the PHP_CURL_USER case in curl_write.
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
function curl_callback($curl_handle, $received_data)
{
echo $received_data;
return strlen($received_data);
}
$log_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
$fp = fopen($log_file, 'w+');
fwrite($fp, "test");
fclose($fp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'curl_callback');
curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
curl_exec($ch);
curl_close($ch);
// cleanup
unlink($log_file);
?>
--EXPECT--
test

View File

@ -0,0 +1,38 @@
--TEST--
Test curl option CURLOPT_FILE
--CREDITS--
Mathieu Kooiman <mathieuk@gmail.com>
Dutch UG, TestFest 2009, Utrecht
--DESCRIPTION--
Writes the value 'test' to a temporary file. Use curl to access this file and store the output in another temporary file. Tests the PHP_CURL_FILE case in curl_write().
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
$test_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
$log_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
$fp = fopen($log_file, 'w+');
fwrite($fp, "test");
fclose($fp);
$testfile_fp = fopen($test_file, 'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $testfile_fp);
curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
curl_exec($ch);
curl_close($ch);
fclose($testfile_fp);
echo file_get_contents($test_file);
// cleanup
unlink($test_file);
unlink($log_file);
?>
--EXPECT--
test

View File

@ -0,0 +1,33 @@
--TEST--
Test curl option CURLOPT_RETURNTRANSFER
--CREDITS--
Mathieu Kooiman <mathieuk@gmail.com>
Dutch UG, TestFest 2009, Utrecht
--DESCRIPTION--
Writes the value 'test' to a temporary file. Use curl to access this file and have it return the content from curl_exec(). Tests the PHP_CURL_RETURN case
of curl_write().
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
$log_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
$fp = fopen($log_file, 'w+');
fwrite($fp, "test");
fclose($fp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
// cleanup
unlink($log_file);
?>
--EXPECT--
test

View File

@ -0,0 +1,30 @@
--TEST--
Test curl option CURLOPT_FILE with STDOUT handle
--CREDITS--
Mathieu Kooiman <mathieuk@gmail.com>
Dutch UG, TestFest 2009, Utrecht
--DESCRIPTION--
Writes the value 'test' to a temporary file. Use curl to access this file and store the output in another temporary file. Tests the PHP_CURL_FILE case in curl_write().
--SKIPIF--
<?php if (!extension_loaded("curl")) print "skip"; ?>
--FILE--
<?php
$log_file = tempnam(sys_get_temp_dir(), 'php-curl-test');
$fp = fopen($log_file, 'w+');
fwrite($fp, "test");
fclose($fp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, STDOUT);
curl_setopt($ch, CURLOPT_URL, 'file://' . $log_file);
curl_exec($ch);
curl_close($ch);
// cleanup
unlink($log_file);
?>
--EXPECT--
test

View File

@ -0,0 +1,30 @@
--TEST--
Test curl option CURLOPT_HEADERFUNCTION
--CREDITS--
Mathieu Kooiman <mathieuk@gmail.com>
Dutch UG, TestFest 2009, Utrecht
--DESCRIPTION--
Hit the host identified by PHP_CURL_HTTP_REMOTE_SERVER and determine that the headers are sent to the callback specified for CURLOPT_HEADERFUNCTION. Different test servers specified for PHP_CURL_HTTP_REMOTE_SERVER might return different sets of headers. Just test for HTTP/1.1 200 OK.
--SKIPIF--
<?php if (!extension_loaded("curl") || false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) print "skip"; ?>
--FILE--
<?php
function curl_header_callback($curl_handle, $data)
{
if (strtolower(substr($data,0, 4)) == 'http')
echo $data;
}
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'curl_header_callback');
curl_setopt($ch, CURLOPT_URL, $host);
curl_exec($ch);
curl_close($ch);
?>
--EXPECT--
HTTP/1.1 200 OK

View File

@ -1,5 +1,8 @@
<?php
switch($_GET['test']) {
case 'post':
var_dump($_POST);
break;
case 'getpost':
var_dump($_GET);
var_dump($_POST);