소스 검색

ZF-10042
Added ability to construct view objects with default values
Added ability for Zend_Application view resources to configure view objects with default variables


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

ralph 14 년 전
부모
커밋
7471baae67
4개의 변경된 파일40개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      library/Zend/Application/Resource/View.php
  2. 8 0
      library/Zend/View/Abstract.php
  3. 20 0
      tests/Zend/Application/Resource/ViewTest.php
  4. 9 0
      tests/Zend/ViewTest.php

+ 3 - 0
library/Zend/Application/Resource/View.php

@@ -78,6 +78,9 @@ class Zend_Application_Resource_View extends Zend_Application_Resource_ResourceA
             if (isset($options['contentType'])) {
                 $this->_view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
             }
+            if (isset($options['assign']) && is_array($options['assign'])) {
+                $this->_view->assign($options['assign']);
+            }
         }
         return $this->_view;
     }

+ 8 - 0
library/Zend/View/Abstract.php

@@ -221,6 +221,14 @@ abstract class Zend_View_Abstract implements Zend_View_Interface
             $this->setLfiProtection($config['lfiProtectionOn']);
         }
 
+        if (array_key_exists('assign', $config)
+            && is_array($config['assign'])
+        ) {
+            foreach ($config['assign'] as $key => $value) {
+                $this->assign($key, $value);
+            }
+        }
+
         $this->init();
     }
 

+ 20 - 0
tests/Zend/Application/Resource/ViewTest.php

@@ -208,8 +208,28 @@ class Zend_Application_Resource_ViewTest extends PHPUnit_Framework_TestCase
         $registry->deleteContainer('Zend_View_Helper_HeadMeta');
         $registry->deleteContainer('Zend_View_Helper_Doctype');
     }
+    
+    /**
+     * @group ZF-10042
+     */
+    public function testAssignmentsAreSet()
+    {
+        $options = array(
+            'assign' => array(
+                'foo' => 'barbapapa',
+                'bar' => 'barbazoo',
+            )
+        );
+        $resource = new Zend_Application_Resource_View($options);
+        $view = $resource->init();
+ 
+        $this->assertEquals('barbapapa', $view->foo);
+        $this->assertEquals('barbazoo', $view->bar);
+    }
+
 }
 
+
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_ViewTest::main') {
     Zend_Application_Resource_ViewTest::main();
 }

+ 9 - 0
tests/Zend/ViewTest.php

@@ -1147,6 +1147,15 @@ class Zend_ViewTest extends PHPUnit_Framework_TestCase
         $paths = $view->getScriptPaths();
         $this->assertContains($path, $paths, var_export($paths, 1));
     }
+    
+    /**
+     * @group ZF-10042
+     */
+    public function testConstructViewObjectWithInitialVariables()
+    {
+        $view = new Zend_View(array('assign' => array('foo' => 'bar')));
+        $this->assertEquals('bar', $view->foo);
+    }
 }
 
 /**