Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
wdalmut committed Jun 14, 2012
12 parents 192d20c + d2649e3 + f0162d1 + 6f01416 + a2b3753 + 1786961 + 1b97191 + d157fcb + 4444c37 + 811122b + 3a2cf9b + eb2029b commit f81b55d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 24 deletions.
24 changes: 20 additions & 4 deletions src/Helper/HeadScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
$attrString = '';
if (!empty($item->attributes)) {
foreach ($item->attributes as $key => $value) {
if (!$this->arbitraryAttributesAllowed()
&& !in_array($key, $this->_optionalAttributes))
if ((!$this->arbitraryAttributesAllowed() && !in_array($key, $this->_optionalAttributes))
|| in_array($key, array('conditional', 'noescape')))
{
continue;
}
Expand All @@ -420,10 +420,25 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
}
}


$addScriptEscape = !(isset($item->attributes['noescape']) && filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN));

$type = ($this->_autoEscape) ? $this->_escape($item->type) : $item->type;
$html = '<script type="' . $type . '"' . $attrString . '>';
if (!empty($item->source)) {
$html .= PHP_EOL . $indent . ' ' . $escapeStart . PHP_EOL . $item->source . $indent . ' ' . $escapeEnd . PHP_EOL . $indent;
$html .= PHP_EOL ;

if ($addScriptEscape) {
$html .= $indent . ' ' . $escapeStart . PHP_EOL;
}

$html .= $indent . ' ' . $item->source;

if ($addScriptEscape) {
$html .= $indent . ' ' . $escapeEnd . PHP_EOL;
}

$html .= $indent;
}
$html .= '</script>';

Expand Down Expand Up @@ -456,8 +471,9 @@ public function toString($indent = null)
} else {
$useCdata = $this->useCdata ? true : false;
}

$escapeStart = ($useCdata) ? '//<![CDATA[' : '//<!--';
$escapeEnd = ($useCdata) ? '//]]>' : '//-->';
$escapeEnd = ($useCdata) ? '//]]>' : '//-->';

$items = array();
$this->getContainer()->ksort();
Expand Down
44 changes: 28 additions & 16 deletions src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,31 @@ public function getContainer()
return $this->container;
}

