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

ZF-11664: Allow manually setting Zend_Navigation_Page_Mvc::isActive

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24857 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan пре 13 година
родитељ
комит
03ca35cbcf
2 измењених фајлова са 61 додато и 2 уклоњено
  1. 10 2
      library/Zend/Navigation/Page/Mvc.php
  2. 51 0
      tests/Zend/Navigation/Page/MvcTest.php

+ 10 - 2
library/Zend/Navigation/Page/Mvc.php

@@ -94,7 +94,6 @@ class Zend_Navigation_Page_Mvc extends Zend_Navigation_Page
      */
      */
     protected $_resetParams = true;
     protected $_resetParams = true;
 
 
-        
     /**
     /**
      * Whether href should be encoded when assembling URL
      * Whether href should be encoded when assembling URL
      *
      *
@@ -104,6 +103,13 @@ class Zend_Navigation_Page_Mvc extends Zend_Navigation_Page
     protected $_encodeUrl = true;
     protected $_encodeUrl = true;
 
 
     /**
     /**
+     * Whether this page should be considered active
+     *
+     * @var bool
+     */
+    protected $_active = null;
+
+    /**
      * Cached href
      * Cached href
      *
      *
      * The use of this variable minimizes execution time when getHref() is
      * The use of this variable minimizes execution time when getHref() is
@@ -137,7 +143,7 @@ class Zend_Navigation_Page_Mvc extends Zend_Navigation_Page
      */
      */
     public function isActive($recursive = false)
     public function isActive($recursive = false)
     {
     {
-        if (!$this->_active) {
+        if (null === $this->_active) {
             $front     = Zend_Controller_Front::getInstance();
             $front     = Zend_Controller_Front::getInstance();
             $request   = $front->getRequest();
             $request   = $front->getRequest();
             $reqParams = array();
             $reqParams = array();
@@ -186,6 +192,8 @@ class Zend_Navigation_Page_Mvc extends Zend_Navigation_Page
                 $this->_active = true;
                 $this->_active = true;
                 return true;
                 return true;
             }
             }
+            
+            $this->_active = false;
         }
         }
 
 
         return parent::isActive($recursive);
         return parent::isActive($recursive);

+ 51 - 0
tests/Zend/Navigation/Page/MvcTest.php

@@ -267,6 +267,34 @@ class Zend_Navigation_Page_MvcTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(true, $page->isActive());
         $this->assertEquals(true, $page->isActive());
     }
     }
 
 
+    /**
+     * @group ZF-11664
+     */
+    public function testIsActiveWithoutAndWithRecursiveOption()
+    {
+        // Parent
+        $page = new Zend_Navigation_Page_Mvc(array(
+            'controller' => 'index',
+            'action'     => 'index',
+        ));
+
+        // Child
+        $page->addPage(new Zend_Navigation_Page_Mvc(array(
+            'controller' => 'index',
+            'action'     => 'foo',
+        )));
+
+        // Front controller
+        $this->_front->getRequest()->setParams(array(
+            'controller' => 'index',
+            'action'     => 'foo'
+        ));
+
+        $this->assertFalse($page->isActive());
+
+        $this->assertTrue($page->isActive(true));
+    }
+
     public function testActionAndControllerAccessors()
     public function testActionAndControllerAccessors()
     {
     {
         $page = new Zend_Navigation_Page_Mvc(array(
         $page = new Zend_Navigation_Page_Mvc(array(
@@ -380,6 +408,29 @@ class Zend_Navigation_Page_MvcTest extends PHPUnit_Framework_TestCase
     }
     }
 
 
     /**
     /**
+     * @group ZF-11664
+     */
+    public function testSetActiveAndIsActive()
+    {
+        // Page
+        $page = new Zend_Navigation_Page_Mvc(array(
+            'controller' => 'foo',
+            'action'     => 'bar',
+        ));
+
+        // Front controller
+        $this->_front->getRequest()->setParams(array(
+            'controller' => 'foo',
+            'action'     => 'bar'
+        ));
+
+        $this->assertTrue($page->isActive());
+
+        $page->setActive(false);
+        $this->assertFalse($page->isActive());
+    }
+
+    /**
      * @group ZF-10465
      * @group ZF-10465
      */
      */
     public function testSetAndGetEncodeUrl()
     public function testSetAndGetEncodeUrl()