mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-05 23:53:38 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* HttpSocketTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.Network.Http
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('HttpSocket', 'Network/Http');
|
||||
|
@ -24,15 +23,14 @@ App::uses('HttpResponse', 'Network/Http');
|
|||
* TestAuthentication class
|
||||
*
|
||||
* @package Cake.Test.Case.Network.Http
|
||||
* @package Cake.Test.Case.Network.Http
|
||||
*/
|
||||
class TestAuthentication {
|
||||
|
||||
/**
|
||||
* authentication method
|
||||
*
|
||||
* @param HttpSocket $http
|
||||
* @param array $authInfo
|
||||
* @param HttpSocket $http A HTTP socket.
|
||||
* @param array &$authInfo Some auth info.
|
||||
* @return void
|
||||
*/
|
||||
public static function authentication(HttpSocket $http, &$authInfo) {
|
||||
|
@ -42,8 +40,8 @@ class TestAuthentication {
|
|||
/**
|
||||
* proxyAuthentication method
|
||||
*
|
||||
* @param HttpSocket $http
|
||||
* @param array $proxyInfo
|
||||
* @param HttpSocket $http A HTTP socket.
|
||||
* @param array &$proxyInfo Some proxy info.
|
||||
* @return void
|
||||
*/
|
||||
public static function proxyAuthentication(HttpSocket $http, &$proxyInfo) {
|
||||
|
@ -54,7 +52,6 @@ class TestAuthentication {
|
|||
|
||||
/**
|
||||
* CustomResponse
|
||||
*
|
||||
*/
|
||||
class CustomResponse {
|
||||
|
||||
|
@ -68,6 +65,7 @@ class CustomResponse {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message A message.
|
||||
*/
|
||||
public function __construct($message) {
|
||||
$this->first10 = substr($message, 0, 10);
|
||||
|
@ -77,7 +75,6 @@ class CustomResponse {
|
|||
|
||||
/**
|
||||
* TestHttpSocket
|
||||
*
|
||||
*/
|
||||
class TestHttpSocket extends HttpSocket {
|
||||
|
||||
|
@ -95,7 +92,7 @@ class TestHttpSocket extends HttpSocket {
|
|||
* Convenience method for testing protected method
|
||||
*
|
||||
* @param string|array $uri URI to parse
|
||||
* @param boolean|array $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
|
||||
* @param bool|array $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
|
||||
* @return array Parsed URI
|
||||
*/
|
||||
public function parseUri($uri = null, $base = array()) {
|
||||
|
@ -137,17 +134,16 @@ class TestHttpSocket extends HttpSocket {
|
|||
* Convenience method for testing protected method
|
||||
*
|
||||
* @param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
|
||||
* @param string $versionToken The version token to use, defaults to HTTP/1.1
|
||||
* @return string Request line
|
||||
*/
|
||||
public function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
|
||||
return parent::_buildRequestLine($request, $versionToken);
|
||||
public function buildRequestLine($request = array()) {
|
||||
return parent::_buildRequestLine($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for testing protected method
|
||||
*
|
||||
* @param boolean $hex true to get them as HEX values, false otherwise
|
||||
* @param bool $hex true to get them as HEX values, false otherwise
|
||||
* @return array Escape chars
|
||||
*/
|
||||
public function tokenEscapeChars($hex = true, $chars = null) {
|
||||
|
@ -176,14 +172,14 @@ class HttpSocketTest extends CakeTestCase {
|
|||
/**
|
||||
* Socket property
|
||||
*
|
||||
* @var mixed null
|
||||
* @var mixed
|
||||
*/
|
||||
public $Socket = null;
|
||||
|
||||
/**
|
||||
* RequestSocket property
|
||||
*
|
||||
* @var mixed null
|
||||
* @var mixed
|
||||
*/
|
||||
public $RequestSocket = null;
|
||||
|
||||
|
@ -193,13 +189,9 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
$this->Socket = new MockHttpSocket();
|
||||
$this->RequestSocket = new MockHttpSocketRequests();
|
||||
parent::setUp();
|
||||
$this->Socket = $this->getMock('TestHttpSocket', array('read', 'write', 'connect'));
|
||||
$this->RequestSocket = $this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,6 +200,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
unset($this->Socket, $this->RequestSocket);
|
||||
}
|
||||
|
||||
|
@ -221,8 +214,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$baseConfig = $this->Socket->config;
|
||||
$this->Socket->expects($this->never())->method('connect');
|
||||
$this->Socket->__construct(array('host' => 'foo-bar'));
|
||||
$baseConfig['host'] = 'foo-bar';
|
||||
$baseConfig['protocol'] = getprotobyname($baseConfig['protocol']);
|
||||
$baseConfig['host'] = 'foo-bar';
|
||||
$this->assertEquals($this->Socket->config, $baseConfig);
|
||||
|
||||
$this->Socket->reset();
|
||||
|
@ -231,7 +223,6 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$baseConfig['host'] = $baseConfig['request']['uri']['host'] = 'www.cakephp.org';
|
||||
$baseConfig['port'] = $baseConfig['request']['uri']['port'] = 23;
|
||||
$baseConfig['request']['uri']['scheme'] = 'http';
|
||||
$baseConfig['protocol'] = getprotobyname($baseConfig['protocol']);
|
||||
$this->assertEquals($this->Socket->config, $baseConfig);
|
||||
|
||||
$this->Socket->reset();
|
||||
|
@ -253,6 +244,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'protocol' => 'tcp',
|
||||
'port' => 23,
|
||||
'timeout' => 30,
|
||||
'ssl_verify_peer' => true,
|
||||
'ssl_allow_self_signed' => false,
|
||||
'ssl_verify_depth' => 5,
|
||||
'ssl_verify_host' => true,
|
||||
'request' => array(
|
||||
'uri' => array(
|
||||
'scheme' => 'https',
|
||||
|
@ -260,7 +255,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'port' => 23
|
||||
),
|
||||
'redirect' => false,
|
||||
'cookies' => array()
|
||||
'cookies' => array(),
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $this->Socket->config);
|
||||
|
@ -278,6 +273,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'protocol' => 'tcp',
|
||||
'port' => 80,
|
||||
'timeout' => 30,
|
||||
'ssl_verify_peer' => true,
|
||||
'ssl_allow_self_signed' => false,
|
||||
'ssl_verify_depth' => 5,
|
||||
'ssl_verify_host' => true,
|
||||
'request' => array(
|
||||
'uri' => array(
|
||||
'scheme' => 'http',
|
||||
|
@ -285,7 +284,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'port' => 80
|
||||
),
|
||||
'redirect' => false,
|
||||
'cookies' => array()
|
||||
'cookies' => array(),
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $this->Socket->config);
|
||||
|
@ -306,6 +305,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testRequest() {
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->Socket->reset();
|
||||
|
||||
$response = $this->Socket->request(true);
|
||||
|
@ -321,6 +324,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'protocol' => 'tcp',
|
||||
'port' => 80,
|
||||
'timeout' => 30,
|
||||
'ssl_verify_peer' => true,
|
||||
'ssl_allow_self_signed' => false,
|
||||
'ssl_verify_depth' => 5,
|
||||
'ssl_verify_host' => true,
|
||||
'request' => array(
|
||||
'uri' => array(
|
||||
'scheme' => 'http',
|
||||
|
@ -481,6 +488,9 @@ class HttpSocketTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
),
|
||||
'reset10' => array(
|
||||
'config.protocol' => 'ssl'
|
||||
),
|
||||
array(
|
||||
'request' => array(
|
||||
'method' => 'POST',
|
||||
|
@ -509,8 +519,12 @@ class HttpSocketTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
),
|
||||
'reset11' => array(
|
||||
'config.protocol' => 'ssl'
|
||||
),
|
||||
array(
|
||||
'request' => array(
|
||||
'version' => '1.0',
|
||||
'method' => 'POST',
|
||||
'uri' => 'https://www.cakephp.org/posts/add',
|
||||
'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'),
|
||||
|
@ -518,6 +532,8 @@ class HttpSocketTest extends CakeTestCase {
|
|||
),
|
||||
'expectation' => array(
|
||||
'request' => array(
|
||||
'version' => '1.0',
|
||||
'line' => "POST /posts/add HTTP/1.0\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(
|
||||
'foo' => array('value' => 'bar'),
|
||||
|
@ -545,13 +561,13 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$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 . ' ');
|
||||
$this->assertEquals($r, $expectation, 'Failed test #' . $i . ' ');
|
||||
$expectation['request']['raw'] = $raw;
|
||||
}
|
||||
|
||||
$this->Socket->reset();
|
||||
$request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'));
|
||||
$response = $this->Socket->request($request);
|
||||
$this->Socket->request($request);
|
||||
$this->assertEquals("name=HttpSocket-is-released&date=today", $this->Socket->request['body']);
|
||||
}
|
||||
|
||||
|
@ -561,6 +577,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testGetWithSchemeAndPort() {
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->Socket->reset();
|
||||
$request = array(
|
||||
'uri' => array(
|
||||
|
@ -571,16 +591,20 @@ class HttpSocketTest extends CakeTestCase {
|
|||
),
|
||||
'method' => 'GET'
|
||||
);
|
||||
$response = $this->Socket->request($request);
|
||||
$this->Socket->request($request);
|
||||
$this->assertContains('Host: cakephp.org:8080', $this->Socket->request['header']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test urls like http://cakephp.org/index.php?somestring without key/value pair for query
|
||||
* Test URLs like http://cakephp.org/index.php?somestring without key/value pair for query
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRequestWithStringQuery() {
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->Socket->reset();
|
||||
$request = array(
|
||||
'uri' => array(
|
||||
|
@ -591,7 +615,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
),
|
||||
'method' => 'GET'
|
||||
);
|
||||
$response = $this->Socket->request($request);
|
||||
$this->Socket->request($request);
|
||||
$this->assertContains("GET /index.php?somestring HTTP/1.1", $this->Socket->request['line']);
|
||||
}
|
||||
|
||||
|
@ -604,7 +628,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
public function testRequestNotAllowedUri() {
|
||||
$this->Socket->reset();
|
||||
$request = array('uri' => '*', 'method' => 'GET');
|
||||
$response = $this->Socket->request($request);
|
||||
$this->Socket->request($request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -614,14 +638,18 @@ class HttpSocketTest extends CakeTestCase {
|
|||
*/
|
||||
public function testRequest2() {
|
||||
$this->Socket->reset();
|
||||
|
||||
$request = array('uri' => 'htpp://www.cakephp.org/');
|
||||
$number = mt_rand(0, 9999999);
|
||||
$this->Socket->expects($this->once())->method('connect')->will($this->returnValue(true));
|
||||
$this->Socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
||||
$serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>Hello, your lucky number is " . $number . "</h1>";
|
||||
$this->Socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->once())->method('write')
|
||||
$this->Socket->expects($this->at(0))->method('write')
|
||||
->with("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n");
|
||||
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse, false));
|
||||
|
||||
$response = (string)$this->Socket->request($request);
|
||||
$this->assertEquals($response, "<h1>Hello, your lucky number is " . $number . "</h1>");
|
||||
}
|
||||
|
@ -634,17 +662,21 @@ class HttpSocketTest extends CakeTestCase {
|
|||
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));
|
||||
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse, false));
|
||||
|
||||
$this->Socket->connected = true;
|
||||
$this->Socket->request($request);
|
||||
$result = $this->Socket->response['cookies'];
|
||||
$expect = array(
|
||||
$expected = array(
|
||||
'foo' => array(
|
||||
'value' => 'bar'
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expect, $result);
|
||||
$this->assertEquals($this->Socket->config['request']['cookies']['www.cakephp.org'], $expect);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($expected, $this->Socket->config['request']['cookies']['www.cakephp.org']);
|
||||
$this->assertFalse($this->Socket->connected);
|
||||
}
|
||||
|
||||
|
@ -665,7 +697,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
);
|
||||
$http = new MockHttpSocketRequests($request);
|
||||
$http = $this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array($request));
|
||||
|
||||
$expected = array('method' => 'GET', 'uri' => '/_test');
|
||||
$http->expects($this->at(0))->method('request')->with($expected);
|
||||
|
@ -683,9 +715,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
*/
|
||||
public function testRequestWithResource() {
|
||||
$serverResponse = "HTTP/1.x 200 OK\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 test!</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse));
|
||||
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse, false, $serverResponse, false));
|
||||
$this->Socket->connected = true;
|
||||
|
||||
$f = fopen(TMP . 'download.txt', 'w');
|
||||
|
@ -716,8 +749,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$this->Socket->config['request']['cookies'] = array();
|
||||
|
||||
$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 test!</h1>";
|
||||
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
|
||||
$expected = array('www.cakephp.org' => array('foo' => array('value' => 'bar')));
|
||||
$this->Socket->request('http://www.cakephp.org/');
|
||||
$this->assertEquals($expected, $this->Socket->config['request']['cookies']);
|
||||
|
@ -753,8 +788,9 @@ class HttpSocketTest extends CakeTestCase {
|
|||
public function testRequestCustomResponse() {
|
||||
$this->Socket->connected = true;
|
||||
$serverResponse = "HTTP/1.x 200 OK\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 test!</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse));
|
||||
$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false));
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse, false));
|
||||
|
||||
$this->Socket->responseClass = 'CustomResponse';
|
||||
$response = $this->Socket->request('http://www.cakephp.org/');
|
||||
|
@ -763,7 +799,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that redirect urls are urldecoded
|
||||
* Test that redirect URLs are urldecoded
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -772,7 +808,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'uri' => 'http://localhost/oneuri',
|
||||
'redirect' => 1
|
||||
);
|
||||
$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://i.cmpnet.com%2Ftechonline%2Fpdf%2Fa.pdf=\r\n\r\n";
|
||||
$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://i.cmpnet.com%2Ftechonline%2Fpdf%2Fa+b.pdf=\r\n\r\n";
|
||||
$serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>";
|
||||
|
||||
$this->Socket->expects($this->at(1))
|
||||
|
@ -783,12 +819,14 @@ class HttpSocketTest extends CakeTestCase {
|
|||
->method('write')
|
||||
->with($this->logicalAnd(
|
||||
$this->stringContains('Host: i.cmpnet.com'),
|
||||
$this->stringContains('GET /techonline/pdf/a.pdf')
|
||||
$this->stringContains('GET /techonline/pdf/a+b.pdf')
|
||||
));
|
||||
|
||||
$this->Socket->expects($this->at(4))
|
||||
->method('read')
|
||||
->will($this->returnValue($serverResponse2));
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')->will($this->returnValue(false));
|
||||
|
||||
$response = $this->Socket->request($request);
|
||||
$this->assertEquals('<h1>You have been redirected</h1>', $response->body());
|
||||
|
@ -806,8 +844,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
);
|
||||
$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/anotheruri\r\n\r\n";
|
||||
$serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse1));
|
||||
$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse2));
|
||||
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse1, false, $serverResponse2, false));
|
||||
|
||||
$response = $this->Socket->request($request);
|
||||
$this->assertEquals('<h1>You have been redirected</h1>', $response->body());
|
||||
|
@ -825,10 +865,12 @@ class HttpSocketTest extends CakeTestCase {
|
|||
);
|
||||
$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/anotheruri\r\n\r\n";
|
||||
$serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse1));
|
||||
$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse2));
|
||||
|
||||
$response = $this->Socket->request($request);
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse1, false, $serverResponse2, false));
|
||||
|
||||
$this->Socket->request($request);
|
||||
$this->assertEquals(1, $this->Socket->request['redirect']);
|
||||
}
|
||||
|
||||
|
@ -844,8 +886,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
);
|
||||
$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/oneruri\r\n\r\n";
|
||||
$serverResponse2 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/anotheruri\r\n\r\n";
|
||||
$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse1));
|
||||
$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse2));
|
||||
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse1, false, $serverResponse2, false));
|
||||
|
||||
$response = $this->Socket->request($request);
|
||||
$this->assertEquals(0, $this->Socket->request['redirect']);
|
||||
|
@ -1031,23 +1075,96 @@ class HttpSocketTest extends CakeTestCase {
|
|||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the head 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
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuth() {
|
||||
$socket = new MockHttpSocket();
|
||||
$socket->get('http://mark:secret@example.com/test');
|
||||
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')->will($this->returnValue(false));
|
||||
|
||||
$socket->configAuth(false);
|
||||
$socket->get('http://example.com/test');
|
||||
$this->assertFalse(strpos($socket->request['header'], 'Authorization:'));
|
||||
$this->Socket->get('http://mark:secret@example.com/test');
|
||||
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
|
||||
$socket->configAuth('Test', 'mark', 'passwd');
|
||||
$socket->get('http://example.com/test');
|
||||
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false);
|
||||
$this->Socket->configAuth(false);
|
||||
$this->Socket->get('http://example.com/test');
|
||||
$this->assertFalse(strpos($this->Socket->request['header'], 'Authorization:'));
|
||||
|
||||
$this->Socket->configAuth('Test', 'mark', 'passwd');
|
||||
$this->Socket->get('http://example.com/test');
|
||||
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Test mark.passwd') !== false);
|
||||
|
||||
$this->Socket->configAuth(false);
|
||||
$this->Socket->request(array(
|
||||
'method' => 'GET',
|
||||
'uri' => 'http://example.com/test',
|
||||
'auth' => array(
|
||||
'method' => 'Basic',
|
||||
'user' => 'joel',
|
||||
'pass' => 'hunter2'
|
||||
)
|
||||
));
|
||||
$this->assertEquals($this->Socket->request['auth'], array('Basic' => array('user' => 'joel', 'pass' => 'hunter2')));
|
||||
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false);
|
||||
|
||||
$this->Socket->configAuth('Basic', 'mark', 'password');
|
||||
$this->Socket->request(array(
|
||||
'method' => 'GET',
|
||||
'uri' => 'http://example.com/test',
|
||||
'header' => array(
|
||||
'Authorization' => 'OtherAuth Hi.There'
|
||||
)
|
||||
));
|
||||
$this->assertPattern('/Authorization: OtherAuth Hi\.There/m', $this->Socket->request['header']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1056,17 +1173,28 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testConsecutiveGetResetsAuthCredentials() {
|
||||
$socket = new MockHttpSocket();
|
||||
$socket->get('http://mark:secret@example.com/test');
|
||||
$this->assertEquals('mark', $socket->request['uri']['user']);
|
||||
$this->assertEquals('secret', $socket->request['uri']['pass']);
|
||||
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')->will($this->returnValue(false));
|
||||
|
||||
$socket->get('/test2');
|
||||
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
$this->Socket->get('http://mark:secret@example.com/test');
|
||||
$this->assertEquals('mark', $this->Socket->request['uri']['user']);
|
||||
$this->assertEquals('secret', $this->Socket->request['uri']['pass']);
|
||||
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
|
||||
$socket->get('/test3');
|
||||
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
$this->Socket->get('/test2');
|
||||
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
|
||||
$this->Socket->request(array(
|
||||
'method' => 'GET',
|
||||
'uri' => 'http://example.com/test',
|
||||
'header' => array(
|
||||
'Authorization' => 'OtherAuth Hi.There'
|
||||
)
|
||||
));
|
||||
$this->assertPattern('/Authorization: OtherAuth Hi\.There/m', $this->Socket->request['header']);
|
||||
|
||||
$this->Socket->get('/test3');
|
||||
$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1117,6 +1245,30 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$this->RequestSocket->put('http://www.google.com/', null, array('line' => 'Hey Server'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testPatch
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPatch() {
|
||||
$this->RequestSocket->reset();
|
||||
$this->RequestSocket->expects($this->at(0))
|
||||
->method('request')
|
||||
->with(array('method' => 'PATCH', 'uri' => 'http://www.google.com/', 'body' => array()));
|
||||
|
||||
$this->RequestSocket->expects($this->at(1))
|
||||
->method('request')
|
||||
->with(array('method' => 'PATCH', 'uri' => 'http://www.google.com/', 'body' => array('Foo' => 'bar')));
|
||||
|
||||
$this->RequestSocket->expects($this->at(2))
|
||||
->method('request')
|
||||
->with(array('method' => 'PATCH', 'uri' => 'http://www.google.com/', 'body' => null, 'line' => 'Hey Server'));
|
||||
|
||||
$this->RequestSocket->patch('http://www.google.com/');
|
||||
$this->RequestSocket->patch('http://www.google.com/', array('Foo' => 'bar'));
|
||||
$this->RequestSocket->patch('http://www.google.com/', null, array('line' => 'Hey Server'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testDelete
|
||||
*
|
||||
|
@ -1177,9 +1329,6 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$r = $this->Socket->buildRequestLine($request);
|
||||
$this->assertEquals("GET /search?q=socket HTTP/1.1\r\n", $r);
|
||||
|
||||
$r = $this->Socket->buildRequestLine($request, 'CAKE-HTTP/0.1');
|
||||
$this->assertEquals("GET /search?q=socket CAKE-HTTP/0.1\r\n", $r);
|
||||
|
||||
$request = array('method' => 'OPTIONS', 'uri' => '*');
|
||||
$r = $this->Socket->buildRequestLine($request);
|
||||
$this->assertEquals("OPTIONS * HTTP/1.1\r\n", $r);
|
||||
|
@ -1191,6 +1340,17 @@ class HttpSocketTest extends CakeTestCase {
|
|||
|
||||
$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
|
||||
$this->assertEquals("GET * HTTP/1.1\r\n", $r);
|
||||
|
||||
$request = array(
|
||||
'version' => '1.0',
|
||||
'method' => 'GET',
|
||||
'uri' => array(
|
||||
'path' => '/search',
|
||||
'query' => array('q' => 'socket')
|
||||
)
|
||||
);
|
||||
$r = $this->Socket->buildRequestLine($request);
|
||||
$this->assertEquals("GET /search?q=socket HTTP/1.0\r\n", $r);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1200,7 +1360,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testBadBuildRequestLine() {
|
||||
$r = $this->Socket->buildRequestLine('Foo');
|
||||
$this->Socket->buildRequestLine('Foo');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1210,7 +1370,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testBadBuildRequestLine2() {
|
||||
$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
|
||||
$this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1489,8 +1649,8 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'name' => 'jim',
|
||||
'items' => array(
|
||||
'personal' => array(
|
||||
'book'
|
||||
, 'pen'
|
||||
'book',
|
||||
'pen'
|
||||
),
|
||||
'ball'
|
||||
)
|
||||
|
@ -1560,9 +1720,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
'people' => array(
|
||||
'value' => 'jim,jack,johnny;',
|
||||
'path' => '/accounts'
|
||||
)
|
||||
),
|
||||
'key' => 'value'
|
||||
);
|
||||
$expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"\r\n";
|
||||
$expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"; key=value\r\n";
|
||||
$result = $this->Socket->buildCookies($cookies);
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
|
@ -1576,10 +1737,10 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$this->Socket->reset();
|
||||
|
||||
$expected = array(
|
||||
'\x22','\x28','\x29','\x3c','\x3e','\x40','\x2c','\x3b','\x3a','\x5c','\x2f','\x5b','\x5d','\x3f','\x3d','\x7b',
|
||||
'\x7d','\x20','\x00','\x01','\x02','\x03','\x04','\x05','\x06','\x07','\x08','\x09','\x0a','\x0b','\x0c','\x0d',
|
||||
'\x0e','\x0f','\x10','\x11','\x12','\x13','\x14','\x15','\x16','\x17','\x18','\x19','\x1a','\x1b','\x1c','\x1d',
|
||||
'\x1e','\x1f','\x7f'
|
||||
'\x22', '\x28', '\x29', '\x3c', '\x3e', '\x40', '\x2c', '\x3b', '\x3a', '\x5c', '\x2f', '\x5b', '\x5d', '\x3f', '\x3d', '\x7b',
|
||||
'\x7d', '\x20', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d',
|
||||
'\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d',
|
||||
'\x1e', '\x1f', '\x7f'
|
||||
);
|
||||
$r = $this->Socket->tokenEscapeChars();
|
||||
$this->assertEquals($expected, $r);
|
||||
|
@ -1618,7 +1779,7 @@ 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 CakeObject::__construct
|
||||
* got executed)
|
||||
*
|
||||
* @return void
|
||||
|
@ -1642,7 +1803,7 @@ class HttpSocketTest extends CakeTestCase {
|
|||
|
||||
/**
|
||||
* This tests asserts HttpSocket::reset(false) resets certain HttpSocket properties to their initial state (before
|
||||
* Object::__construct got executed).
|
||||
* CakeObject::__construct got executed).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -1667,4 +1828,63 @@ class HttpSocketTest extends CakeTestCase {
|
|||
}
|
||||
$this->assertEquals(true, $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that requests fail when peer verification fails.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testVerifyPeer() {
|
||||
$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.');
|
||||
$socket = new HttpSocket();
|
||||
try {
|
||||
$socket->get('https://tv.eurosport.com/');
|
||||
$this->markTestSkipped('Found valid certificate, was expecting invalid certificate.');
|
||||
} catch (SocketException $e) {
|
||||
$message = $e->getMessage();
|
||||
$this->skipIf(strpos($message, 'Invalid HTTP') !== false, 'Invalid HTTP Response received, skipping.');
|
||||
$this->assertContains('Failed to enable crypto', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for status codes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function statusProvider() {
|
||||
return array(
|
||||
array('HTTP/1.1 200 ', '200'),
|
||||
array('HTTP/1.1 200 ', '200'),
|
||||
array('HTTP/1.1 200', '200'),
|
||||
array('HTTP/1.1 200 OK', '200', 'OK'),
|
||||
array('HTTP/1.1 404 Not Found', '404', 'Not Found'),
|
||||
array('HTTP/1.1 404 Not Found', '404', 'Not Found'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test response status parsing
|
||||
*
|
||||
* @dataProvider statusProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testResponseStatusParsing($status, $code, $msg = '') {
|
||||
$this->Socket->connected = true;
|
||||
$serverResponse = $status . "\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n\r\n<h1>This is a test!</h1>";
|
||||
|
||||
$this->Socket->expects($this->any())
|
||||
->method('read')
|
||||
->will($this->onConsecutiveCalls($serverResponse, false));
|
||||
|
||||
$response = $this->Socket->request('http://www.cakephp.org/');
|
||||
$this->assertInstanceOf('HttpSocketResponse', $response);
|
||||
$expected = array(
|
||||
'http-version' => 'HTTP/1.1',
|
||||
'code' => $code,
|
||||
'reason-phrase' => $msg
|
||||
);
|
||||
$this->assertEquals($expected, $response['status']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue