Ver Fonte

ZF-11663: Incorporate GET parameters set via setParameterGet into Zend_Oauth_Client request

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24414 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan há 14 anos atrás
pai
commit
6fa6c63f14
2 ficheiros alterados com 40 adições e 1 exclusões
  1. 1 1
      library/Zend/Oauth/Client.php
  2. 39 0
      tests/Zend/Oauth/OauthTest.php

+ 1 - 1
library/Zend/Oauth/Client.php

@@ -261,7 +261,7 @@ class Zend_Oauth_Client extends Zend_Http_Client
             $this->setRawData($raw, 'application/x-www-form-urlencoded');
             $this->paramsPost = array();
         } elseif ($requestScheme == Zend_Oauth::REQUEST_SCHEME_QUERYSTRING) {
-            $params = array();
+            $params = $this->paramsGet;            
             $query = $this->getUri()->getQuery();
             if ($query) {
                 $queryParts = explode('&', $this->getUri()->getQuery());

+ 39 - 0
tests/Zend/Oauth/OauthTest.php

@@ -183,4 +183,43 @@ class Zend_OauthTest extends PHPUnit_Framework_TestCase
         $this->assertNotContains('realm=""',$client->getHeader('Authorization'));
         $this->assertContains('realm="someRealm"',$client->getHeader('Authorization'));
     }
+    
+    /**
+     * @group ZF-11663
+     */
+    public function testOauthClientAcceptsGetParametersThroughSetter()
+    {
+        require_once "Zend/Oauth/Token/Access.php";
+        $token = new Zend_Oauth_Token_Access();
+        
+        $options = array(
+            'requestMethod' => 'GET',
+            'requestScheme' => Zend_Oauth::REQUEST_SCHEME_QUERYSTRING,
+            'realm'			=> 'someRealm'
+        );
+        
+        require_once 'Zend/Oauth/Client.php';
+        $client = new Zend_Oauth_Client($options);
+        $client->setToken($token);
+        $client->setUri('http://www.example.com/?test=FooBar');
+        $queryString = $client->getUri()->getQuery();
+        
+        // Check that query string was set properly
+        $this->assertSame('test=FooBar', $queryString);        
+        
+        // Change the GET parameters
+        $client->setParameterGet('test', 'FooBaz');
+        $client->setParameterGet('second', 'TestTest');
+        
+        // Prepare the OAuth request
+        $client->prepareOauth();        
+        $queryString = $client->getUri()->getQuery();
+        
+        // Ensure that parameter 'test' is unchanged, as URI parameters
+        // should take precedence over ones set with setParameterGet
+        $this->assertContains('test=FooBar', $queryString);
+        
+        // Ensure that new parameter was added
+        $this->assertContains('second=TestTest', $queryString);
+    }
 }