Formatting

This commit is contained in:
Juan Basso 2010-12-04 01:23:07 -02:00
parent 3f910dc6c1
commit 123b2256c5

View file

@ -51,6 +51,10 @@ class TestAuthentication {
}
/**
* TestHttpSocket
*
*/
class TestHttpSocket extends HttpSocket {
/**
@ -59,7 +63,7 @@ class TestHttpSocket extends HttpSocket {
* @param mixed $uri URI (see {@link _parseUri()})
* @return array Current configuration settings
*/
function configUri($uri = null) {
public function configUri($uri = null) {
return parent::_configUri($uri);
}
@ -70,7 +74,7 @@ class TestHttpSocket extends HttpSocket {
* @param mixed $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
* @return array Parsed URI
*/
function parseUri($uri = null, $base = array()) {
public function parseUri($uri = null, $base = array()) {
return parent::_parseUri($uri, $base);
}
@ -81,7 +85,7 @@ class TestHttpSocket extends HttpSocket {
* @param string $uriTemplate The Uri template/format to use
* @return string A fully qualified URL formated according to $uriTemplate
*/
function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') {
public function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') {
return parent::_buildUri($uri, $uriTemplate);
}
@ -91,7 +95,7 @@ class TestHttpSocket extends HttpSocket {
* @param array $header Header to build
* @return string Header built from array
*/
function buildHeader($header, $mode = 'standard') {
public function buildHeader($header, $mode = 'standard') {
return parent::_buildHeader($header, $mode);
}
@ -101,7 +105,7 @@ class TestHttpSocket extends HttpSocket {
* @param string $message Message to parse
* @return array Parsed message (with indexed elements such as raw, status, header, body)
*/
function parseResponse($message) {
public function parseResponse($message) {
return parent::_parseResponse($message);
}
@ -111,7 +115,7 @@ class TestHttpSocket extends HttpSocket {
* @param array $header Header as an indexed array (field => value)
* @return array Parsed header
*/
function parseHeader($header) {
public function parseHeader($header) {
return parent::_parseHeader($header);
}
@ -121,7 +125,7 @@ class TestHttpSocket extends HttpSocket {
* @param mixed $query A query string to parse into an array or an array to return directly "as is"
* @return array The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned.
*/
function parseQuery($query) {
public function parseQuery($query) {
return parent::_parseQuery($query);
}
@ -132,7 +136,7 @@ class TestHttpSocket extends HttpSocket {
* @param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding
* @return mixed Array or false
*/
function decodeBody($body, $encoding = 'chunked') {
public function decodeBody($body, $encoding = 'chunked') {
return parent::_decodeBody($body, $encoding);
}
@ -142,7 +146,7 @@ class TestHttpSocket extends HttpSocket {
* @param string $body A string continaing the chunked body to decode
* @return mixed Array or false
*/
function decodeChunkedBody($body) {
public function decodeChunkedBody($body) {
return parent::_decodeChunkedBody($body);
}
@ -153,7 +157,7 @@ class TestHttpSocket extends HttpSocket {
* @param string $versionToken The version token to use, defaults to HTTP/1.1
* @return string Request line
*/
function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
public function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
return parent::_buildRequestLine($request, $versionToken);
}
@ -163,7 +167,7 @@ class TestHttpSocket extends HttpSocket {
* @param boolean $hex true to get them as HEX values, false otherwise
* @return array Escape chars
*/
function tokenEscapeChars($hex = true, $chars = null) {
public function tokenEscapeChars($hex = true, $chars = null) {
return parent::_tokenEscapeChars($hex, $chars);
}
@ -173,7 +177,7 @@ class TestHttpSocket extends HttpSocket {
* @param string $token Token to escape
* @return string Escaped token
*/
function EscapeToken($token, $chars = null) {
public function EscapeToken($token, $chars = null) {
return parent::_escapeToken($token, $chars);
}
@ -183,7 +187,7 @@ class TestHttpSocket extends HttpSocket {
* @param string $token Token to unescape
* @return string Unescaped token
*/
function unescapeToken($token, $chars = null) {
public function unescapeToken($token, $chars = null) {
return parent::_unescapeToken($token, $chars);
}
}
@ -200,7 +204,6 @@ class HttpSocketTest extends CakeTestCase {
* Socket property
*
* @var mixed null
* @access public
*/
public $Socket = null;
@ -208,17 +211,15 @@ class HttpSocketTest extends CakeTestCase {
* RequestSocket property
*
* @var mixed null
* @access public
*/
public $RequestSocket = null;
/**
* This function sets up a TestHttpSocket instance we are going to use for testing
*
* @access public
* @return void
*/
function setUp() {
public function setUp() {
if (!class_exists('MockHttpSocket')) {
$this->getMock('TestHttpSocket', array('read', 'write', 'connect'), array(), 'MockHttpSocket');
$this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array(), 'MockHttpSocketRequests');
@ -231,20 +232,18 @@ class HttpSocketTest extends CakeTestCase {
/**
* We use this function to clean up after the test case was executed
*
* @access public
* @return void
*/
function tearDown() {
public function tearDown() {
unset($this->Socket, $this->RequestSocket);
}
/**
* Test that HttpSocket::__construct does what one would expect it to do
*
* @access public
* @return void
*/
function testConstruct() {
public function testConstruct() {
$this->Socket->reset();
$baseConfig = $this->Socket->config;
$this->Socket->expects($this->never())->method('connect');
@ -270,10 +269,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* Test that HttpSocket::configUri works properly with different types of arguments
*
* @access public
* @return void
*/
function testConfigUri() {
public function testConfigUri() {
$this->Socket->reset();
$r = $this->Socket->configUri('https://bob:secret@www.cakephp.org:23/?query=foo');
$expected = array(
@ -284,11 +282,11 @@ class HttpSocketTest extends CakeTestCase {
'timeout' => 30,
'request' => array(
'uri' => array(
'scheme' => 'https'
, 'host' => 'www.cakephp.org'
, 'port' => 23
'scheme' => 'https',
'host' => 'www.cakephp.org',
'port' => 23
),
'cookies' => array(),
'cookies' => array()
)
);
$this->assertEquals($this->Socket->config, $expected);
@ -308,9 +306,9 @@ class HttpSocketTest extends CakeTestCase {
'timeout' => 30,
'request' => array(
'uri' => array(
'scheme' => 'http'
, 'host' => 'www.foo.com'
, 'port' => 80
'scheme' => 'http',
'host' => 'www.foo.com',
'port' => 80
),
'cookies' => array()
)
@ -328,191 +326,216 @@ class HttpSocketTest extends CakeTestCase {
/**
* Tests that HttpSocket::request (the heart of the HttpSocket) is working properly.
*
* @access public
* @return void
*/
function testRequest() {
public function testRequest() {
$this->Socket->reset();
$response = $this->Socket->request(true);
$this->assertFalse($response);
$tests = array(
0 => array(
'request' => 'http://www.cakephp.org/?foo=bar'
, 'expectation' => array(
array(
'request' => 'http://www.cakephp.org/?foo=bar',
'expectation' => array(
'config' => array(
'persistent' => false
, 'host' => 'www.cakephp.org'
, 'protocol' => 'tcp'
, 'port' => 80
, 'timeout' => 30
, 'request' => array(
'persistent' => false,
'host' => 'www.cakephp.org',
'protocol' => 'tcp',
'port' => 80,
'timeout' => 30,
'request' => array(
'uri' => array (
'scheme' => 'http'
, 'host' => 'www.cakephp.org'
, 'port' => 80,
'scheme' => 'http',
'host' => 'www.cakephp.org',
'port' => 80
),
'cookies' => array(),
'cookies' => array()
)
),
)
, 'request' => array(
'method' => 'GET'
, 'uri' => array(
'scheme' => 'http'
, 'host' => 'www.cakephp.org'
, 'port' => 80
, 'user' => null
, 'pass' => null
, 'path' => '/'
, 'query' => array('foo' => 'bar')
, 'fragment' => null
)
, 'version' => '1.1'
, 'body' => ''
, 'line' => "GET /?foo=bar HTTP/1.1\r\n"
, 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n"
, 'raw' => ""
, 'cookies' => array(),
'request' => array(
'method' => 'GET',
'uri' => array(
'scheme' => 'http',
'host' => 'www.cakephp.org',
'port' => 80,
'user' => null,
'pass' => null,
'path' => '/',
'query' => array('foo' => 'bar'),
'fragment' => null
),
'version' => '1.1',
'body' => '',
'line' => "GET /?foo=bar HTTP/1.1\r\n",
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n",
'raw' => "",
'cookies' => array()
)
)
)
, 1 => array(
),
array(
'request' => array(
'uri' => array(
'host' => 'www.cakephp.org'
, 'query' => '?foo=bar'
'host' => 'www.cakephp.org',
'query' => '?foo=bar'
)
)
)
, 2 => array(
),
array(
'request' => 'www.cakephp.org/?foo=bar'
)
, 3 => array(
'request' => array('host' => '192.168.0.1', 'uri' => 'http://www.cakephp.org/?foo=bar')
, 'expectation' => array(
),
array(
'request' => array(
'host' => '192.168.0.1',
'uri' => 'http://www.cakephp.org/?foo=bar'
),
'expectation' => array(
'request' => array(
'uri' => array('host' => 'www.cakephp.org')
)
, 'config' => array(
),
'config' => array(
'request' => array(
'uri' => array('host' => 'www.cakephp.org')
)
, 'host' => '192.168.0.1'
),
'host' => '192.168.0.1'
)
)
)
, 'reset4' => array(
),
'reset4' => array(
'request.uri.query' => array()
)
, 4 => array(
'request' => array('header' => array('Foo@woo' => 'bar-value'))
, 'expectation' => array(
),
array(
'request' => array(
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n"
, 'line' => "GET / HTTP/1.1\r\n"
'header' => array('Foo@woo' => 'bar-value')
),
'expectation' => array(
'request' => array(
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n",
'line' => "GET / HTTP/1.1\r\n"
)
)
)
, 5 => array(
'request' => array('header' => array('Foo@woo' => 'bar-value', 'host' => 'foo.com'), 'uri' => 'http://www.cakephp.org/')
, 'expectation' => array(
),
array(
'request' => array('header' => array('Foo@woo' => 'bar-value', 'host' => 'foo.com'), 'uri' => 'http://www.cakephp.org/'),
'expectation' => array(
'request' => array(
'header' => "Host: foo.com\r\nConnection: close\r\nUser-Agent: CakePHP\r\nFoo\"@\"woo: bar-value\r\n"
)
, 'config' => array(
),
'config' => array(
'host' => 'www.cakephp.org'
)
)
)
, 6 => array(
'request' => array('header' => "Foo: bar\r\n")
, 'expectation' => array(
),
array(
'request' => array('header' => "Foo: bar\r\n"),
'expectation' => array(
'request' => array(
'header' => "Foo: bar\r\n"
)
)
)
, 7 => array(
'request' => array('header' => "Foo: bar\r\n", 'uri' => 'http://www.cakephp.org/search?q=http_socket#ignore-me')
, 'expectation' => array(
),
array(
'request' => array('header' => "Foo: bar\r\n", 'uri' => 'http://www.cakephp.org/search?q=http_socket#ignore-me'),
'expectation' => array(
'request' => array(
'uri' => array(
'path' => '/search'
, 'query' => array('q' => 'http_socket')
, 'fragment' => 'ignore-me'
)
, 'line' => "GET /search?q=http_socket HTTP/1.1\r\n"
'path' => '/search',
'query' => array('q' => 'http_socket'),
'fragment' => 'ignore-me'
),
'line' => "GET /search?q=http_socket HTTP/1.1\r\n"
)
)
)
, 'reset8' => array(
),
'reset8' => array(
'request.uri.query' => array()
)
, 8 => array(
'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
, 'expectation' => array(
),
array(
'request' => array(
'method' => 'POST'
, 'uri' => array(
'path' => '/posts/add'
, 'fragment' => null
'method' => 'POST',
'uri' => 'http://www.cakephp.org/posts/add',
'body' => array(
'name' => 'HttpSocket-is-released',
'date' => 'today'
)
, 'body' => "name=HttpSocket-is-released&date=today"
, 'line' => "POST /posts/add HTTP/1.1\r\n"
, 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
, 'raw' => "name=HttpSocket-is-released&date=today"
),
'expectation' => array(
'request' => array(
'method' => 'POST',
'uri' => array(
'path' => '/posts/add',
'fragment' => null
),
'body' => "name=HttpSocket-is-released&date=today",
'line' => "POST /posts/add HTTP/1.1\r\n",
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n",
'raw' => "name=HttpSocket-is-released&date=today"
)
)
),
array(
'request' => array(
'method' => 'POST',
'uri' => 'http://www.cakephp.org:8080/posts/add',
'body' => array(
'name' => 'HttpSocket-is-released',
'date' => 'today'
)
, 9 => array(
'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org:8080/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
, 'expectation' => array(
),
'expectation' => array(
'config' => array(
'port' => 8080
, 'request' => array(
'port' => 8080,
'request' => array(
'uri' => array(
'port' => 8080
)
)
)
, 'request' => array(
),
'request' => array(
'uri' => array(
'port' => 8080
)
, 'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
),
'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
)
)
),
array(
'request' => array(
'method' => 'POST',
'uri' => 'https://www.cakephp.org/posts/add',
'body' => array(
'name' => 'HttpSocket-is-released',
'date' => 'today'
)
, 10 => array(
'request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
, 'expectation' => array(
),
'expectation' => array(
'config' => array(
'port' => 443,
'request' => array(
'uri' => array(
'scheme' => 'https',
'port' => 443
, 'request' => array(
)
)
),
'request' => array(
'uri' => array(
'scheme' => 'https'
, 'port' => 443
'scheme' => 'https',
'port' => 443
),
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
)
)
)
, 'request' => array(
'uri' => array(
'scheme' => 'https'
, 'port' => 443
)
, 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
)
)
)
, 11 => array(
),
array(
'request' => array(
'method' => 'POST',
'uri' => 'https://www.cakephp.org/posts/add',
'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'),
'cookies' => array('foo' => array('value' => 'bar'))
)
, 'expectation' => array(
),
'expectation' => array(
'request' => array(
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n",
'cookies' => array(
@ -538,10 +561,10 @@ class HttpSocketTest extends CakeTestCase {
$this->Socket->request($test['request']);
$raw = $expectation['request']['raw'];
$expectation['request']['raw'] = $expectation['request']['line'].$expectation['request']['header']."\r\n".$raw;
$expectation['request']['raw'] = $expectation['request']['line'] . $expectation['request']['header'] . "\r\n" . $raw;
$r = array('config' => $this->Socket->config, 'request' => $this->Socket->request);
$v = $this->assertEquals($r, $expectation, 'Failed test #'.$i.' ');
$v = $this->assertEquals($r, $expectation, 'Failed test #' . $i . ' ');
$expectation['request']['raw'] = $raw;
}
@ -560,10 +583,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testRequest2 method
*
* @access public
* @return void
*/
function testRequest2() {
public function testRequest2() {
$this->Socket->reset();
$request = array('uri' => 'htpp://www.cakephp.org/');
$number = mt_rand(0, 9999999);
@ -580,10 +602,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testRequest3 method
*
* @access public
* @return void
*/
function testRequest3() {
public function testRequest3() {
$request = array('uri' => 'htpp://www.cakephp.org/');
$serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a cookie test!</h1>";
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
@ -605,7 +626,7 @@ class HttpSocketTest extends CakeTestCase {
*
* @return void
*/
function testProxy() {
public function testProxy() {
$this->Socket->reset();
$this->Socket->expects($this->any())->method('connect')->will($this->returnValue(true));
$this->Socket->expects($this->any())->method('read')->will($this->returnValue(false));
@ -633,10 +654,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testUrl method
*
* @access public
* @return void
*/
function testUrl() {
public function testUrl() {
$this->Socket->reset(true);
$this->assertEquals($this->Socket->url(true), false);
@ -688,10 +708,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testGet method
*
* @access public
* @return void
*/
function testGet() {
public function testGet() {
$this->RequestSocket->reset();
$this->RequestSocket->expects($this->at(0))
@ -745,7 +764,7 @@ class HttpSocketTest extends CakeTestCase {
*
* @return void
*/
function testConsecutiveGetResetsAuthCredentials() {
public function testConsecutiveGetResetsAuthCredentials() {
$socket = new MockHttpSocket();
$socket->get('http://mark:secret@example.com/test');
$this->assertEqual($socket->request['uri']['user'], 'mark');
@ -762,10 +781,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testPostPutDelete method
*
* @access public
* @return void
*/
function testPost() {
public function testPost() {
$this->RequestSocket->reset();
$this->RequestSocket->expects($this->at(0))
->method('request')
@ -784,7 +802,12 @@ class HttpSocketTest extends CakeTestCase {
$this->RequestSocket->post('http://www.google.com/', null, array('line' => 'Hey Server'));
}
function testPut() {
/**
* testPut
*
* @return void
*/
public function testPut() {
$this->RequestSocket->reset();
$this->RequestSocket->expects($this->at(0))
->method('request')
@ -803,7 +826,12 @@ class HttpSocketTest extends CakeTestCase {
$this->RequestSocket->put('http://www.google.com/', null, array('line' => 'Hey Server'));
}
function testDelete() {
/**
* testDelete
*
* @return void
*/
public function testDelete() {
$this->RequestSocket->reset();
$this->RequestSocket->expects($this->at(0))
->method('request')
@ -825,10 +853,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testParseResponse method
*
* @access public
* @return void
*/
function testParseResponse() {
public function testParseResponse() {
$this->Socket->reset();
$r = $this->Socket->parseResponse(array('foo' => 'bar'));
@ -846,8 +873,8 @@ class HttpSocketTest extends CakeTestCase {
'status-line' => "HTTP/1.x 200 OK\r\n",
'header' => "Date: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n",
'body' => "<h1>Hello World</h1>\r\n<p>It's good to be html</p>"
)
, 'expectations' => array(
),
'expectations' => array(
'status.http-version' => 'HTTP/1.x',
'status.code' => 200,
'status.reason-phrase' => 'OK',
@ -858,9 +885,9 @@ class HttpSocketTest extends CakeTestCase {
'no-header' => array(
'response' => array(
'status-line' => "HTTP/1.x 404 OK\r\n",
'header' => null,
)
, 'expectations' => array(
'header' => null
),
'expectations' => array(
'status.code' => 404,
'header' => array()
)
@ -897,19 +924,18 @@ class HttpSocketTest extends CakeTestCase {
$expectations = array();
foreach ($tests as $name => $test) {
$testResponse = array_merge($testResponse, $test['response']);
$testResponse['response'] = $testResponse['status-line'].$testResponse['header']."\r\n".$testResponse['body'];
$testResponse['response'] = $testResponse['status-line'] . $testResponse['header'] . "\r\n" . $testResponse['body'];
$r = $this->Socket->parseResponse($testResponse['response']);
$expectations = array_merge($expectations, $test['expectations']);
foreach ($expectations as $property => $expectedVal) {
$val = Set::extract($r, $property);
$this->assertEquals($val, $expectedVal, 'Test "'.$name.'": response.'.$property.' - %s');
$this->assertEquals($val, $expectedVal, 'Test "' . $name . '": response.' . $property . ' - %s');
}
foreach (array('status-line', 'header', 'body', 'response') as $field) {
$this->assertEquals($r['raw'][$field], $testResponse[$field], 'Test response.raw.'.$field.': %s');
$this->assertEquals($r['raw'][$field], $testResponse[$field], 'Test response.raw.' . $field . ': %s');
}
}
}
@ -917,10 +943,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testDecodeBody method
*
* @access public
* @return void
*/
function testDecodeBody() {
public function testDecodeBody() {
$this->Socket->reset();
$r = $this->Socket->decodeBody(true);
@ -939,7 +964,12 @@ class HttpSocketTest extends CakeTestCase {
$this->assertEquals($r, $sample['decoded']);
}
function testDecodeFooCoded() {
/**
* testDecodeFooCoded
*
* @return void
*/
public function testDecodeFooCoded() {
$this->Socket->reset();
$r = $this->Socket->decodeBody(true);
@ -967,10 +997,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testDecodeChunkedBody method
*
* @access public
* @return void
*/
function testDecodeChunkedBody() {
public function testDecodeChunkedBody() {
$this->Socket->reset();
$r = $this->Socket->decodeChunkedBody(true);
@ -1023,10 +1052,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testBuildRequestLine method
*
* @access public
* @return void
*/
function testBuildRequestLine() {
public function testBuildRequestLine() {
$this->Socket->reset();
$this->Socket->quirksMode = true;
@ -1076,10 +1104,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testBadBuildRequestLine method
*
* @access public
* @return void
*/
function testBadBuildRequestLine() {
public function testBadBuildRequestLine() {
$this->expectError();
$r = $this->Socket->buildRequestLine('Foo');
}
@ -1087,10 +1114,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testBadBuildRequestLine2 method
*
* @access public
* @return void
*/
function testBadBuildRequestLine2() {
public function testBadBuildRequestLine2() {
$this->expectError();
$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
}
@ -1098,10 +1124,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* Asserts that HttpSocket::parseUri is working properly
*
* @access public
* @return void
*/
function testParseUri() {
public function testParseUri() {
$this->Socket->reset();
$uri = $this->Socket->parseUri(array('invalid' => 'uri-string'));
@ -1132,7 +1157,7 @@ class HttpSocketTest extends CakeTestCase {
$this->assertEquals($uri, array(
'scheme' => 'http',
'host' => 'www.cakephp.org',
'path' => '/',
'path' => '/'
));
$uri = $this->Socket->parseUri('http://www.cakephp.org', true);
@ -1197,7 +1222,7 @@ class HttpSocketTest extends CakeTestCase {
$this->assertEquals($uri, array(
'scheme' => 'http',
'host' => 'www.google.com',
'port' => 8080,
'port' => 8080
));
$uri = $this->Socket->parseUri('http://www.cakephp.org/?param1=value1&param2=value2%3Dvalue3');
@ -1226,10 +1251,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* Tests that HttpSocket::buildUri can turn all kinds of uri arrays (and strings) into fully or partially qualified URI's
*
* @access public
* @return void
*/
function testBuildUri() {
public function testBuildUri() {
$this->Socket->reset();
$r = $this->Socket->buildUri(true);
@ -1293,10 +1317,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* Asserts that HttpSocket::parseQuery is working properly
*
* @access public
* @return void
*/
function testParseQuery() {
public function testParseQuery() {
$this->Socket->reset();
$query = $this->Socket->parseQuery(array('framework' => 'cakephp'));
@ -1345,16 +1368,10 @@ class HttpSocketTest extends CakeTestCase {
$query = $this->Socket->parseQuery('a[][]=foo&a[bar]=php&a[][]=bar&a[][]=cake');
$expectedQuery = array(
'a' => array(
0 => array(
0 => 'foo'
),
array('foo'),
'bar' => 'php',
1 => array(
0 => 'bar'
),
array(
0 => 'cake'
)
array('bar'),
array('cake')
)
);
$this->assertEquals($query, $expectedQuery);
@ -1400,10 +1417,9 @@ class HttpSocketTest extends CakeTestCase {
* Tests that HttpSocket::buildHeader can turn a given $header array into a proper header string according to
* HTTP 1.1 specs.
*
* @access public
* @return void
*/
function testBuildHeader() {
public function testBuildHeader() {
$this->Socket->reset();
$r = $this->Socket->buildHeader(true);
@ -1438,10 +1454,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* Test that HttpSocket::parseHeader can take apart a given (and valid) $header string and turn it into an array.
*
* @access public
* @return void
*/
function testParseHeader() {
public function testParseHeader() {
$this->Socket->reset();
$r = $this->Socket->parseHeader(array('foo' => 'Bar', 'fOO-bAr' => 'quux'));
@ -1460,17 +1475,17 @@ class HttpSocketTest extends CakeTestCase {
$header = "Date:Sat, 07 Apr 2007 10:10:25 GMT\r\nX-Powered-By: PHP/5.1.2\r\n";
$r = $this->Socket->parseHeader($header);
$expected = array(
'Date' => 'Sat, 07 Apr 2007 10:10:25 GMT'
, 'X-Powered-By' => 'PHP/5.1.2'
'Date' => 'Sat, 07 Apr 2007 10:10:25 GMT',
'X-Powered-By' => 'PHP/5.1.2'
);
$this->assertEquals($r, $expected);
$header = "people: Jim,John\r\nfoo-LAND: Bar\r\ncAKe-PHP: rocks\r\n";
$r = $this->Socket->parseHeader($header);
$expected = array(
'people' => 'Jim,John'
, 'foo-LAND' => 'Bar'
, 'cAKe-PHP' => 'rocks'
'people' => 'Jim,John',
'foo-LAND' => 'Bar',
'cAKe-PHP' => 'rocks'
);
$this->assertEquals($r, $expected);
@ -1484,8 +1499,8 @@ class HttpSocketTest extends CakeTestCase {
$header = "Multi-Line: I am a \r\nmulti line\t\r\nfield value.\r\nSingle-Line: I am not\r\n";
$r = $this->Socket->parseHeader($header);
$expected = array(
'Multi-Line' => "I am a\r\nmulti line\r\nfield value."
, 'Single-Line' => 'I am not'
'Multi-Line' => "I am a\r\nmulti line\r\nfield value.",
'Single-Line' => 'I am not'
);
$this->assertEquals($r, $expected);
@ -1500,10 +1515,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* testParseCookies method
*
* @access public
* @return void
*/
function testParseCookies() {
public function testParseCookies() {
$header = array(
'Set-Cookie' => array(
'foo=bar',
@ -1543,10 +1557,9 @@ class HttpSocketTest extends CakeTestCase {
* testBuildCookies method
*
* @return void
* @access public
* @todo Test more scenarios
*/
function testBuildCookies() {
public function testBuildCookies() {
$cookies = array(
'foo' => array(
'value' => 'bar'
@ -1564,10 +1577,9 @@ class HttpSocketTest extends CakeTestCase {
/**
* Tests that HttpSocket::_tokenEscapeChars() returns the right characters.
*
* @access public
* @return void
*/
function testTokenEscapeChars() {
public function testTokenEscapeChars() {
$this->Socket->reset();
$expected = array(
@ -1590,19 +1602,18 @@ class HttpSocketTest extends CakeTestCase {
/**
* Test that HttpSocket::escapeToken is escaping all characters as descriped in RFC 2616 (HTTP 1.1 specs)
*
* @access public
* @return void
*/
function testEscapeToken() {
public function testEscapeToken() {
$this->Socket->reset();
$this->assertEquals($this->Socket->escapeToken('Foo'), 'Foo');
$escape = $this->Socket->tokenEscapeChars(false);
foreach ($escape as $char) {
$token = 'My-special-'.$char.'-Token';
$token = 'My-special-' . $char . '-Token';
$escapedToken = $this->Socket->escapeToken($token);
$expectedToken = 'My-special-"'.$char.'"-Token';
$expectedToken = 'My-special-"' . $char . '"-Token';
$this->assertEquals($escapedToken, $expectedToken, 'Test token escaping for ASCII '.ord($char));
}
@ -1616,19 +1627,18 @@ class HttpSocketTest extends CakeTestCase {
/**
* Test that escaped token strings are properly unescaped by HttpSocket::unescapeToken
*
* @access public
* @return void
*/
function testUnescapeToken() {
public function testUnescapeToken() {
$this->Socket->reset();
$this->assertEquals($this->Socket->unescapeToken('Foo'), 'Foo');
$escape = $this->Socket->tokenEscapeChars(false);
foreach ($escape as $char) {
$token = 'My-special-"'.$char.'"-Token';
$token = 'My-special-"' . $char . '"-Token';
$unescapedToken = $this->Socket->unescapeToken($token);
$expectedToken = 'My-special-'.$char.'-Token';
$expectedToken = 'My-special-' . $char . '-Token';
$this->assertEquals($unescapedToken, $expectedToken, 'Test token unescaping for ASCII '.ord($char));
}
@ -1643,10 +1653,9 @@ class HttpSocketTest extends CakeTestCase {
* This tests asserts HttpSocket::reset() resets a HttpSocket instance to it's initial state (before Object::__construct
* got executed)
*
* @access public
* @return void
*/
function testReset() {
public function testReset() {
$this->Socket->reset();
$initialState = get_class_vars('HttpSocket');
@ -1667,10 +1676,9 @@ class HttpSocketTest extends CakeTestCase {
* This tests asserts HttpSocket::reset(false) resets certain HttpSocket properties to their initial state (before
* Object::__construct got executed).
*
* @access public
* @return void
*/
function testPartialReset() {
public function testPartialReset() {
$this->Socket->reset();
$partialResetProperties = array('request', 'response');