Просмотр исходного кода

[ZF-5163] _getParam in Controller/Action don't handle 0

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19762 44c647ce-9c0f-0410-b52a-842ac1e357ba
mluiten 16 лет назад
Родитель
Сommit
7c78c96070
2 измененных файлов с 20 добавлено и 1 удалено
  1. 1 1
      library/Zend/Controller/Action.php
  2. 19 0
      tests/Zend/Controller/ActionTest.php

+ 1 - 1
library/Zend/Controller/Action.php

@@ -580,7 +580,7 @@ abstract class Zend_Controller_Action implements Zend_Controller_Action_Interfac
     protected function _getParam($paramName, $default = null)
     {
         $value = $this->getRequest()->getParam($paramName);
-        if ((null == $value) && (null !== $default)) {
+        if ((null === $value) && (null !== $default)) {
             $value = $default;
         }
 

+ 19 - 0
tests/Zend/Controller/ActionTest.php

@@ -227,6 +227,20 @@ class Zend_Controller_ActionTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(isset($params['foo']));
         $this->assertEquals('bar', $params['foo']);
     }
+    
+    /**
+     * @group ZF-5163
+     */
+    public function testGetParamForZeroValues()
+    {
+        $this->_controller->setParam('foo', 'bar');
+        $this->_controller->setParam('bar', 0);
+        $this->_controller->setParam('baz', null);
+        
+        $this->assertEquals('bar', $this->_controller->getParam('foo', -1));
+        $this->assertEquals(0, $this->_controller->getParam('bar', -1));
+        $this->assertEquals(-1, $this->_controller->getParam('baz', -1));
+    }
 
     public function testGetParams()
     {
@@ -543,6 +557,11 @@ class Zend_Controller_ActionTest_TestController extends Zend_Controller_Action
         $this->_setParam($key, $value);
         return $this;
     }
+    
+    public function getParam($key, $default)
+    {
+        return $this->_getParam($key, $default);
+    }
 
     public function redirect($url, $code = 302, $prependBase = true)
     {