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

Defining a numerical key when telling the nav application resource plugin to use the registry works now. Resolves ZF-7461 Fixes ZF-7641 Closes ZF-7461
Those last few words are meant to check if jira automatically closes the issue.



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

freak 16 лет назад
Родитель
Сommit
c46aaeeef3

+ 2 - 3
library/Zend/Application/Resource/Navigation.php

@@ -82,9 +82,8 @@ class Zend_Application_Resource_Navigation
     protected function _storeRegistry()
     {
         $options = $this->getOptions();
-        if(isset($options['storage']) &&
-           isset($options['storage']['registry']) &&
-           isset($options['storage']['registry']['key']))
+        if(isset($options['storage']['registry']['key']) &&
+           !is_numeric($options['storage']['registry']['key'])) // see ZF-7461
         {
            $key = $options['storage']['registry']['key'];
         } else {

+ 32 - 1
tests/Zend/Application/Resource/NavigationTest.php

@@ -138,7 +138,6 @@ class Zend_Application_Resource_NavigationTest extends PHPUnit_Framework_TestCas
         $number = $container->count();
 
         $this->assertEquals($number,1);
-		$this->bootstrap->unregisterPluginResource('view');
     }
     
     /**
@@ -154,6 +153,38 @@ class Zend_Application_Resource_NavigationTest extends PHPUnit_Framework_TestCas
  		
  		$this->assertEquals($view->setInMethodByTest,true);
     }
+    
+    /**
+     * @group ZF-7461
+     */
+    public function testCorrectRegistryKeyIsUsedWhenNumeric()
+    {
+    	// Register view for cases where registry should not be used
+    	$this->bootstrap->registerPluginResource('view');
+    	$this->bootstrap->getPluginResource('view')->getView(); 
+    	
+    	$options1 = array(
+    	   'pages'=> array(new Zend_Navigation_Page_Mvc(array(
+            'action'     => 'index',
+            'controller' => 'index'))), 
+           'storage' => array('registry' => true));
+    	$options = array($options1, 
+    	                 array_merge($options1, array('storage' => array('registry' => '1'))),
+    	                 array_merge($options1, array('storage' => array('registry' => 1))),
+    	                 array_merge($options1, array('storage' => array('registry' => false))));
+    	                 
+    	$results = array();
+    	$key = Zend_Application_Resource_Navigation::DEFAULT_REGISTRY_KEY;
+    	foreach($options as $option) {
+	        $resource = new Zend_Application_Resource_Navigation($option);
+	        $resource->setBootstrap($this->bootstrap)->init();
+            $results[] = Zend_Registry::get($key) instanceof Zend_Navigation;;
+	        Zend_Registry::set($key,null);
+        }
+    
+        $this->assertEquals(array(true,true,true,false),$results);
+        $this->bootstrap->unregisterPluginResource('view');
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LocaleTest::main') {