Add setHeaders() method and test

This commit is contained in:
php-curl-class
2013-08-20 15:29:35 -07:00
parent 36c71bd2d3
commit 94982c6450
2 changed files with 16 additions and 0 deletions
+6
View File
@@ -53,6 +53,11 @@ class Curl {
$this->setopt(CURLOPT_USERPWD, $username . ':' . $password);
}
function setHeader($key, $value) {
$this->_headers[$key] = $key . ': ' . $value;
$this->setopt(CURLOPT_HTTPHEADER, array_values($this->_headers));
}
function setUserAgent($user_agent) {
$this->setopt(CURLOPT_USERAGENT, $user_agent);
}
@@ -97,6 +102,7 @@ class Curl {
}
private $_cookies = array();
private $_headers = array();
public $curl;
public $error = NULL;
+10
View File
@@ -80,4 +80,14 @@ class CurlTest extends PHPUnit_Framework_TestCase {
$this->assertTrue($test->curl->error === TRUE);
$this->assertTrue($test->curl->error_code === CURLE_OPERATION_TIMEOUTED);
}
public function testHeaders() {
$test = new Test();
$test->curl->setHeader('Content-Type', 'application/json');
$test->curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$test->curl->setHeader('Accept', 'application/json');
$this->assertTrue($test->server('GET', 'server', 'CONTENT_TYPE') === 'application/json');
$this->assertTrue($test->server('GET', 'server', 'HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest');
$this->assertTrue($test->server('GET', 'server', 'HTTP_ACCEPT') === 'application/json');
}
}