2
0

UserAuthorizationTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/Http/UserAuthorization.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_Http
  31. */
  32. class Zend_Oauth_Http_UserAuthorizationTest extends PHPUnit_Framework_TestCase
  33. {
  34. protected $stubConsumer = null;
  35. public function setup()
  36. {
  37. $this->stubConsumer = new Test_Consumer_34879;
  38. }
  39. public function testConstructorSetsConsumerInstance()
  40. {
  41. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer);
  42. $this->assertTrue($redirect->getConsumer() instanceof Test_Consumer_34879);
  43. }
  44. public function testConstructorSetsCustomServiceParameters()
  45. {
  46. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer, array(1,2,3));
  47. $this->assertEquals(array(1,2,3), $redirect->getParameters());
  48. }
  49. public function testAssembleParametersReturnsUserAuthorizationParamArray()
  50. {
  51. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer, array('foo '=>'bar~'));
  52. $expected = array(
  53. 'oauth_token'=>'1234567890',
  54. 'oauth_callback'=>'http://www.example.com/local',
  55. 'foo '=>'bar~'
  56. );
  57. $this->assertEquals($expected, $redirect->assembleParams());
  58. }
  59. public function testGetUrlReturnsEncodedQueryStringParamsAppendedToLocalUrl()
  60. {
  61. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer, array('foo '=>'bar~'));
  62. $expected =
  63. 'http://www.example.com/authorize?oauth_token=1234567890&oauth_callback=http%3A%2F%2Fwww.example.com%2Flocal&foo%20=bar~';
  64. $this->assertEquals($expected, $redirect->getUrl());
  65. }
  66. }
  67. class Test_Consumer_34879 extends Zend_Oauth_Consumer
  68. {
  69. public function getUserAuthorizationUrl(){return 'http://www.example.com/authorize';}
  70. public function getCallbackUrl(){return 'http://www.example.com/local';}
  71. public function getLastRequestToken(){$r=new Test_Token_34879;return $r;}
  72. }
  73. class Test_Token_34879
  74. {
  75. public function getToken(){return '1234567890';}
  76. }