RequestTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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-2012 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/Token/Request.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Oauth
  26. * @subpackage UnitTests
  27. * @copyright Copyright (c) 2005-2012 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_Token
  31. */
  32. class Zend_Oauth_Token_RequestTest extends PHPUnit_Framework_TestCase
  33. {
  34. public function testConstructorSetsResponseObject()
  35. {
  36. $response = new Zend_Http_Response(200, array());
  37. $token = new Zend_Oauth_Token_Request($response);
  38. $this->assertTrue($token->getResponse() instanceof Zend_Http_Response);
  39. }
  40. public function testConstructorParsesRequestTokenFromResponseBody()
  41. {
  42. $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
  43. $response = new Zend_Http_Response(200, array(), $body);
  44. $token = new Zend_Oauth_Token_Request($response);
  45. $this->assertEquals('jZaee4GF52O3lUb9', $token->getToken());
  46. }
  47. public function testConstructorParsesRequestTokenSecretFromResponseBody()
  48. {
  49. $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
  50. $response = new Zend_Http_Response(200, array(), $body);
  51. $token = new Zend_Oauth_Token_Request($response);
  52. $this->assertEquals('J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri', $token->getTokenSecret());
  53. }
  54. public function testPropertyAccessWorks()
  55. {
  56. $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri&foo=bar';
  57. $response = new Zend_Http_Response(200, array(), $body);
  58. $token = new Zend_Oauth_Token_Request($response);
  59. $this->assertEquals('J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri', $token->oauth_token_secret);
  60. }
  61. public function testTokenCastsToEncodedResponseBody()
  62. {
  63. $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
  64. $token = new Zend_Oauth_Token_Request();
  65. $token->setToken('jZaee4GF52O3lUb9');
  66. $token->setTokenSecret('J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri');
  67. $this->assertEquals($body, (string) $token);
  68. }
  69. public function testToStringReturnsEncodedResponseBody()
  70. {
  71. $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
  72. $token = new Zend_Oauth_Token_Request();
  73. $token->setToken('jZaee4GF52O3lUb9');
  74. $token->setTokenSecret('J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri');
  75. $this->assertEquals($body, $token->toString());
  76. }
  77. public function testIsValidDetectsBadResponse()
  78. {
  79. $body = 'oauthtoken=jZaee4GF52O3lUb9&oauthtokensecret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
  80. $response = new Zend_Http_Response(200, array(), $body);
  81. $token = new Zend_Oauth_Token_Request($response);
  82. $this->assertFalse($token->isValid());
  83. }
  84. public function testIsValidDetectsGoodResponse()
  85. {
  86. $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
  87. $response = new Zend_Http_Response(200, array(), $body);
  88. $token = new Zend_Oauth_Token_Request($response);
  89. $this->assertTrue($token->isValid());
  90. }
  91. }