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

ZF-11910: Zend_View_Helper_HeadMeta fatal error when no View object is set

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24776 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 лет назад
Родитель
Сommit
162ae000cd
2 измененных файлов с 16 добавлено и 5 удалено
  1. 5 4
      library/Zend/View/Helper/HeadMeta.php
  2. 11 1
      tests/Zend/View/Helper/HeadMetaTest.php

+ 5 - 4
library/Zend/View/Helper/HeadMeta.php

@@ -202,14 +202,15 @@ class Zend_View_Helper_HeadMeta extends Zend_View_Helper_Placeholder_Container_S
             return false;
         }
 
+        $isHtml5 = is_null($this->view) ? false : $this->view->doctype()->isHtml5();
+
         if (!isset($item->content)
-        && (! $this->view->doctype()->isHtml5()
-        || (! $this->view->doctype()->isHtml5() && $item->type !== 'charset'))) {
+        && (! $isHtml5 || (! $isHtml5 && $item->type !== 'charset'))) {
             return false;
         }
 
         // <meta property= ... /> is only supported with doctype RDFa
-        if (!$this->view->doctype()->isRdfa()
+        if ( !is_null($this->view) && !$this->view->doctype()->isRdfa()
             && $item->type === 'property') {
             return false;
         }
@@ -341,7 +342,7 @@ class Zend_View_Helper_HeadMeta extends Zend_View_Helper_Placeholder_Container_S
 
         $modifiersString = '';
         foreach ($item->modifiers as $key => $value) {
-            if ($this->view->doctype()->isHtml5()
+            if (!is_null($this->view) && $this->view->doctype()->isHtml5()
             && $key == 'scheme') {
                 require_once 'Zend/View/Exception.php';
                 throw new Zend_View_Exception('Invalid modifier '

+ 11 - 1
tests/Zend/View/Helper/HeadMetaTest.php

@@ -532,7 +532,17 @@ class Zend_View_Helper_HeadMetaTest extends PHPUnit_Framework_TestCase
         $this->assertRegExp("|^<!--\[if lt IE 7\]>|", $html);
         $this->assertRegExp("|<!\[endif\]-->$|", $html);
     }
-    
+
+    /**
+     * @group ZF-11910
+     */
+    public function testStandaloneInstantiationWithoutViewDoesNotCauseFatalError()
+    {
+        $expected = '<meta name="foo" content="bar" />';
+        $helper = new Zend_View_Helper_HeadMeta();
+        $result = (string)$helper->headMeta()->appendName('foo','bar');
+        $this->assertEquals($expected, $result);
+    }
 }
 
 // Call Zend_View_Helper_HeadMetaTest::main() if this source file is executed directly.