2
0
Преглед на файлове

[ZF-10182] Zend_Oauth

- Fix config http client how object Zend_Config. 

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24310 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon преди 14 години
родител
ревизия
1b336879bd
променени са 2 файла, в които са добавени 70 реда и са изтрити 31 реда
  1. 8 14
      library/Zend/Oauth/Client.php
  2. 62 17
      tests/Zend/Oauth/OauthTest.php

+ 8 - 14
library/Zend/Oauth/Client.php

@@ -69,14 +69,18 @@ class Zend_Oauth_Client extends Zend_Http_Client
      * assist in automating OAuth parameter generation, addition and
      * cryptographioc signing of requests.
      *
-     * @param  array $oauthOptions
-     * @param  string $uri
+     * @param  array|Zend_Config $oauthOptions
+     * @param  string            $uri
      * @param  array|Zend_Config $config
      * @return void
      */
     public function __construct($oauthOptions, $uri = null, $config = null)
     {
-        if (!isset($config['rfc3986_strict'])) {
+        if ($config instanceof Zend_Config && !isset($config->rfc3986_strict)) {
+            $config                   = $config->toArray();
+            $config['rfc3986_strict'] = true;
+        } else if (null === $config ||
+                   (is_array($config) && !isset($config['rfc3986_strict']))) {
             $config['rfc3986_strict'] = true;
         }
         parent::__construct($uri, $config);
@@ -89,16 +93,6 @@ class Zend_Oauth_Client extends Zend_Http_Client
         }
     }
 
-    /**
-     * Return the current connection adapter
-     *
-     * @return Zend_Http_Client_Adapter_Interface|string $adapter
-     */
-    public function getAdapter()
-    {
-        return $this->adapter;
-    }
-
    /**
      * Load the connection adapter
      *
@@ -274,7 +268,7 @@ class Zend_Oauth_Client extends Zend_Http_Client
                 foreach ($queryParts as $queryPart) {
                     $kvTuple = explode('=', $queryPart);
                     $params[urldecode($kvTuple[0])] =
-                        (array_key_exists(1, $kvTuple) ? urldecode($kvTuple[1]) : NULL);
+                        (array_key_exists(1, $kvTuple) ? urldecode($kvTuple[1]) : null);
                 }
             }
             if (!empty($this->paramsPost)) {

+ 62 - 17
tests/Zend/Oauth/OauthTest.php

@@ -67,36 +67,81 @@ class Zend_OauthTest extends PHPUnit_Framework_TestCase
 
     /**
      * @group ZF-10182
+     * @dataProvider providerOauthClientOauthOptions
      */
-    public function testOauthClientPassingObjectConfigInConstructor()
+    public function testOauthClientOauthOptionsInConstructor($oauthOptions)
     {
-        $options = array(
-            'requestMethod' => 'GET',
-            'siteUrl'       => 'http://www.example.com'
-        );
-
-        require_once 'Zend/Config.php';
         require_once 'Zend/Oauth/Client.php';
-        $config = new Zend_Config($options);
-        $client = new Zend_Oauth_Client($config);
+        $client = new Zend_Oauth_Client($oauthOptions);
         $this->assertEquals('GET', $client->getRequestMethod());
         $this->assertEquals('http://www.example.com', $client->getSiteUrl());
     }
 
     /**
      * @group ZF-10182
+     * @dataProvider providerOauthClientConfigHttpClient
      */
-    public function testOauthClientPassingArrayInConstructor()
+    public function testOauthClientConfigHttpClientInConstructor($configHttpClient, $expected)
+    {
+        require_once 'Zend/Oauth/Client.php';
+        $client = new Zend_Oauth_Client(null, null, $configHttpClient);
+        $config = $client->getAdapter()->getConfig();
+        $this->assertEquals($expected['rfc'], $config['rfc3986_strict']);
+        $this->assertEquals($expected['useragent'], $config['useragent']);
+        $this->assertEquals($expected['timeout'], $config['timeout']);
+    }
+
+    public function providerOauthClientOauthOptions()
     {
         $options = array(
             'requestMethod' => 'GET',
             'siteUrl'       => 'http://www.example.com'
         );
 
-        require_once 'Zend/Oauth/Client.php';
-        $client = new Zend_Oauth_Client($options);
-        $this->assertEquals('GET', $client->getRequestMethod());
-        $this->assertEquals('http://www.example.com', $client->getSiteUrl());
+        require_once 'Zend/Config.php';
+        return array(
+            array($options),
+            array(new Zend_Config($options))
+        );
+    }
+
+    public function providerOauthClientConfigHttpClient()
+    {
+        return array(
+            array(
+                array('adapter' => 'Zend_Http_Client_Adapter_Test'),
+                array('rfc' => true,
+                      'timeout' => 10,
+                      'useragent' => 'Zend_Http_Client'
+                )
+            ),
+            array(
+                new Zend_Config(array('adapter' => 'Zend_Http_Client_Adapter_Test')),
+                array('rfc' => true,
+                      'timeout' => 10,
+                      'useragent' => 'Zend_Http_Client'
+                )
+            ),
+            array(
+                new Zend_Config(array(
+                   'adapter' => 'Zend_Http_Client_Adapter_Test',
+                   'rfc3986_strict' => false,
+                   'timeout'        => 100,
+                   'useragent' => 'Zend_Http_ClientCustom'
+                )),
+                array('rfc' => false,
+                      'timeout' => 100,
+                      'useragent' => 'Zend_Http_ClientCustom'
+                )
+            ),
+            array(
+                null,
+                array('rfc'       => true,
+                      'timeout'   => 10,
+                      'useragent' => 'Zend_Http_Client'
+                )
+            ),
+        );
     }
 
     /**
@@ -119,7 +164,7 @@ class Zend_OauthTest extends PHPUnit_Framework_TestCase
     public function testOauthClientPreparationWithRealmConfigurationOption()
     {
         require_once "Zend/Oauth/Token/Access.php";
-        
+
         $options = array(
             'requestMethod' => 'GET',
             'siteUrl'       => 'http://www.example.com',
@@ -130,11 +175,11 @@ class Zend_OauthTest extends PHPUnit_Framework_TestCase
         require_once 'Zend/Oauth/Client.php';
         $client = new Zend_Oauth_Client($options);
         $this->assertEquals(NULL,$client->getHeader('Authorization'));
-        
+
         $client->setToken($token);
         $client->setUri('http://oauth.example.com');
         $client->prepareOauth();
-        
+
         $this->assertNotContains('realm=""',$client->getHeader('Authorization'));
         $this->assertContains('realm="someRealm"',$client->getHeader('Authorization'));
     }