BasicAuthenticationTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * BasicAuthenticationTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  15. * @package Cake.Test.Case.Network.Http
  16. * @since CakePHP(tm) v 2.0.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('HttpSocket', 'Network/Http');
  20. App::uses('BasicAuthentication', 'Network/Http');
  21. /**
  22. * BasicMethodTest class
  23. *
  24. * @package Cake.Test.Case.Network.Http
  25. */
  26. class BasicAuthenticationTest extends CakeTestCase {
  27. /**
  28. * testAuthentication method
  29. *
  30. * @return void
  31. */
  32. public function testAuthentication() {
  33. $http = new HttpSocket();
  34. $auth = array(
  35. 'method' => 'Basic',
  36. 'user' => 'mark',
  37. 'pass' => 'secret'
  38. );
  39. BasicAuthentication::authentication($http, $auth);
  40. $this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->request['header']['Authorization']);
  41. }
  42. /**
  43. * testProxyAuthentication method
  44. *
  45. * @return void
  46. */
  47. public function testProxyAuthentication() {
  48. $http = new HttpSocket();
  49. $proxy = array(
  50. 'method' => 'Basic',
  51. 'user' => 'mark',
  52. 'pass' => 'secret'
  53. );
  54. BasicAuthentication::proxyAuthentication($http, $proxy);
  55. $this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->request['header']['Proxy-Authorization']);
  56. }
  57. }