2
0

UserAuthorizationTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Oauth/Http/UserAuthorization.php';
  4. class Zend_Oauth_Http_UserAuthorizationTest extends PHPUnit_Framework_TestCase
  5. {
  6. protected $stubConsumer = null;
  7. public function setup()
  8. {
  9. $this->stubConsumer = new Test_Consumer_34879;
  10. }
  11. public function testConstructorSetsConsumerInstance()
  12. {
  13. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer);
  14. $this->assertType('Test_Consumer_34879', $redirect->getConsumer());
  15. }
  16. public function testConstructorSetsCustomServiceParameters()
  17. {
  18. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer, array(1,2,3));
  19. $this->assertEquals(array(1,2,3), $redirect->getParameters());
  20. }
  21. public function testAssembleParametersReturnsUserAuthorizationParamArray()
  22. {
  23. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer, array('foo '=>'bar~'));
  24. $expected = array(
  25. 'oauth_token'=>'1234567890',
  26. 'oauth_callback'=>'http://www.example.com/local',
  27. 'foo '=>'bar~'
  28. );
  29. $this->assertEquals($expected, $redirect->assembleParams());
  30. }
  31. public function testGetUrlReturnsEncodedQueryStringParamsAppendedToLocalUrl()
  32. {
  33. $redirect = new Zend_Oauth_Http_UserAuthorization($this->stubConsumer, array('foo '=>'bar~'));
  34. $expected =
  35. 'http://www.example.com/authorize?oauth_token=1234567890&oauth_callback=http%3A%2F%2Fwww.example.com%2Flocal&foo%20=bar~';
  36. $this->assertEquals($expected, $redirect->getUrl());
  37. }
  38. }
  39. class Test_Consumer_34879 extends Zend_Oauth_Consumer
  40. {
  41. public function getUserAuthorizationUrl(){return 'http://www.example.com/authorize';}
  42. public function getCallbackUrl(){return 'http://www.example.com/local';}
  43. public function getLastRequestToken(){$r=new Test_Token_34879;return $r;}
  44. }
  45. class Test_Token_34879
  46. {
  47. public function getToken(){return '1234567890';}
  48. }