OauthTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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-2011 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.php';
  23. class Test_Http_Client_19485876 extends Zend_Http_Client {}
  24. /**
  25. * @category Zend
  26. * @package Zend_Oauth
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Oauth
  31. */
  32. class Zend_OauthTest extends PHPUnit_Framework_TestCase
  33. {
  34. public function teardown()
  35. {
  36. Zend_Oauth::clearHttpClient();
  37. }
  38. public function testCanSetCustomHttpClient()
  39. {
  40. Zend_Oauth::setHttpClient(new Test_Http_Client_19485876());
  41. $this->assertType('Test_Http_Client_19485876', Zend_Oauth::getHttpClient());
  42. }
  43. public function testGetHttpClientResetsParameters()
  44. {
  45. $client = new Test_Http_Client_19485876();
  46. $client->setParameterGet(array('key'=>'value'));
  47. Zend_Oauth::setHttpClient($client);
  48. $resetClient = Zend_Oauth::getHttpClient();
  49. $resetClient->setUri('http://www.example.com');
  50. $this->assertEquals('http://www.example.com:80', $resetClient->getUri(true));
  51. }
  52. public function testGetHttpClientResetsAuthorizationHeader()
  53. {
  54. $client = new Test_Http_Client_19485876();
  55. $client->setHeaders('Authorization', 'realm="http://www.example.com",oauth_version="1.0"');
  56. Zend_Oauth::setHttpClient($client);
  57. $resetClient = Zend_Oauth::getHttpClient();
  58. $this->assertEquals(null, $resetClient->getHeader('Authorization'));
  59. }
  60. /**
  61. * @group ZF-10182
  62. */
  63. public function testOauthClientPassingObjectConfigInConstructor()
  64. {
  65. $options = array(
  66. 'requestMethod' => 'GET',
  67. 'siteUrl' => 'http://www.example.com'
  68. );
  69. require_once 'Zend/Config.php';
  70. require_once 'Zend/Oauth/Client.php';
  71. $config = new Zend_Config($options);
  72. $client = new Zend_Oauth_Client($config);
  73. $this->assertEquals('GET', $client->getRequestMethod());
  74. $this->assertEquals('http://www.example.com', $client->getSiteUrl());
  75. }
  76. /**
  77. * @group ZF-10182
  78. */
  79. public function testOauthClientPassingArrayInConstructor()
  80. {
  81. $options = array(
  82. 'requestMethod' => 'GET',
  83. 'siteUrl' => 'http://www.example.com'
  84. );
  85. require_once 'Zend/Oauth/Client.php';
  86. $client = new Zend_Oauth_Client($options);
  87. $this->assertEquals('GET', $client->getRequestMethod());
  88. $this->assertEquals('http://www.example.com', $client->getSiteUrl());
  89. }
  90. }