/**
* Verifies container and eventually fetches it from service locator if it is a string
*
* @param \Zend\Navigation\AbstractContainer|string|null $container
* @throws \Zend\View\Exception\InvalidArgumentException
*/
protected function parseContainer(&$container = null)
{
if (null === $container) {
; // intentionally left blank
} else if (is_string($container)) {
return;
}

if (is_string($container)) {
if (!$this->getServiceLocator()) {
throw new Exception\InvalidArgumentException(sprintf(
'Attempted to set container with alias "%s" but no ServiceLocator wwas set',
'Attempted to set container with alias "%s" but no ServiceLocator was set',
$container
));
}

$container = $this->getServiceLocator()->get($container);
} else if (!$container instanceof Navigation\AbstractContainer) {
return;
}

if (!$container instanceof Navigation\AbstractContainer) {
throw new Exception\InvalidArgumentException(
'Container must be a string alias or an instance of ' .
'Zend\Navigation\AbstractContainer'
Expand All @@ -215,7 +227,7 @@ protected function parseContainer(&$container = null)
/**
* Sets the minimum depth a page must have to be included when rendering
*
* @param int $minDepth [optional] minimum depth. Default is null, which
* @param int $minDepth [optional] minimum depth. Default is null, which
* sets no minimum depth.
* @return AbstractHelper fluent interface, returns self
*/
Expand Down Expand Up @@ -245,7 +257,7 @@ public function getMinDepth()
/**
* Sets the maximum depth a page can have to be included when rendering
*
* @param int $maxDepth [optional] maximum depth. Default is null, which
* @param int $maxDepth [optional] maximum depth. Default is null, which
* sets no maximum depth.
* @return AbstractHelper fluent interface, returns self
*/
Expand Down Expand Up @@ -297,9 +309,9 @@ public function getIndent()
*
* Implements {@link HelperInterface::setTranslator()}.
*
* @param mixed $translator [optional] translator. Expects an object of
* @param mixed $translator [optional] translator. Expects an object of
* type {@link Translator\Adapter\AbstractAdapter}
* or {@link Translator\Translator}, or null.
* or {@link Translator\Translator}, or null.
* Default is null, which sets no translator.
* @return AbstractHelper fluent interface, returns self
*/
Expand Down Expand Up @@ -363,7 +375,7 @@ public function getAcl()
*
* Implements {@link HelperInterface::setRole()}.
*
* @param mixed $role [optional] role to set. Expects a string, an
* @param mixed $role [optional] role to set. Expects a string, an
* instance of type {@link Acl\Role\RoleInterface}, or null. Default
* is null, which will set no role.
* @return AbstractHelper fluent interface, returns self
Expand All @@ -377,7 +389,7 @@ public function setRole($role = null)
$this->role = $role;
} else {
throw new Exception\InvalidArgumentException(sprintf(
'$role must be a string, null, or an instance of '
'$role must be a string, null, or an instance of '
. 'Zend\Acl\Role\RoleInterface; %s given',
(is_object($role) ? get_class($role) : gettype($role))
));
Expand Down Expand Up @@ -456,7 +468,7 @@ public function setRenderInvisible($renderInvisible = true)
*
* Implements {@link HelperInterface::setUseTranslator()}.
*
* @param bool $useTranslator [optional] whether translator should be used.
* @param bool $useTranslator [optional] whether translator should be used.
* Default is true.
* @return AbstractHelper fluent interface, returns self
*/
Expand Down Expand Up @@ -691,8 +703,8 @@ public function htmlify(AbstractPage $page)
* will not be accepted if it is the descendant of a non-accepted page.
*
* @param AbstractPage $page page to check
* @param bool $recursive [optional] if true, page will not be
* accepted if it is the descendant of a
* @param bool $recursive [optional] if true, page will not be
* accepted if it is the descendant of a
* page that is not accepted. Default is true.
* @return bool whether page should be accepted
*/
Expand Down Expand Up @@ -822,16 +834,16 @@ public static function setDefaultAcl(Acl\Acl $acl = null)
* Sets default ACL role(s) to use when iterating pages if not explicitly
* set later with {@link setRole()}
*
* @param mixed $role [optional] role to set. Expects null, string, or an
* @param mixed $role [optional] role to set. Expects null, string, or an
* instance of {@link Acl\Role\RoleInterface}. Default is null, which
* sets no default role.
* @return void
* @throws Exception\InvalidArgumentException if role is invalid
*/
public static function setDefaultRole($role = null)
{
if (null === $role
|| is_string($role)
if (null === $role
|| is_string($role)
|| $role instanceof Acl\Role\RoleInterface
) {
self::$defaultRole = $role;
Expand Down
5 changes: 2 additions & 3 deletions test/Helper/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function setUp()
{
$this->clearRegistry();

$this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
Currency\Currency::setCache($this->_cache);
$cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
Currency\Currency::setCache($cache);

$this->helper = new Helper\Currency('de_AT');
}
Expand All @@ -78,7 +78,6 @@ public function setUp()
public function tearDown()
{
unset($this->helper);
$this->_cache->clear(CacheAdapter::MATCH_ALL);
$this->clearRegistry();
}

Expand Down
38 changes: 37 additions & 1 deletion test/Helper/HeadScriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,41 @@ public function testContainerMaintainsCorrectOrderOfItems()

$this->assertEquals($expected, $test);
}
}

public function testConditionalWithAllowArbitraryAttributesDoesNotIncludeConditionalScript()
{
$this->helper->__invoke()->setAllowArbitraryAttributes(true);
$this->helper->__invoke()->appendFile('/js/foo.js', 'text/javascript', array('conditional' => 'lt IE 7'));
$test = $this->helper->__invoke()->toString();

$this->assertNotContains('conditional', $test);
}

public function testNoEscapeWithAllowArbitraryAttributesDoesNotIncludeNoEscapeScript()
{
$this->helper->__invoke()->setAllowArbitraryAttributes(true);
$this->helper->__invoke()->appendScript('// some script', 'text/javascript', array('noescape' => true));
$test = $this->helper->__invoke()->toString();

$this->assertNotContains('noescape', $test);
}

public function testNoEscapeDefaultsToFalse()
{
$this->helper->__invoke()->appendScript('// some script' . PHP_EOL, 'text/javascript', array());
$test = $this->helper->__invoke()->toString();

$this->assertContains('//<!--', $test);
$this->assertContains('//-->', $test);
}

public function testNoEscapeTrue()
{
$this->helper->__invoke()->appendScript('// some script' . PHP_EOL, 'text/javascript', array('noescape' => true));
$test = $this->helper->__invoke()->toString();

$this->assertNotContains('//<!--', $test);
$this->assertNotContains('//-->', $test);
}

}

0 comments on commit f81b55d

Please sign in to comment.