mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Merge pull request #356 from zachborboa/master
Add Curl::setCookieString
This commit is contained in:
@@ -222,6 +222,7 @@ Curl::setConnectTimeout($seconds)
|
||||
Curl::setCookie($key, $value)
|
||||
Curl::setCookieFile($cookie_file)
|
||||
Curl::setCookieJar($cookie_jar)
|
||||
Curl::setCookieString($string)
|
||||
Curl::setDefaultJsonDecoder()
|
||||
Curl::setDefaultTimeout()
|
||||
Curl::setDefaultUserAgent()
|
||||
|
||||
@@ -713,6 +713,17 @@ class Curl
|
||||
$this->setOpt(CURLOPT_CONNECTTIMEOUT, $seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Cookie String
|
||||
*
|
||||
* @access public
|
||||
* @param $string
|
||||
*/
|
||||
public function setCookieString($string)
|
||||
{
|
||||
return $this->setOpt(CURLOPT_COOKIE, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Cookie File
|
||||
*
|
||||
|
||||
@@ -706,7 +706,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testCookies()
|
||||
public function testSetCookie()
|
||||
{
|
||||
$test = new Test();
|
||||
$test->curl->setCookie('mycookie', 'yum');
|
||||
@@ -715,7 +715,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
)));
|
||||
}
|
||||
|
||||
public function testCookieEncodingSpace()
|
||||
public function testSetCookieEncodingSpace()
|
||||
{
|
||||
$curl = new Curl();
|
||||
$curl->setCookie('cookie', 'Om nom nom nom');
|
||||
@@ -727,7 +727,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
|
||||
}
|
||||
|
||||
public function testMultipleCookies()
|
||||
public function testSetMultipleCookies()
|
||||
{
|
||||
$curl = new Curl();
|
||||
$curl->setCookie('cookie', 'Om nom nom nom');
|
||||
@@ -740,7 +740,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('cookie=Om%20nom%20nom%20nom; foo=bar', $options[CURLOPT_COOKIE]);
|
||||
}
|
||||
|
||||
public function testCookieEncodingColon()
|
||||
public function testSetCookieEncodingColon()
|
||||
{
|
||||
$curl = new Curl();
|
||||
$curl->setCookie('JSESSIONID', '0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl');
|
||||
@@ -752,6 +752,21 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('JSESSIONID=0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl', $options[CURLOPT_COOKIE]);
|
||||
}
|
||||
|
||||
public function testSetCookieString()
|
||||
{
|
||||
$cookie_string = 'fruit=apple; color=red';
|
||||
|
||||
$test = new Test();
|
||||
$test->curl->setCookieString($cookie_string);
|
||||
|
||||
$reflectionClass = new ReflectionClass('\Curl\Curl');
|
||||
$reflectionProperty = $reflectionClass->getProperty('options');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$options = $reflectionProperty->getValue($test->curl);
|
||||
$this->assertEquals($cookie_string, $options[CURLOPT_COOKIE]);
|
||||
$this->assertEquals('fruit=apple&color=red', $test->server('cookie', 'GET'));
|
||||
}
|
||||
|
||||
public function testCookieFile()
|
||||
{
|
||||
$cookie_file = dirname(__FILE__) . '/cookies.txt';
|
||||
|
||||
@@ -299,6 +299,12 @@ $data_mapping = array(
|
||||
|
||||
if (!empty($test)) {
|
||||
$data = $data_mapping[$test];
|
||||
$value = isset($data[$key]) ? $data[$key] : '';
|
||||
if (empty($key)) {
|
||||
// Return all values when a key is not specified.
|
||||
$value = http_build_query($data);
|
||||
} else {
|
||||
// Return individual value when a key is specified.
|
||||
$value = isset($data[$key]) ? $data[$key] : '';
|
||||
}
|
||||
echo $value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user