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