Преглед изворни кода

ZF-5578: Zend_Config support in Zend_Uri

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18194 44c647ce-9c0f-0410-b52a-842ac1e357ba
jan пре 16 година
родитељ
комит
d2b4429d13
2 измењених фајлова са 45 додато и 2 уклоњено
  1. 8 2
      library/Zend/Uri.php
  2. 37 0
      tests/Zend/UriTest.php

+ 8 - 2
library/Zend/Uri.php

@@ -149,10 +149,16 @@ abstract class Zend_Uri
     /**
      * Set global configuration options
      *
-     * @param array $config
+     * @param Zend_Config|array $config
      */
-    static public function setConfig(array $config)
+    static public function setConfig($config)
     {
+        if ($config instanceof Zend_Config) {
+            $config = $config->toArray();
+        } elseif (!is_array($config)) {
+            throw new Zend_Uri_Exception("Config must be an array or an instance of Zend_Config.");
+        }
+        
         foreach ($config as $k => $v) {
             self::$_config[$k] = $v;
         }

+ 37 - 0
tests/Zend/UriTest.php

@@ -35,6 +35,11 @@ require_once dirname(__FILE__) . '/../TestHelper.php';
 require_once 'Zend/Uri.php';
 
 /**
+ * Zend_Config
+ */
+require_once 'Zend/Config.php';
+
+/**
  * @category   Zend
  * @package    Zend_Uri
  * @subpackage UnitTests
@@ -97,6 +102,38 @@ class Zend_UriTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * Tests that Zend_Uri::setConfig() allows Zend_Config
+     * 
+     * @group ZF-5578
+     */
+    public function testSetConfigWithArray()
+    {
+        Zend_Uri::setConfig(array('allow_unwise' => true));
+    }
+    
+    /**
+     * Tests that Zend_Uri::setConfig() allows Array
+     * 
+     * @group ZF-5578
+     */
+    public function testSetConfigWithZendConfig()
+    {
+        Zend_Uri::setConfig(new Zend_Config(array('allow_unwise' => true)));
+    }
+    
+    /**
+     * Tests that Zend_Uri::setConfig() throws Zend_Uri_Exception if no array
+     * nor Zend_Config is given as first parameter
+     * 
+     * @group ZF-5578
+     * @expectedException Zend_Uri_Exception
+     */
+    public function testSetConfigInvalid()
+    {
+        Zend_Uri::setConfig('This should cause an exception');
+    }
+
+    /**
      * Tests that an invalid $uri throws an exception and that the
      * message of that exception matches $regex.
      *