Skip to content
Permalink
Browse files

Test for new HEAD function inside HttpSocket

  • Loading branch information...
MelvinRoss committed Jul 14, 2014
1 parent ad4dbdc commit 0eaf650d9f1d4e79c4cc46436db6c9d04a162c53
0 lib/Cake/Network/CakeSocket.php 100755 → 100644
No changes.
@@ -463,6 +463,32 @@ public function get($uri = null, $query = array(), $request = array()) {
return $this->request($request);
}
/**
* Issues a HEAD request to the specified URI, query, and request.
*
* By definition HEAD request are identical to GET request except they return no response body. This means that all
* information and examples relevant to GET also applys to HEAD.
*
* @param string|array $uri URI to request. Either a string uri, or a uri array, see HttpSocket::_parseUri()
* @param array $query Querystring parameters to append to URI
* @param array $request An indexed array with indexes such as 'method' or uri
* @return mixed Result of request, either false on failure or the response to the request.
*/
public function head($uri = null, $query = array(), $request = array()) {
if (!empty($query)) {
$uri = $this->_parseUri($uri, $this->config['request']['uri']);
if (isset($uri['query'])) {
$uri['query'] = array_merge($uri['query'], $query);
} else {
$uri['query'] = $query;
}
$uri = $this->_buildUri($uri);
}
$request = Hash::merge(array('method' => 'HEAD', 'uri' => $uri), $request);
return $this->request($request);
}
/**
* Issues a POST request to the specified URI, query, and request.
*
@@ -524,19 +550,6 @@ public function delete($uri = null, $data = array(), $request = array()) {
return $this->request($request);
}
/**
* Issues a HEAD request to the specified URI, query, and request.
*
* @param string|array $uri URI to request (see {@link _parseUri()})
* @param array $data Array of request body data keys and values.
* @param array $request An indexed array with indexes such as 'method' or uri
* @return mixed Result of request
*/
public function head($uri = null, $data = array(), $request = array()) {
$request = Hash::merge(array('method' => 'HEAD', 'uri' => $uri, 'body' => $data), $request);
return $this->request($request);
}
/**
* Normalizes URLs into a $uriTemplate. If no template is provided
* a default one will be used. Will generate the URL using the
No changes.
@@ -1049,6 +1049,56 @@ public function testGet() {
));
}
/**
* testHead method
*
* @return void
*/
public function testHead() {
$this->RequestSocket->reset();
$this->RequestSocket->expects($this->at(0))
->method('request')
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/'));
$this->RequestSocket->expects($this->at(1))
->method('request')
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=bar'));
$this->RequestSocket->expects($this->at(2))
->method('request')
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=bar'));
$this->RequestSocket->expects($this->at(3))
->method('request')
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=23&foobar=42'));
$this->RequestSocket->expects($this->at(4))
->method('request')
->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/', 'version' => '1.0'));
$this->RequestSocket->expects($this->at(5))
->method('request')
->with(array('method' => 'HEAD', 'uri' => 'https://secure.example.com/test.php?one=two'));
$this->RequestSocket->expects($this->at(6))
->method('request')
->with(array('method' => 'HEAD', 'uri' => 'https://example.com/oauth/access?clientid=123&redirect_uri=http%3A%2F%2Fexample.com&code=456'));
$this->RequestSocket->head('http://www.google.com/');
$this->RequestSocket->head('http://www.google.com/', array('foo' => 'bar'));
$this->RequestSocket->head('http://www.google.com/', 'foo=bar');
$this->RequestSocket->head('http://www.google.com/?foo=bar', array('foobar' => '42', 'foo' => '23'));
$this->RequestSocket->head('http://www.google.com/', null, array('version' => '1.0'));
$this->RequestSocket->head('https://secure.example.com/test.php', array('one' => 'two'));
$this->RequestSocket->head('https://example.com/oauth/access', array(
'clientid' => '123',
'redirect_uri' => 'http://example.com',
'code' => 456
));
}
/**
* Test authentication
*

0 comments on commit 0eaf650

Please sign in to comment.
You can’t perform that action at this time.