Ver Fonte

ZF-8848: fixed: A conditional headScript() doesn't output indent correctly

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20363 44c647ce-9c0f-0410-b52a-842ac1e357ba
mabe há 16 anos atrás
pai
commit
82086bfd6b

+ 4 - 2
library/Zend/View/Helper/HeadScript.php

@@ -424,7 +424,7 @@ class Zend_View_Helper_HeadScript extends Zend_View_Helper_Placeholder_Container
         }
 
         $type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type;
-        $html  = $indent . '<script type="' . $type . '"' . $attrString . '>';
+        $html  = '<script type="' . $type . '"' . $attrString . '>';
         if (!empty($item->source)) {
               $html .= PHP_EOL . $indent . '    ' . $escapeStart . PHP_EOL . $item->source . $indent . '    ' . $escapeEnd . PHP_EOL . $indent;
         }
@@ -434,7 +434,9 @@ class Zend_View_Helper_HeadScript extends Zend_View_Helper_Placeholder_Container
             && !empty($item->attributes['conditional'])
             && is_string($item->attributes['conditional']))
         {
-            $html = '<!--[if ' . $item->attributes['conditional'] . ']> ' . $html . '<![endif]-->';
+            $html = $indent . '<!--[if ' . $item->attributes['conditional'] . ']> ' . $html . '<![endif]-->';
+        } else {
+            $html = $indent . $html;
         }
 
         return $html;

+ 12 - 4
tests/Zend/View/Helper/HeadScriptTest.php

@@ -424,6 +424,14 @@ document.write(bar.strlen());');
         $this->assertContains('<!--[if lt IE 7]>', $test);
     }
 
+    public function testConditionalScriptWidthIndentation()
+    {
+        $this->helper->headScript()->appendFile('/js/foo.js', 'text/javascript', array('conditional' => 'lt IE 7'));
+        $this->helper->headScript()->setIndent(4);
+        $test = $this->helper->headScript()->toString();
+        $this->assertContains('    <!--[if lt IE 7]>', $test);
+    }
+
     /**
      * @issue ZF-5435
      */
@@ -438,10 +446,10 @@ document.write(bar.strlen());');
 
         $test = $this->helper->toString();
 
-        $expected = '<script type="text/javascript" src="test1.js"></script>
-<script type="text/javascript" src="test4.js"></script>
-<script type="text/javascript" src="test3.js"></script>
-<script type="text/javascript" src="test2.js"></script>';
+        $expected = '<script type="text/javascript" src="test1.js"></script>' . PHP_EOL
+                  . '<script type="text/javascript" src="test4.js"></script>' . PHP_EOL
+                  . '<script type="text/javascript" src="test3.js"></script>' . PHP_EOL
+                  . '<script type="text/javascript" src="test2.js"></script>';
 
         $this->assertEquals($expected, $test);
     }