Browse Source

ZF-8053
added user_agent-option

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18569 44c647ce-9c0f-0410-b52a-842ac1e357ba

sgehrig 16 years ago
parent
commit
3529b22113
2 changed files with 57 additions and 0 deletions
  1. 27 0
      library/Zend/Soap/Client.php
  2. 30 0
      tests/Zend/Soap/ClientTest.php

+ 27 - 0
library/Zend/Soap/Client.php

@@ -82,6 +82,7 @@ class Zend_Soap_Client
     protected $_stream_context      = null;
     protected $_features            = null;
     protected $_cache_wsdl          = null;
+    protected $_user_agent          = null;
 
     /**
      * WSDL used to access server
@@ -256,6 +257,11 @@ class Zend_Soap_Client
                 case 'cache_wsdl':
                     $this->setWsdlCache($value);
                     break;
+                case 'useragent':
+                case 'userAgent':
+                case 'user_agent':
+                    $this->setUserAgent($value);
+                    break;
 
                 // Not used now
                 // case 'connection_timeout':
@@ -302,6 +308,7 @@ class Zend_Soap_Client
         $options['stream_context'] = $this->getStreamContext();
         $options['cache_wsdl']     = $this->getWsdlCache();
         $options['features']       = $this->getSoapFeatures();
+        $options['user_agent']     = $this->getUserAgent();
 
         foreach ($options as $key => $value) {
             if ($value == null) {
@@ -851,6 +858,26 @@ class Zend_Soap_Client
     }
 
     /**
+     * Set the string to use in User-Agent header
+     *
+     * @param  string $userAgent
+     * @return Zend_Soap_Client
+     */
+    public function setUserAgent($userAgent)
+    {
+        $this->_user_agent = (string)$userAgent;
+        return $this;
+    }
+
+    /**
+     * Get current string to use in User-Agent header
+     */
+    public function getUserAgent()
+    {
+        return $this->_user_agent;
+    }
+
+    /**
      * Retrieve request XML
      *
      * @return string

+ 30 - 0
tests/Zend/Soap/ClientTest.php

@@ -172,6 +172,36 @@ class Zend_Soap_ClientTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($client->getOptions() == $options);
     }
 
+    /**
+     * @group ZF-8053
+     */
+    public function testGetAndSetUserAgentOption()
+    {
+        $client = new Zend_Soap_Client();
+        $this->assertNull($client->getUserAgent());
+
+        $client->setUserAgent('agent1');
+        $this->assertEquals('agent1', $client->getUserAgent());
+
+        $client->setOptions(array(
+            'user_agent' => 'agent2'
+        ));
+        $this->assertEquals('agent2', $client->getUserAgent());
+
+        $client->setOptions(array(
+            'useragent' => 'agent3'
+        ));
+        $this->assertEquals('agent3', $client->getUserAgent());
+
+        $client->setOptions(array(
+            'userAgent' => 'agent4'
+        ));
+        $this->assertEquals('agent4', $client->getUserAgent());
+
+        $options = $client->getOptions();
+        $this->assertEquals('agent4', $options['user_agent']);
+    }
+
     public function testGetFunctions()
     {
         $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');