Skip to content

Commit

Permalink
Test for new HEAD function inside HttpSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
MelvinRoss committed Jul 14, 2014
1 parent ad4dbdc commit 0eaf650
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 13 deletions.
Empty file modified lib/Cake/Network/CakeSocket.php 100755 → 100644
Empty file.
39 changes: 26 additions & 13 deletions lib/Cake/Network/Http/HttpSocket.php 100755 → 100644
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
Empty file modified lib/Cake/Test/Case/Network/CakeSocketTest.php 100755 → 100644
Empty file.
50 changes: 50 additions & 0 deletions lib/Cake/Test/Case/Network/Http/HttpSocketTest.php 100755 → 100644
Expand Up @@ -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
*
Expand Down

0 comments on commit 0eaf650

Please sign in to comment.