mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Add tests for setCookieFile() and setCookieJar() methods
This commit is contained in:
@@ -164,6 +164,42 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
)) === 'yum');
|
||||
}
|
||||
|
||||
public function testCookieFile() {
|
||||
$cookie_file = dirname(__FILE__) . '/cookies.txt';
|
||||
$cookie_data = implode("\t", array(
|
||||
'127.0.0.1', // domain
|
||||
'FALSE', // tailmatch
|
||||
'/', // path
|
||||
'FALSE', // secure
|
||||
'0', // expires
|
||||
'mycookie', // name
|
||||
'yum', // value
|
||||
));
|
||||
file_put_contents($cookie_file, $cookie_data);
|
||||
|
||||
$test = new Test();
|
||||
$test->curl->setCookieFile($cookie_file);
|
||||
$this->assertTrue($test->server('cookie', 'GET', array(
|
||||
'key' => 'mycookie',
|
||||
)) === 'yum');
|
||||
|
||||
unlink($cookie_file);
|
||||
$this->assertFalse(file_exists($cookie_file));
|
||||
}
|
||||
|
||||
public function testCookieJar() {
|
||||
$cookie_file = dirname(__FILE__) . '/cookies.txt';
|
||||
|
||||
$test = new Test();
|
||||
$test->curl->setCookieJar($cookie_file);
|
||||
$test->server('cookiejar', 'GET');
|
||||
$test->curl->close();
|
||||
|
||||
$this->assertTrue(!(strpos(file_get_contents($cookie_file), "\t" . 'mycookie' . "\t" . 'yum') === false));
|
||||
unlink($cookie_file);
|
||||
$this->assertFalse(file_exists($cookie_file));
|
||||
}
|
||||
|
||||
public function testError() {
|
||||
$test = new Test();
|
||||
$test->curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
|
||||
|
||||
@@ -51,6 +51,10 @@ else if ($test === 'request_uri') {
|
||||
echo $_SERVER['REQUEST_URI'];
|
||||
exit;
|
||||
}
|
||||
else if ($test === 'cookiejar') {
|
||||
setcookie('mycookie', 'yum');
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Content-Type: text/plain');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user