UtilityTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Oauth
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Oauth/Http/Utility.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Oauth
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Oauth
  30. * @group Zend_Oauth_Http
  31. */
  32. class Zend_Oauth_Http_UtilityTest extends PHPUnit_Framework_TestCase
  33. {
  34. // see: http://wiki.oauth.net/TestCases (Parameter Encoding Tests)
  35. public function testUrlEncodeCorrectlyEncodesAlnum()
  36. {
  37. $string = 'abcABC123';
  38. $this->assertEquals('abcABC123', Zend_Oauth_Http_Utility::urlEncode($string));
  39. }
  40. public function testUrlEncodeCorrectlyEncodesUnreserved()
  41. {
  42. $string = '-._~';
  43. $this->assertEquals('-._~', Zend_Oauth_Http_Utility::urlEncode($string));
  44. }
  45. public function testUrlEncodeCorrectlyEncodesPercentSign()
  46. {
  47. $string = '%';
  48. $this->assertEquals('%25', Zend_Oauth_Http_Utility::urlEncode($string));
  49. }
  50. public function testUrlEncodeCorrectlyEncodesPlusSign()
  51. {
  52. $string = '+';
  53. $this->assertEquals('%2B', Zend_Oauth_Http_Utility::urlEncode($string));
  54. }
  55. public function testUrlEncodeCorrectlyEncodesAmpEqualsAndAsterix()
  56. {
  57. $string = '&=*';
  58. $this->assertEquals('%26%3D%2A', Zend_Oauth_Http_Utility::urlEncode($string));
  59. }
  60. public function testUrlEncodeCorrectlyEncodesSpace()
  61. {
  62. $string = ' ';
  63. $this->assertEquals('%20', Zend_Oauth_Http_Utility::urlEncode($string));
  64. }
  65. public function testUrlEncodeCorrectlyEncodesLineFeed()
  66. {
  67. $string = "\n";
  68. $this->assertEquals('%0A', Zend_Oauth_Http_Utility::urlEncode($string));
  69. }
  70. public function testUrlEncodeCorrectlyEncodesU007F()
  71. {
  72. $string = chr(127);
  73. $this->assertEquals('%7F', Zend_Oauth_Http_Utility::urlEncode($string));
  74. }
  75. public function testUrlEncodeCorrectlyEncodesU0080()
  76. {
  77. $string = "\xC2\x80";
  78. $this->assertEquals('%C2%80', Zend_Oauth_Http_Utility::urlEncode($string));
  79. }
  80. public function testUrlEncodeCorrectlyEncodesU3001()
  81. {
  82. $string = '、';
  83. $this->assertEquals('%E3%80%81', Zend_Oauth_Http_Utility::urlEncode($string));
  84. }
  85. }