Skip to content
This repository
Browse code

Cleaning up HttpSocket public/protected api; all protected methods ar…

…e now prefixed with an underscore. Refactored associated tests.
  • Loading branch information...
commit 2e2aa0cd3a2e9d178b7a7f09d176a6e78315ed0a 1 parent 70e0316
Joel Perras authored May 07, 2009
135  cake/libs/http_socket.php
@@ -40,7 +40,8 @@ class HttpSocket extends CakeSocket {
40 40
  */
41 41
 	var $description = 'HTTP-based DataSource Interface';
42 42
 /**
43  
- * When one activates the $quirksMode by setting it to true, all checks meant to enforce RFC 2616 (HTTP/1.1 specs)
  43
+ * When one activates the $quirksMode by setting it to true, all checks meant to
  44
+ * enforce RFC 2616 (HTTP/1.1 specs).
44 45
  * will be disabled and additional measures to deal with non-standard responses will be enabled.
45 46
  *
46 47
  * @var boolean
@@ -143,10 +144,10 @@ class HttpSocket extends CakeSocket {
143 144
  */
144 145
 	function __construct($config = array()) {
145 146
 		if (is_string($config)) {
146  
-			$this->configUri($config);
  147
+			$this->_configUri($config);
147 148
 		} elseif (is_array($config)) {
148 149
 			if (isset($config['request']['uri']) && is_string($config['request']['uri'])) {
149  
-				$this->configUri($config['request']['uri']);
  150
+				$this->_configUri($config['request']['uri']);
150 151
 				unset($config['request']['uri']);
151 152
 			}
152 153
 			$this->config = Set::merge($this->config, $config);
@@ -172,7 +173,7 @@ function request($request = array()) {
172 173
 		if (!isset($request['uri'])) {
173 174
 			$request['uri'] = null;
174 175
 		}
175  
-		$uri = $this->parseUri($request['uri']);
  176
+		$uri = $this->_parseUri($request['uri']);
176 177
 
177 178
 		if (!isset($uri['host'])) {
178 179
 			$host = $this->config['host'];
@@ -183,10 +184,10 @@ function request($request = array()) {
183 184
 		}
184 185
 
185 186
 		$request['uri'] = $this->url($request['uri']);
186  
-		$request['uri'] = $this->parseUri($request['uri'], true);
  187
+		$request['uri'] = $this->_parseUri($request['uri'], true);
187 188
 		$this->request = Set::merge($this->request, $this->config['request'], $request);
188 189
 
189  
-		$this->configUri($this->request['uri']);
  190
+		$this->_configUri($this->request['uri']);
190 191
 
191 192
 		if (isset($host)) {
192 193
 			$this->config['host'] = $host;
@@ -194,7 +195,7 @@ function request($request = array()) {
194 195
 		$cookies = null;
195 196
 
196 197
 		if (is_array($this->request['header'])) {
197  
-			$this->request['header'] = $this->parseHeader($this->request['header']);
  198
+			$this->request['header'] = $this->_parseHeader($this->request['header']);
198 199
 			if (!empty($this->request['cookies'])) {
199 200
 				$cookies = $this->buildCookies($this->request['cookies']);
200 201
 			}
@@ -209,7 +210,7 @@ function request($request = array()) {
209 210
 		}
210 211
 
211 212
 		if (is_array($this->request['body'])) {
212  
-			$this->request['body'] = $this->httpSerialize($this->request['body']);
  213
+			$this->request['body'] = $this->_httpSerialize($this->request['body']);
213 214
 		}
214 215
 
215 216
 		if (!empty($this->request['body']) && !isset($this->request['header']['Content-Type'])) {
@@ -221,10 +222,10 @@ function request($request = array()) {
221 222
 		}
222 223
 
223 224
 		$connectionType = @$this->request['header']['Connection'];
224  
-		$this->request['header'] = $this->buildHeader($this->request['header']).$cookies;
  225
+		$this->request['header'] = $this->_buildHeader($this->request['header']).$cookies;
225 226
 
226 227
 		if (empty($this->request['line'])) {
227  
-			$this->request['line'] = $this->buildRequestLine($this->request);
  228
+			$this->request['line'] = $this->_buildRequestLine($this->request);
228 229
 		}
229 230
 
230 231
 		if ($this->quirksMode === false && $this->request['line'] === false) {
@@ -252,7 +253,7 @@ function request($request = array()) {
252 253
 			$this->disconnect();
253 254
 		}
254 255
 
255  
-		$this->response = $this->parseResponse($response);
  256
+		$this->response = $this->_parseResponse($response);
256 257
 		if (!empty($this->response['cookies'])) {
257 258
 			$this->config['request']['cookies'] = array_merge($this->config['request']['cookies'], $this->response['cookies']);
258 259
 		}
@@ -262,7 +263,7 @@ function request($request = array()) {
262 263
 /**
263 264
  * Issues a GET request to the specified URI, query, and request.
264 265
  *
265  
- * @param mixed $uri URI to request (see {@link parseUri()})
  266
+ * @param mixed $uri URI to request (see {@link _parseUri()})
266 267
  * @param array $query Query to append to URI
267 268
  * @param array $request An indexed array with indexes such as 'method' or uri
268 269
  * @return mixed Result of request
@@ -270,13 +271,13 @@ function request($request = array()) {
270 271
  */
271 272
 	function get($uri = null, $query = array(), $request = array()) {
272 273
 		if (!empty($query)) {
273  
-			$uri =$this->parseUri($uri);
  274
+			$uri =$this->_parseUri($uri);
274 275
 			if (isset($uri['query'])) {
275 276
 				$uri['query'] = array_merge($uri['query'], $query);
276 277
 			} else {
277 278
 				$uri['query'] = $query;
278 279
 			}
279  
-			$uri = $this->buildUri($uri);
  280
+			$uri = $this->_buildUri($uri);
280 281
 		}
281 282
 
282 283
 		$request = Set::merge(array('method' => 'GET', 'uri' => $uri), $request);
@@ -286,7 +287,7 @@ function get($uri = null, $query = array(), $request = array()) {
286 287
 /**
287 288
  * Issues a POST request to the specified URI, query, and request.
288 289
  *
289  
- * @param mixed $uri URI to request (see {@link parseUri()})
  290
+ * @param mixed $uri URI to request (see {@link _parseUri()})
290 291
  * @param array $query Query to append to URI
291 292
  * @param array $request An indexed array with indexes such as 'method' or uri
292 293
  * @return mixed Result of request
@@ -299,7 +300,7 @@ function post($uri = null, $data = array(), $request = array()) {
299 300
 /**
300 301
  * Issues a PUT request to the specified URI, query, and request.
301 302
  *
302  
- * @param mixed $uri URI to request (see {@link parseUri()})
  303
+ * @param mixed $uri URI to request (see {@link _parseUri()})
303 304
  * @param array $query Query to append to URI
304 305
  * @param array $request An indexed array with indexes such as 'method' or uri
305 306
  * @return mixed Result of request
@@ -312,7 +313,7 @@ function put($uri = null, $data = array(), $request = array()) {
312 313
 /**
313 314
  * Issues a DELETE request to the specified URI, query, and request.
314 315
  *
315  
- * @param mixed $uri URI to request (see {@link parseUri()})
  316
+ * @param mixed $uri URI to request (see {@link _parseUri()})
316 317
  * @param array $query Query to append to URI
317 318
  * @param array $request An indexed array with indexes such as 'method' or uri
318 319
  * @return mixed Result of request
@@ -346,16 +347,16 @@ function url($url = null, $uriTemplate = null) {
346 347
 		}
347 348
 
348 349
 		$base = array_merge($this->config['request']['uri'], array('scheme' => array('http', 'https'), 'port' => array(80, 443)));
349  
-		$url = $this->parseUri($url, $base);
  350
+		$url = $this->_parseUri($url, $base);
350 351
 
351 352
 		if (empty($url)) {
352 353
 			$url = $this->config['request']['uri'];
353 354
 		}
354 355
 
355 356
 		if (!empty($uriTemplate)) {
356  
-			return $this->buildUri($url, $uriTemplate);
  357
+			return $this->_buildUri($url, $uriTemplate);
357 358
 		}
358  
-		return $this->buildUri($url);
  359
+		return $this->_buildUri($url);
359 360
 	}
360 361
 /**
361 362
  * Parses the given message and breaks it down in parts.
@@ -364,7 +365,7 @@ function url($url = null, $uriTemplate = null) {
364 365
  * @return array Parsed message (with indexed elements such as raw, status, header, body)
365 366
  * @access protected
366 367
  */
367  
-	function parseResponse($message) {
  368
+	function _parseResponse($message) {
368 369
 		if (is_array($message)) {
369 370
 			return $message;
370 371
 		} elseif (!is_string($message)) {
@@ -394,12 +395,12 @@ function parseResponse($message) {
394 395
 			$response['status']['reason-phrase'] = $match[3];
395 396
 		}
396 397
 
397  
-		$response['header'] = $this->parseHeader($response['raw']['header']);
398  
-		$decoded = $this->decodeBody($response['raw']['body'], @$response['header']['Transfer-Encoding']);
  398
+		$response['header'] = $this->_parseHeader($response['raw']['header']);
  399
+		$decoded = $this->_decodeBody($response['raw']['body'], @$response['header']['Transfer-Encoding']);
399 400
 		$response['body'] = $decoded['body'];
400 401
 
401 402
 		if (!empty($decoded['header'])) {
402  
-			$response['header'] = $this->parseHeader($this->buildHeader($response['header']).$this->buildHeader($decoded['header']));
  403
+			$response['header'] = $this->_parseHeader($this->_buildHeader($response['header']).$this->_buildHeader($decoded['header']));
403 404
 		}
404 405
 
405 406
 		if (!empty($response['header'])) {
@@ -423,7 +424,7 @@ function parseResponse($message) {
423 424
  * @return mixed Array or false
424 425
  * @access protected
425 426
  */
426  
-	function decodeBody($body, $encoding = 'chunked') {
  427
+	function _decodeBody($body, $encoding = 'chunked') {
427 428
 		if (!is_string($body)) {
428 429
 			return false;
429 430
 		}
@@ -434,7 +435,7 @@ function decodeBody($body, $encoding = 'chunked') {
434 435
 
435 436
 		if (!is_callable(array(&$this, $decodeMethod))) {
436 437
 			if (!$this->quirksMode) {
437  
-				trigger_error(sprintf(__('HttpSocket::decodeBody - Unknown encoding: %s. Activate quirks mode to surpress error.', true), h($encoding)), E_USER_WARNING);
  438
+				trigger_error(sprintf(__('HttpSocket::_decodeBody - Unknown encoding: %s. Activate quirks mode to surpress error.', true), h($encoding)), E_USER_WARNING);
438 439
 			}
439 440
 			return array('body' => $body, 'header' => false);
440 441
 		}
@@ -448,7 +449,7 @@ function decodeBody($body, $encoding = 'chunked') {
448 449
  * @return mixed Array or false
449 450
  * @access protected
450 451
  */
451  
-	function decodeChunkedBody($body) {
  452
+	function _decodeChunkedBody($body) {
452 453
 		if (!is_string($body)) {
453 454
 			return false;
454 455
 		}
@@ -459,7 +460,7 @@ function decodeChunkedBody($body) {
459 460
 		while ($chunkLength !== 0) {
460 461
 			if (!preg_match("/^([0-9a-f]+) *(?:;(.+)=(.+))?\r\n/iU", $body, $match)) {
461 462
 				if (!$this->quirksMode) {
462  
-					trigger_error(__('HttpSocket::decodeChunkedBody - Could not parse malformed chunk. Activate quirks mode to do this.', true), E_USER_WARNING);
  463
+					trigger_error(__('HttpSocket::_decodeChunkedBody - Could not parse malformed chunk. Activate quirks mode to do this.', true), E_USER_WARNING);
463 464
 					return false;
464 465
 				}
465 466
 				break;
@@ -498,26 +499,26 @@ function decodeChunkedBody($body) {
498 499
 
499 500
 		$entityHeader = false;
500 501
 		if (!empty($body)) {
501  
-			$entityHeader = $this->parseHeader($body);
  502
+			$entityHeader = $this->_parseHeader($body);
502 503
 		}
503 504
 		return array('body' => $decodedBody, 'header' => $entityHeader);
504 505
 	}
505 506
 /**
506 507
  * Parses and sets the specified URI into current request configuration.
507 508
  *
508  
- * @param mixed $uri URI (see {@link parseUri()})
  509
+ * @param mixed $uri URI (see {@link _parseUri()})
509 510
  * @return array Current configuration settings
510 511
  * @access protected
511 512
  */
512  
-	function configUri($uri = null) {
  513
+	function _configUri($uri = null) {
513 514
 		if (empty($uri)) {
514 515
 			return false;
515 516
 		}
516 517
 
517 518
 		if (is_array($uri)) {
518  
-			$uri = $this->parseUri($uri);
  519
+			$uri = $this->_parseUri($uri);
519 520
 		} else {
520  
-			$uri = $this->parseUri($uri, true);
  521
+			$uri = $this->_parseUri($uri, true);
521 522
 		}
522 523
 
523 524
 		if (!isset($uri['host'])) {
@@ -542,18 +543,18 @@ function configUri($uri = null) {
542 543
  * @return string A fully qualified URL formated according to $uriTemplate
543 544
  * @access protected
544 545
  */
545  
-	function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') {
  546
+	function _buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') {
546 547
 		if (is_string($uri)) {
547 548
 			$uri = array('host' => $uri);
548 549
 		}
549  
-		$uri = $this->parseUri($uri, true);
  550
+		$uri = $this->_parseUri($uri, true);
550 551
 
551 552
 		if (!is_array($uri) || empty($uri)) {
552 553
 			return false;
553 554
 		}
554 555
 
555 556
 		$uri['path'] = preg_replace('/^\//', null, $uri['path']);
556  
-		$uri['query'] = $this->httpSerialize($uri['query']);
  557
+		$uri['query'] = $this->_httpSerialize($uri['query']);
557 558
 		$stripIfEmpty = array(
558 559
 			'query' => '?%query',
559 560
 			'fragment' => '#%fragment',
@@ -589,7 +590,7 @@ function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%p
589 590
  * @return array Parsed URI
590 591
  * @access protected
591 592
  */
592  
-	function parseUri($uri = null, $base = array()) {
  593
+	function _parseUri($uri = null, $base = array()) {
593 594
 		$uriBase = array(
594 595
 			'scheme' => array('http', 'https'),
595 596
 			'host' => null,
@@ -631,7 +632,7 @@ function parseUri($uri = null, $base = array()) {
631 632
 		}
632 633
 
633 634
 		if (array_key_exists('query', $uri)) {
634  
-			$uri['query'] = $this->parseQuery($uri['query']);
  635
+			$uri['query'] = $this->_parseQuery($uri['query']);
635 636
 		}
636 637
 
637 638
 		if (!array_intersect_key($uriBase, $uri)) {
@@ -647,13 +648,13 @@ function parseUri($uri = null, $base = array()) {
647 648
  * - ?key[]=value1&key[]=value2
648 649
  *
649 650
  * A leading '?' mark in $query is optional and does not effect the outcome of this function. For the complete capabilities of this implementation
650  
- * take a look at HttpSocketTest::testParseQuery()
  651
+ * take a look at HttpSocketTest::testparseQuery()
651 652
  *
652 653
  * @param mixed $query A query string to parse into an array or an array to return directly "as is"
653 654
  * @return array The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned.
654 655
  * @access protected
655 656
  */
656  
-	function parseQuery($query) {
  657
+	function _parseQuery($query) {
657 658
 		if (is_array($query)) {
658 659
 			return $query;
659 660
 		}
@@ -710,13 +711,13 @@ function parseQuery($query) {
710 711
  * @return string Request line
711 712
  * @access protected
712 713
  */
713  
-	function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
  714
+	function _buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
714 715
 		$asteriskMethods = array('OPTIONS');
715 716
 
716 717
 		if (is_string($request)) {
717 718
 			$isValid = preg_match("/(.+) (.+) (.+)\r\n/U", $request, $match);
718 719
 			if (!$this->quirksMode && (!$isValid || ($match[2] == '*' && !in_array($match[3], $asteriskMethods)))) {
719  
-				trigger_error(__('HttpSocket::buildRequestLine - Passed an invalid request line string. Activate quirks mode to do this.', true), E_USER_WARNING);
  720
+				trigger_error(__('HttpSocket::_buildRequestLine - Passed an invalid request line string. Activate quirks mode to do this.', true), E_USER_WARNING);
720 721
 				return false;
721 722
 			}
722 723
 			return $request;
@@ -726,12 +727,12 @@ function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
726 727
 			return false;
727 728
 		}
728 729
 
729  
-		$request['uri']	= $this->parseUri($request['uri']);
  730
+		$request['uri']	= $this->_parseUri($request['uri']);
730 731
 		$request = array_merge(array('method' => 'GET'), $request);
731  
-		$request['uri'] = $this->buildUri($request['uri'], '/%path?%query');
  732
+		$request['uri'] = $this->_buildUri($request['uri'], '/%path?%query');
732 733
 
733 734
 		if (!$this->quirksMode && $request['uri'] === '*' && !in_array($request['method'], $asteriskMethods)) {
734  
-			trigger_error(sprintf(__('HttpSocket::buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.', true), join(',', $asteriskMethods)), E_USER_WARNING);
  735
+			trigger_error(sprintf(__('HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.', true), join(',', $asteriskMethods)), E_USER_WARNING);
735 736
 			return false;
736 737
 		}
737 738
 		return $request['method'].' '.$request['uri'].' '.$versionToken.$this->lineBreak;
@@ -743,7 +744,7 @@ function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
743 744
  * @return string Serialized variable
744 745
  * @access protected
745 746
  */
746  
-	function httpSerialize($data = array()) {
  747
+	function _httpSerialize($data = array()) {
747 748
 		if (is_string($data)) {
748 749
 			return $data;
749 750
 		}
@@ -759,7 +760,7 @@ function httpSerialize($data = array()) {
759 760
  * @return string Header built from array
760 761
  * @access protected
761 762
  */
762  
-	function buildHeader($header, $mode = 'standard') {
  763
+	function _buildHeader($header, $mode = 'standard') {
763 764
 		if (is_string($header)) {
764 765
 			return $header;
765 766
 		} elseif (!is_array($header)) {
@@ -773,7 +774,7 @@ function buildHeader($header, $mode = 'standard') {
773 774
 			}
774 775
 			foreach ((array)$contents as $content) {
775 776
 				$contents = preg_replace("/\r\n(?![\t ])/", "\r\n ", $content);
776  
-				$field = $this->escapeToken($field);
  777
+				$field = $this->_escapeToken($field);
777 778
 
778 779
 				$returnHeader .= $field.': '.$contents.$this->lineBreak;
779 780
 			}
@@ -788,7 +789,7 @@ function buildHeader($header, $mode = 'standard') {
788 789
  * @return array Parsed header
789 790
  * @access protected
790 791
  */
791  
-	function parseHeader($header) {
  792
+	function _parseHeader($header) {
792 793
 		if (is_array($header)) {
793 794
 			foreach ($header as $field => $value) {
794 795
 				unset($header[$field]);
@@ -814,7 +815,7 @@ function parseHeader($header) {
814 815
 			$value = trim($value);
815 816
 			$value = preg_replace("/[\t ]\r\n/", "\r\n", $value);
816 817
 
817  
-			$field = $this->unescapeToken($field);
  818
+			$field = $this->_unescapeToken($field);
818 819
 
819 820
 			$field = strtolower($field);
820 821
 			preg_match_all('/(?:^|(?<=-))[a-z]/U', $field, $offsets, PREG_OFFSET_CAPTURE);
@@ -875,30 +876,12 @@ function parseCookies($header) {
875 876
 	function buildCookies($cookies) {
876 877
 		$header = array();
877 878
 		foreach ($cookies as $name => $cookie) {
878  
-			$header[] = $name.'='.$this->escapeToken($cookie['value'], array(';'));
  879
+			$header[] = $name.'='.$this->_escapeToken($cookie['value'], array(';'));
879 880
 		}
880  
-		$header = $this->buildHeader(array('Cookie' => $header), 'pragmatic');
  881
+		$header = $this->_buildHeader(array('Cookie' => $header), 'pragmatic');
881 882
 		return $header;
882 883
 	}
883 884
 /**
884  
- * undocumented function
885  
- *
886  
- * @return void
887  
- * @access public
888  
- */
889  
-	function saveCookies() {
890  
-
891  
-	}
892  
-/**
893  
- * undocumented function
894  
- *
895  
- * @return void
896  
- * @access public
897  
- */
898  
-	function loadCookies() {
899  
-
900  
-	}
901  
-/**
902 885
  * Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs)
903 886
  *
904 887
  * @param string $token Token to unescape
@@ -906,8 +889,8 @@ function loadCookies() {
906 889
  * @access protected
907 890
  * @todo Test $chars parameter
908 891
  */
909  
-	function unescapeToken($token, $chars = null) {
910  
-		$regex = '/"(['.join('', $this->__tokenEscapeChars(true, $chars)).'])"/';
  892
+	function _unescapeToken($token, $chars = null) {
  893
+		$regex = '/"(['.join('', $this->_tokenEscapeChars(true, $chars)).'])"/';
911 894
 		$token = preg_replace($regex, '\\1', $token);
912 895
 		return $token;
913 896
 	}
@@ -919,8 +902,8 @@ function unescapeToken($token, $chars = null) {
919 902
  * @access protected
920 903
  * @todo Test $chars parameter
921 904
  */
922  
-	function escapeToken($token, $chars = null) {
923  
-		$regex = '/(['.join('', $this->__tokenEscapeChars(true, $chars)).'])/';
  905
+	function _escapeToken($token, $chars = null) {
  906
+		$regex = '/(['.join('', $this->_tokenEscapeChars(true, $chars)).'])/';
924 907
 		$token = preg_replace($regex, '"\\1"', $token);
925 908
 		return $token;
926 909
 	}
@@ -929,10 +912,10 @@ function escapeToken($token, $chars = null) {
929 912
  *
930 913
  * @param boolean $hex true to get them as HEX values, false otherwise
931 914
  * @return array Escape chars
932  
- * @access private
  915
+ * @access protected
933 916
  * @todo Test $chars parameter
934 917
  */
935  
-	function __tokenEscapeChars($hex = true, $chars = null) {
  918
+	function _tokenEscapeChars($hex = true, $chars = null) {
936 919
 		if (!empty($chars)) {
937 920
 			$escape = $chars;
938 921
 		} else {
152  cake/tests/cases/libs/http_socket.test.php
@@ -25,6 +25,132 @@
25 25
  * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
26 26
  */
27 27
 App::import('Core', 'HttpSocket');
  28
+
  29
+class TestHttpSocket extends HttpSocket {
  30
+/**
  31
+ * Convenience method for testing protected method
  32
+ *
  33
+ * @param mixed $uri URI (see {@link _parseUri()})
  34
+ * @return array Current configuration settings
  35
+ */
  36
+	function configUri($uri = null) {
  37
+		return parent::_configUri($uri);
  38
+	}
  39
+/**
  40
+ * Convenience method for testing protected method
  41
+ *
  42
+ * @param string $uri URI to parse
  43
+ * @param mixed $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
  44
+ * @return array Parsed URI
  45
+ */
  46
+	function parseUri($uri = null, $base = array()) {
  47
+		return parent::_parseUri($uri, $base);
  48
+	}
  49
+/**
  50
+ * Convenience method for testing protected method
  51
+ *
  52
+ * @param array $uri A $uri array, or uses $this->config if left empty
  53
+ * @param string $uriTemplate The Uri template/format to use
  54
+ * @return string A fully qualified URL formated according to $uriTemplate
  55
+ */
  56
+	function buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') {
  57
+		return parent::_buildUri($uri, $uriTemplate);
  58
+	}
  59
+/**
  60
+ * Convenience method for testing protected method
  61
+ *
  62
+ * @param array $header Header to build
  63
+ * @return string Header built from array
  64
+ */
  65
+	function buildHeader($header, $mode = 'standard') {
  66
+		return parent::_buildHeader($header, $mode);
  67
+	}
  68
+
  69
+/**
  70
+ * Convenience method for testing protected method
  71
+ *
  72
+ * @param string $message Message to parse
  73
+ * @return array Parsed message (with indexed elements such as raw, status, header, body)
  74
+ */
  75
+	function parseResponse($message) {
  76
+		return parent::_parseResponse($message);
  77
+	}
  78
+/**
  79
+ * Convenience method for testing protected method
  80
+ *
  81
+ * @param array $header Header as an indexed array (field => value)
  82
+ * @return array Parsed header
  83
+ */
  84
+	function parseHeader($header) {
  85
+		return parent::_parseHeader($header);
  86
+	}
  87
+/**
  88
+ * Convenience method for testing protected method
  89
+ *
  90
+ * @param mixed $query A query string to parse into an array or an array to return directly "as is"
  91
+ * @return array The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned.
  92
+ */
  93
+	function parseQuery($query) {
  94
+		return parent::_parseQuery($query);
  95
+	}
  96
+/**
  97
+ * Convenience method for testing protected method
  98
+ *
  99
+ * @param string $body A string continaing the body to decode
  100
+ * @param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding
  101
+ * @return mixed Array or false
  102
+ */
  103
+	function decodeBody($body, $encoding = 'chunked') {
  104
+		return parent::_decodeBody($body, $encoding);
  105
+	}
  106
+/**
  107
+ * Convenience method for testing protected method
  108
+ *
  109
+ * @param string $body A string continaing the chunked body to decode
  110
+ * @return mixed Array or false
  111
+ */
  112
+	function decodeChunkedBody($body) {
  113
+		return parent::_decodeChunkedBody($body);
  114
+	}
  115
+/**
  116
+ * Convenience method for testing protected method
  117
+ *
  118
+ * @param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
  119
+ * @param string $versionToken The version token to use, defaults to HTTP/1.1
  120
+ * @return string Request line
  121
+ */
  122
+	function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
  123
+		return parent::_buildRequestLine($request, $versionToken);
  124
+	}
  125
+/**
  126
+ * Convenience method for testing protected method
  127
+ *
  128
+ * @param boolean $hex true to get them as HEX values, false otherwise
  129
+ * @return array Escape chars
  130
+ */
  131
+	function tokenEscapeChars($hex = true, $chars = null) {
  132
+		return parent::_tokenEscapeChars($hex, $chars);
  133
+	}
  134
+/**
  135
+ * Convenience method for testing protected method
  136
+ *
  137
+ * @param string $token Token to escape
  138
+ * @return string Escaped token
  139
+ */
  140
+	function EscapeToken($token, $chars = null) {
  141
+		return parent::_escapeToken($token, $chars);
  142
+	}
  143
+/**
  144
+ * Convenience method for testing protected method
  145
+ *
  146
+ * @param string $token Token to unescape
  147
+ * @return string Unescaped token
  148
+ */
  149
+	function unescapeToken($token, $chars = null) {
  150
+		return parent::_unescapeToken($token, $chars);
  151
+	}
  152
+}
  153
+
28 154
 /**
29 155
  * Short description for class.
30 156
  *
@@ -51,13 +177,13 @@ class HttpSocketTest extends CakeTestCase {
51 177
  *
52 178
  */
53 179
 	function setUp() {
54  
-		if (!class_exists('TestHttpSocket')) {
55  
-			Mock::generatePartial('HttpSocket', 'TestHttpSocket', array('read', 'write', 'connect'));
56  
-			Mock::generatePartial('HttpSocket', 'TestHttpSocketRequests', array('read', 'write', 'connect', 'request'));
  180
+		if (!class_exists('MockHttpSocket')) {
  181
+			Mock::generatePartial('TestHttpSocket', 'MockHttpSocket', array('read', 'write', 'connect'));
  182
+			Mock::generatePartial('TestHttpSocket', 'MockHttpSocketRequests', array('read', 'write', 'connect', 'request'));
57 183
 		}
58 184
 
59  
-		$this->Socket =& new TestHttpSocket();
60  
-		$this->RequestSocket =& new TestHttpSocketRequests();
  185
+		$this->Socket =& new MockHttpSocket();
  186
+		$this->RequestSocket =& new MockHttpSocketRequests();
61 187
 	}
62 188
 /**
63 189
  * We use this function to clean up after the test case was executed
@@ -365,12 +491,6 @@ function testRequest() {
365 491
 
366 492
 			$r = array('config' => $this->Socket->config, 'request' => $this->Socket->request);
367 493
 			$v = $this->assertIdentical($r, $expectation, '%s in test #'.$i.' ');
368  
-			if (!$v) {
369  
-				debug('Result:');
370  
-				debug($r);
371  
-				debug('Expected:');
372  
-				debug($expectation);
373  
-			}
374 494
 			$expectation['request']['raw'] = $raw;
375 495
 		}
376 496
 
@@ -1189,7 +1309,7 @@ function testBuildCookies() {
1189 1309
 		$this->assertEqual($result, $expect);
1190 1310
 	}
1191 1311
 /**
1192  
- * Tests that HttpSocket::__tokenEscapeChars() returns the right characters.
  1312
+ * Tests that HttpSocket::_tokenEscapeChars() returns the right characters.
1193 1313
  *
1194 1314
  */
1195 1315
 	function testTokenEscapeChars() {
@@ -1201,14 +1321,14 @@ function testTokenEscapeChars() {
1201 1321
 			'\x0e','\x0f','\x10','\x11','\x12','\x13','\x14','\x15','\x16','\x17','\x18','\x19','\x1a','\x1b','\x1c','\x1d',
1202 1322
 			'\x1e','\x1f','\x7f'
1203 1323
 		);
1204  
-		$r = $this->Socket->__tokenEscapeChars();
  1324
+		$r = $this->Socket->tokenEscapeChars();
1205 1325
 		$this->assertEqual($r, $expected);
1206 1326
 
1207 1327
 		foreach ($expected as $key => $char) {
1208 1328
 			$expected[$key] = chr(hexdec(substr($char, 2)));
1209 1329
 		}
1210 1330
 
1211  
-		$r = $this->Socket->__tokenEscapeChars(false);
  1331
+		$r = $this->Socket->tokenEscapeChars(false);
1212 1332
 		$this->assertEqual($r, $expected);
1213 1333
 	}
1214 1334
 
@@ -1221,7 +1341,7 @@ function testEscapeToken() {
1221 1341
 
1222 1342
 		$this->assertIdentical($this->Socket->escapeToken('Foo'), 'Foo');
1223 1343
 
1224  
-		$escape = $this->Socket->__tokenEscapeChars(false);
  1344
+		$escape = $this->Socket->tokenEscapeChars(false);
1225 1345
 		foreach ($escape as $char) {
1226 1346
 			$token = 'My-special-'.$char.'-Token';
1227 1347
 			$escapedToken = $this->Socket->escapeToken($token);
@@ -1245,7 +1365,7 @@ function testUnescapeToken() {
1245 1365
 
1246 1366
 		$this->assertIdentical($this->Socket->unescapeToken('Foo'), 'Foo');
1247 1367
 
1248  
-		$escape = $this->Socket->__tokenEscapeChars(false);
  1368
+		$escape = $this->Socket->tokenEscapeChars(false);
1249 1369
 		foreach ($escape as $char) {
1250 1370
 			$token = 'My-special-"'.$char.'"-Token';
1251 1371
 			$unescapedToken = $this->Socket->unescapeToken($token);

0 notes on commit 2e2aa0c

Please sign in to comment.
Something went wrong with that request. Please try again.