diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 21d57da5..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "tools/phptools"] - path = tools/phptools - url = git://github.com/ralphschindler/PHPTools.git diff --git a/composer.json b/composer.json index 6cab7681..032477d2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "zendframework/zend-view", - "description": "Zend\\View component", + "description": "provides a system of helpers, output filters, and variable escaping", "license": "BSD-3-Clause", "keywords": [ "zf2", @@ -9,11 +9,11 @@ "homepage": "https://github.com/zendframework/zend-view", "autoload": { "psr-4": { - "Zend\\View\\": "src/" + "Zend\\View": "src/" } }, "require": { - "php": ">=5.3.23", + "php": ">=5.3.3", "zendframework/zend-eventmanager": "self.version", "zendframework/zend-loader": "self.version", "zendframework/zend-stdlib": "self.version" diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index f1bcde48..3b863e1f 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -1,21 +1,11 @@ view->plugin('escape'); + $escaper = $this->view->plugin('escapehtml'); foreach ((array) $attribs as $key => $val) { $key = $escaper($key); diff --git a/src/Helper/BasePath.php b/src/Helper/BasePath.php index b0a7cf4c..87400447 100644 --- a/src/Helper/BasePath.php +++ b/src/Helper/BasePath.php @@ -1,22 +1,11 @@ setCurrency($currency); - } - - /** - * Output a formatted currency - * - * @param integer|float $value Currency value to output - * @param string|\Zend\Locale\Locale|array $currency OPTIONAL Currency to use for this call - * @return string Formatted currency - */ - public function __invoke($value = null, $currency = null) - { - if ($value === null) { - return $this; - } - - if (is_string($currency) || ($currency instanceof Locale\Locale)) { - if (Locale\Locale::isLocale($currency)) { - $currency = array('locale' => $currency); - } - } - - if (is_string($currency)) { - $currency = array('currency' => $currency); - } - - if (is_array($currency)) { - return $this->_currency->toCurrency($value, $currency); - } - - return $this->_currency->toCurrency($value); - } - - /** - * Sets a currency to use - * - * @param Zend_Currency|String|\Zend\Locale\Locale $currency Currency to use - * @throws \Zend\View\Exception When no or a false currency was set - * @return \Zend\View\Helper\Currency - */ - public function setCurrency($currency = null) - { - if (!$currency instanceof \Zend\Currency\Currency) { - $currency = new \Zend\Currency\Currency($currency); - } - $this->_currency = $currency; - - return $this; - } - - /** - * Retrieve currency object - * - * @return \Zend\Currency\Currency|null - */ - public function getCurrency() - { - return $this->_currency; - } -} diff --git a/src/Helper/Cycle.php b/src/Helper/Cycle.php index 54cbcbfd..0248a65f 100644 --- a/src/Helper/Cycle.php +++ b/src/Helper/Cycle.php @@ -1,22 +1,11 @@ $value) { $this->_declareVar($name, $value); } - } else if (!isset($view->vars()->$key)) { + } elseif (!isset($view->vars()->$key)) { $this->_declareVar($key); } } diff --git a/src/Helper/Doctype.php b/src/Helper/Doctype.php index 4b935e44..931970f2 100644 --- a/src/Helper/Doctype.php +++ b/src/Helper/Doctype.php @@ -1,37 +1,23 @@ array( + self::XHTML11 => '', + self::XHTML1_STRICT => '', + self::XHTML1_TRANSITIONAL => '', + self::XHTML1_FRAMESET => '', + self::XHTML1_RDFA => '', + self::XHTML1_RDFA11 => '', + self::XHTML_BASIC1 => '', + self::XHTML5 => '', + self::HTML4_STRICT => '', + self::HTML4_LOOSE => '', + self::HTML4_FRAMESET => '', + self::HTML5 => '', + ), + )); + } + + /** + * Unset the static doctype registry + * + * Mainly useful for testing purposes. Sets {@link $registeredDoctypes} to + * a null value. + * + * @return void + */ + public static function unsetDoctypeRegistry() + { + static::$registeredDoctypes = null; + } /** * Constructor @@ -78,28 +102,11 @@ class Doctype extends AbstractHelper */ public function __construct() { - if (!Registry::isRegistered($this->_regKey)) { - $this->_registry = new ArrayObject(array( - 'doctypes' => array( - self::XHTML11 => '', - self::XHTML1_STRICT => '', - self::XHTML1_TRANSITIONAL => '', - self::XHTML1_FRAMESET => '', - self::XHTML1_RDFA => '', - self::XHTML_BASIC1 => '', - self::XHTML5 => '', - self::HTML4_STRICT => '', - self::HTML4_LOOSE => '', - self::HTML4_FRAMESET => '', - self::HTML5 => '', - ) - )); - - Registry::set($this->_regKey, $this->_registry); - $this->setDoctype($this->_defaultDoctype); - } else { - $this->_registry = Registry::get($this->_regKey); + if (null === static::$registeredDoctypes) { + static::registerDefaultDoctypes(); + $this->setDoctype($this->defaultDoctype); } + $this->registry = static::$registeredDoctypes; } /** @@ -119,6 +126,7 @@ public function __invoke($doctype = null) case self::XHTML1_FRAMESET: case self::XHTML_BASIC1: case self::XHTML1_RDFA: + case self::XHTML1_RDFA11: case self::XHTML5: case self::HTML4_STRICT: case self::HTML4_LOOSE: @@ -136,7 +144,7 @@ public function __invoke($doctype = null) $type = self::CUSTOM; } $this->setDoctype($type); - $this->_registry['doctypes'][$type] = $doctype; + $this->registry['doctypes'][$type] = $doctype; break; } } @@ -152,7 +160,7 @@ public function __invoke($doctype = null) */ public function setDoctype($doctype) { - $this->_registry['doctype'] = $doctype; + $this->registry['doctype'] = $doctype; return $this; } @@ -163,7 +171,10 @@ public function setDoctype($doctype) */ public function getDoctype() { - return $this->_registry['doctype']; + if (!isset($this->registry['doctype'])) { + $this->setDoctype($this->defaultDoctype); + } + return $this->registry['doctype']; } /** @@ -173,7 +184,7 @@ public function getDoctype() */ public function getDoctypes() { - return $this->_registry['doctypes']; + return $this->registry['doctypes']; } /** diff --git a/src/Helper/Escape.php b/src/Helper/Escape.php deleted file mode 100644 index 069e411e..00000000 --- a/src/Helper/Escape.php +++ /dev/null @@ -1,185 +0,0 @@ -supportedEncodings)) { - throw new Exception\InvalidArgumentException( - 'Value of \'' . $encoding . '\' passed to ' . get_called_class() - . '::setEncoding() is invalid. Provide an encoding supported by htmlspecialchars()' - ); - } - $this->encoding = $encoding; - return $this; - } - - /** - * Get the encoding to use for escape operations - * - * @return string - */ - public function getEncoding() - { - return $this->encoding; - } - - /** - * Set a callback to use for escaping - * - * @param callback $callback - * @return Escape - * @throws Exception\InvalidArgumentException if provided callback is not callable - */ - public function setCallback($callback) - { - if (!is_callable($callback)) { - throw new Exception\InvalidArgumentException('Invalid callback provided to ' . get_called_class()); - } - $this->callback = $callback; - return $this; - } - - /** - * Get the attached callback - * - * If none defined, creates a closure wrapping htmlspecialchars, providing - * the currently set encoding. - * - * @return callback - */ - public function getCallback() - { - if (!is_callable($this->callback)) { - $encoding = $this->getEncoding(); - $callback = function($value) use ($encoding) { - return htmlspecialchars($value, ENT_QUOTES, $encoding, false); - }; - $this->setCallback($callback); - } - return $this->callback; - } - - /** - * Invoke this helper: escape a value - * - * @param mixed $value - * @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping - * @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array. - * @throws Exception\InvalidArgumentException - */ - public function __invoke($value, $recurse = self::RECURSE_NONE) - { - if (is_string($value)) { - $callback = $this->getCallback(); - return call_user_func($callback, $value); - } - if (is_array($value)) { - if (!(self::RECURSE_ARRAY & $recurse)) { - throw new Exception\InvalidArgumentException( - 'Array provided to Escape helper, but flags do not allow recursion' - ); - } - foreach ($value as $k => $v) { - $value[$k] = $this->__invoke($v, $recurse); - } - return $value; - } - if (is_object($value)) { - if (!(self::RECURSE_OBJECT & $recurse)) { - // Attempt to cast it to a string - if (method_exists($value, '__toString')) { - $callback = $this->getCallback(); - return call_user_func($callback, (string) $value); - } - - throw new Exception\InvalidArgumentException( - 'Object provided to Escape helper, but flags do not allow recursion' - ); - } - if (method_exists($value, 'toArray')) { - return $this->__invoke($value->toArray(), $recurse | self::RECURSE_ARRAY); - } - return $this->__invoke((array) $value, $recurse | self::RECURSE_ARRAY); - } - - // At this point, we have a scalar; simply return it - return $value; - } -} diff --git a/src/Helper/EscapeCss.php b/src/Helper/EscapeCss.php new file mode 100644 index 00000000..597d4486 --- /dev/null +++ b/src/Helper/EscapeCss.php @@ -0,0 +1,36 @@ +getEscaper()->escapeCss($value); + } + +} diff --git a/src/Helper/EscapeHtml.php b/src/Helper/EscapeHtml.php new file mode 100644 index 00000000..0ee00dcc --- /dev/null +++ b/src/Helper/EscapeHtml.php @@ -0,0 +1,36 @@ +getEscaper()->escapeHtml($value); + } + +} diff --git a/src/Helper/EscapeHtmlAttr.php b/src/Helper/EscapeHtmlAttr.php new file mode 100644 index 00000000..e674f089 --- /dev/null +++ b/src/Helper/EscapeHtmlAttr.php @@ -0,0 +1,36 @@ +getEscaper()->escapeHtmlAttr($value); + } + +} diff --git a/src/Helper/EscapeJs.php b/src/Helper/EscapeJs.php new file mode 100644 index 00000000..c186e109 --- /dev/null +++ b/src/Helper/EscapeJs.php @@ -0,0 +1,36 @@ +getEscaper()->escapeJs($value); + } + +} diff --git a/src/Helper/EscapeUrl.php b/src/Helper/EscapeUrl.php new file mode 100644 index 00000000..a687f133 --- /dev/null +++ b/src/Helper/EscapeUrl.php @@ -0,0 +1,36 @@ +getEscaper()->escapeUrl($value); + } + +} diff --git a/src/Helper/Escaper/AbstractHelper.php b/src/Helper/Escaper/AbstractHelper.php new file mode 100644 index 00000000..453cbb50 --- /dev/null +++ b/src/Helper/Escaper/AbstractHelper.php @@ -0,0 +1,138 @@ +escaper = $escaper; + $this->encoding = $escaper->getEncoding(); + return $this; + } + + public function getEscaper() + { + if (null === $this->escaper) { + $this->setEscaper(new Escaper\Escaper($this->getEncoding())); + } + return $this->escaper; + } + + /** + * Set the encoding to use for escape operations + * + * @param string $encoding + * @return AbstractEscaper + */ + public function setEncoding($encoding) + { + if (!is_null($this->escaper)) { + throw new Exception\InvalidArgumentException( + 'Character encoding settings cannot be changed once the Helper has been used or ' + . ' if a Zend\Escaper\Escaper object (with preset encoding option) is set.' + ); + } + $this->encoding = $encoding; + return $this; + } + + /** + * Get the encoding to use for escape operations + * + * @return string + */ + public function getEncoding() + { + return $this->encoding; + } + + /** + * Invoke this helper: escape a value + * + * @param mixed $value + * @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping + * @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array. + * @throws Exception\InvalidArgumentException + */ + public function __invoke($value, $recurse = self::RECURSE_NONE) + { + if (is_string($value)) { + return $this->escape($value); + } + if (is_array($value)) { + if (!(self::RECURSE_ARRAY & $recurse)) { + throw new Exception\InvalidArgumentException( + 'Array provided to Escape helper, but flags do not allow recursion' + ); + } + foreach ($value as $k => $v) { + $value[$k] = $this->__invoke($v, $recurse); + } + return $value; + } + if (is_object($value)) { + if (!(self::RECURSE_OBJECT & $recurse)) { + // Attempt to cast it to a string + if (method_exists($value, '__toString')) { + return $this->escape((string) $value); + } + throw new Exception\InvalidArgumentException( + 'Object provided to Escape helper, but flags do not allow recursion' + ); + } + if (method_exists($value, 'toArray')) { + return $this->__invoke($value->toArray(), $recurse | self::RECURSE_ARRAY); + } + return $this->__invoke((array) $value, $recurse | self::RECURSE_ARRAY); + } + // At this point, we have a scalar; simply return it + return $value; + } + + /** + * Escape a value for current escaping strategy + * + * @param string $value + * @return string + */ + abstract protected function escape($value); + +} diff --git a/src/Helper/FormElement.php b/src/Helper/FormElement.php deleted file mode 100644 index 43eec6bb..00000000 --- a/src/Helper/FormElement.php +++ /dev/null @@ -1,194 +0,0 @@ -_translator; - } - - /** - * Set translator - * - * @param $translator|null \Zend\Translator\Translator - * @return \Zend\View\Helper\FormElement - * @throws Exception\InvalidArgumentException - */ - public function setTranslator($translator = null) - { - if (null === $translator) { - $this->_translator = null; - } elseif ($translator instanceof \Zend\Translator\Adapter\AbstractAdapter) { - $this->_translator = $translator; - } elseif ($translator instanceof \Zend\Translator\Translator) { - $this->_translator = $translator->getAdapter(); - } else { - throw new Exception\InvalidArgumentException('Invalid translator specified'); - } - - return $this; - } - - /** - * Converts parameter arguments to an element info array. - * - * E.g, formExample($name, $value, $attribs, $options, $listsep) is - * the same thing as formExample(array('name' => ...)). - * - * Note that you cannot pass a 'disable' param; you need to pass - * it as an 'attribs' key. - * - * @access protected - * - * @return array An element info array with keys for name, value, - * attribs, options, listsep, disable, and escape. - */ - protected function _getInfo($name, $value = null, $attribs = null, - $options = null, $listsep = null - ) { - // the baseline info. note that $name serves a dual purpose; - // if an array, it's an element info array that will override - // these baseline values. as such, ignore it for the 'name' - // if it's an array. - $info = array( - 'name' => is_array($name) ? '' : $name, - 'id' => is_array($name) ? '' : $name, - 'value' => $value, - 'attribs' => $attribs, - 'options' => $options, - 'listsep' => $listsep, - 'disable' => false, - 'escape' => true, - ); - - // override with named args - if (is_array($name)) { - // only set keys that are already in info - foreach ($info as $key => $val) { - if (isset($name[$key])) { - $info[$key] = $name[$key]; - } - } - - // If all helper options are passed as an array, attribs may have - // been as well - if (null === $attribs) { - $attribs = $info['attribs']; - } - } - - $attribs = (array)$attribs; - - // Normalize readonly tag - if (array_key_exists('readonly', $attribs)) { - $attribs['readonly'] = 'readonly'; - } - - // Disable attribute - if (array_key_exists('disable', $attribs)) { - if (is_scalar($attribs['disable'])) { - // disable the element - $info['disable'] = (bool)$attribs['disable']; - } else if (is_array($attribs['disable'])) { - $info['disable'] = $attribs['disable']; - } - } - - // Set ID for element - if (array_key_exists('id', $attribs)) { - $info['id'] = (string)$attribs['id']; - } else if ('' !== $info['name']) { - $info['id'] = trim(strtr($info['name'], - array('[' => '-', ']' => '')), '-'); - } - - // Determine escaping from attributes - if (array_key_exists('escape', $attribs)) { - $info['escape'] = (bool)$attribs['escape']; - } - - // Determine listsetp from attributes - if (array_key_exists('listsep', $attribs)) { - $info['listsep'] = (string)$attribs['listsep']; - } - - // Remove attribs that might overwrite the other keys. We do this LAST - // because we needed the other attribs values earlier. - foreach ($info as $key => $val) { - if (array_key_exists($key, $attribs)) { - unset($attribs[$key]); - } - } - $info['attribs'] = $attribs; - - // done! - return $info; - } - - /** - * Creates a hidden element. - * - * We have this as a common method because other elements often - * need hidden elements for their operation. - * - * @access protected - * - * @param $name The element name. - * - * @param $value The element value. - * - * @param $attribs Attributes for the element. - * - * @return string A hidden element. - */ - protected function _hidden($name, $value = null, $attribs = null) - { - $escaper = $this->view->plugin('escape'); - return '_htmlAttribs($attribs) . $this->getClosingBracket(); - } -} diff --git a/src/Helper/Gravatar.php b/src/Helper/Gravatar.php index 8f73f84c..eed71bfe 100644 --- a/src/Helper/Gravatar.php +++ b/src/Helper/Gravatar.php @@ -1,22 +1,11 @@ - * - * Not valid in a non-HTML5 doctype - * - * @param string $charset - * @return \Zend\View\Helper\HeadMeta Provides a fluent interface - */ + /** + * Create an HTML5-style meta charset tag. Something like + * + * Not valid in a non-HTML5 doctype + * + * @param string $charset + * @return \Zend\View\Helper\HeadMeta Provides a fluent interface + */ public function setCharset($charset) { $item = new \stdClass; @@ -357,9 +344,9 @@ public function itemToString(\stdClass $item) if ($this->view->plugin('doctype')->isHtml5() && $type == 'charset' ) { - $tpl = ($this->view->plugin('doctype')->isXhtml()) - ? '' - : ''; + $tpl = ($this->view->plugin('doctype')->isXhtml()) + ? '' + : ''; } elseif ($this->view->plugin('doctype')->isXhtml()) { $tpl = ''; } else { diff --git a/src/Helper/HeadScript.php b/src/Helper/HeadScript.php index 45cbeb64..27bebac7 100644 --- a/src/Helper/HeadScript.php +++ b/src/Helper/HeadScript.php @@ -1,38 +1,25 @@ 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; @@ -437,7 +424,7 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd) if ($addScriptEscape) { $html .= $indent . ' ' . $escapeEnd . PHP_EOL; } - + $html .= $indent; } $html .= ''; diff --git a/src/Helper/HeadStyle.php b/src/Helper/HeadStyle.php index d1564378..f1d062ed 100644 --- a/src/Helper/HeadStyle.php +++ b/src/Helper/HeadStyle.php @@ -1,38 +1,25 @@ _defaultAttachOrder; } - /** - * Sets a translation Adapter for translation - * - * @param Zend_Translator|\Zend\Translator\Adapter\Adapter $translate - * @return \Zend\View\Helper\HeadTitle - * @throws Exception\InvalidArgumentException - */ - public function setTranslator($translate) - { - if ($translate instanceof \Zend\Translator\Adapter\AbstractAdapter) { - $this->_translator = $translate; - } elseif ($translate instanceof \Zend\Translator\Translator) { - $this->_translator = $translate->getAdapter(); - } else { - throw new Exception\InvalidArgumentException( - "You must set an instance of Zend_Translator or Zend_Translator_Adapter" - ); - } - return $this; - } - - /** - * Retrieve translation object - * - * If none is currently registered, attempts to pull it from the registry - * using the key 'Zend_Translator'. - * - * @return Zend_Translator_Adapter|null - */ - public function getTranslator() - { - if (null === $this->_translator) { - if (\Zend\Registry::isRegistered('Zend_Translator')) { - $this->setTranslator(\Zend\Registry::get('Zend_Translator')); - } - } - return $this->_translator; - } - - /** - * Enables translation - * - * @return \Zend\View\Helper\HeadTitle - */ - public function enableTranslation() - { - $this->_translate = true; - return $this; - } - - /** - * Disables translation - * - * @return \Zend\View\Helper\HeadTitle - */ - public function disableTranslation() - { - $this->_translate = false; - return $this; - } - /** * Turn helper into string * * @param string|null $indent - * @param string|null $locale * @return string */ - public function toString($indent = null, $locale = null) + public function toString($indent = null) { $indent = (null !== $indent) ? $this->getWhitespace($indent) @@ -197,9 +133,11 @@ public function toString($indent = null, $locale = null) $items = array(); - if($this->_translate && $translator = $this->getTranslator()) { + if (null !== ($translator = $this->getTranslator())) { foreach ($this as $item) { - $items[] = $translator->translate($item, $locale); + $items[] = $translator->translate( + $item, $this->getTranslatorTextDomain() + ); } } else { foreach ($this as $item) { @@ -211,14 +149,14 @@ public function toString($indent = null, $locale = null) $output = ''; $prefix = $this->getPrefix(); - if($prefix) { + if ($prefix) { $output .= $prefix; } $output .= implode($separator, $items); $postfix = $this->getPostfix(); - if($postfix) { + if ($postfix) { $output .= $postfix; } @@ -226,4 +164,93 @@ public function toString($indent = null, $locale = null) return $indent . '
$this->container
.
*
* @param AbstractContainer $container [optional] container to pass to view script.
- * Default is to use the container registered
+ * Default is to use the container registered
* in the helper.
- * @param string|array $partial [optional] partial view script to use.
- * Default is to use the partial registered
- * in the helper. If an array is given, it
- * is expected to contain two values; the
- * partial view script to use, and the module
+ * @param string|array $partial [optional] partial view script to use.
+ * Default is to use the partial registered
+ * in the helper. If an array is given, it
+ * is expected to contain two values; the
+ * partial view script to use, and the module
* where the script can be found.
* @return string helper output
* @throws Exception\RuntimeException if no partial provided
diff --git a/src/Helper/Navigation/HelperInterface.php b/src/Helper/Navigation/HelperInterface.php
index 1016e483..0dc134d5 100644
--- a/src/Helper/Navigation/HelperInterface.php
+++ b/src/Helper/Navigation/HelperInterface.php
@@ -1,28 +1,19 @@
findRelation($arguments[0],
strtolower($match[1]),
strtolower($match[2]));
@@ -737,8 +728,8 @@ public function renderLink(AbstractPage $page, $attrib, $relation)
* Implements {@link HelperInterface::render()}.
*
* @param AbstractContainer string|$container [optional] container to render.
- * Default is to render the
- * container registered in the
+ * Default is to render the
+ * container registered in the
* helper.
* @return string helper output
*/
diff --git a/src/Helper/Navigation/Menu.php b/src/Helper/Navigation/Menu.php
index 96cfffeb..372287af 100644
--- a/src/Helper/Navigation/Menu.php
+++ b/src/Helper/Navigation/Menu.php
@@ -1,22 +1,11 @@
getTitle();
// translate label and title?
- if ($this->getUseTranslator() && $t = $this->getTranslator()) {
+ if (null !== ($translator = $this->getTranslator())) {
+ $textDomain = $this->getTranslatorTextDomain();
if (is_string($label) && !empty($label)) {
- $label = $t->translate($label);
+ $label = $translator->translate($label, $textDomain);
}
if (is_string($title) && !empty($title)) {
- $title = $t->translate($title);
+ $title = $translator->translate($title, $textDomain);
}
}
@@ -233,7 +221,7 @@ public function htmlify(AbstractPage $page)
$element = 'span';
}
- $escaper = $this->view->plugin('escape');
+ $escaper = $this->view->plugin('escapeHtml');
return '<' . $element . $this->_htmlAttribs($attribs) . '>'
. $escaper($label)
. '' . $element . '>';
@@ -319,10 +307,10 @@ protected function renderDeepestMenu(AbstractContainer $container,
if (!$active['page']->hasPages()) {
return '';
}
- } else if (!$active['page']->hasPages()) {
+ } elseif (!$active['page']->hasPages()) {
// found pages has no children; render siblings
$active['page'] = $active['page']->getParent();
- } else if (is_int($maxDepth) && $active['depth'] +1 > $maxDepth) {
+ } elseif (is_int($maxDepth) && $active['depth'] +1 > $maxDepth) {
// children are below max depth; render siblings
$active['page'] = $active['page']->getParent();
}
@@ -389,14 +377,14 @@ protected function _renderMenu(AbstractContainer $container,
if ($depth < $minDepth || !$this->accept($page)) {
// page is below minDepth or not accepted by acl/visibilty
continue;
- } else if ($onlyActive && !$isActive) {
+ } elseif ($onlyActive && !$isActive) {
// page is not active itself, but might be in the active branch
$accept = false;
if ($foundPage) {
if ($foundPage->hasPage($page)) {
// accept if page is a direct child of the active page
$accept = true;
- } else if ($foundPage->getParent()->hasPage($page)) {
+ } elseif ($foundPage->getParent()->hasPage($page)) {
// page is a sibling of the active page...
if (!$foundPage->hasPages() ||
is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
@@ -424,7 +412,7 @@ protected function _renderMenu(AbstractContainer $container,
$ulClass = '';
}
$html .= $myIndent . 'echo 'Number of pages: ', count($this->container);
.
*
* @param AbstractContainer $container [optional] container to pass to view
- * script. Default is to use the container
+ * script. Default is to use the container
* registered in the helper.
- * @param string|array $partial [optional] partial view script to use.
- * Default is to use the partial
- * registered in the helper. If an array
- * is given, it is expected to contain two
- * values; the partial view script to use,
- * and the module where the script can be
+ * @param string|array $partial [optional] partial view script to use.
+ * Default is to use the partial
+ * registered in the helper. If an array
+ * is given, it is expected to contain two
+ * values; the partial view script to use,
+ * and the module where the script can be
* found.
* @return string helper output
* @throws Exception\RuntimeException if no partial provided
@@ -621,7 +609,7 @@ public function renderPartial($container = null, $partial = null)
* @see renderMenu()
*
* @param AbstractContainer $container [optional] container to render. Default is
- * to render the container registered in the
+ * to render the container registered in the
* helper.
* @return string helper output
*/
diff --git a/src/Helper/Navigation/PluginManager.php b/src/Helper/Navigation/PluginManager.php
index 377b8f5a..c743bb8c 100644
--- a/src/Helper/Navigation/PluginManager.php
+++ b/src/Helper/Navigation/PluginManager.php
@@ -1,22 +1,11 @@
getServerUrl(), '/') . '/'
- . $curDoc
- . (empty($curDoc) ? '' : '/') . $href;
+ . $curDoc
+ . (empty($curDoc) ? '' : '/') . $href;
}
- return $this->xmlEscape($url);
+ if (! in_array($url, $this->urls)) {
+
+ $this->urls[] = $url;
+ return $this->xmlEscape($url);
+ }
+
+ return null;
}
/**
@@ -309,6 +309,9 @@ public function url(AbstractPage $page)
*/
public function getDomSitemap(AbstractContainer $container = null)
{
+ // Reset the urls
+ $this->urls = array();
+
if (null === $container) {
$container = $this->getContainer();
}
@@ -353,6 +356,7 @@ public function getDomSitemap(AbstractContainer $container = null)
// get absolute url from page
if (!$url = $this->url($page)) {
// skip page if it has no url (rare case)
+ // or already is in the sitemap
continue;
}
@@ -364,14 +368,14 @@ public function getDomSitemap(AbstractContainer $container = null)
&& !$locValidator->isValid($url)
) {
throw new Exception\RuntimeException(sprintf(
- 'Encountered an invalid URL for Sitemap XML: "%s"',
- $url
+ 'Encountered an invalid URL for Sitemap XML: "%s"',
+ $url
));
}
// put url in 'loc' element
$urlNode->appendChild($dom->createElementNS(self::SITEMAP_NS,
- 'loc', $url));
+ 'loc', $url));
// add 'lastmod' element if a valid lastmod is set in page
if (isset($page->lastmod)) {
@@ -386,7 +390,7 @@ public function getDomSitemap(AbstractContainer $container = null)
$lastmodValidator->isValid($lastmod)) {
$urlNode->appendChild(
$dom->createElementNS(self::SITEMAP_NS, 'lastmod',
- $lastmod)
+ $lastmod)
);
}
}
@@ -398,7 +402,7 @@ public function getDomSitemap(AbstractContainer $container = null)
$changefreqValidator->isValid($changefreq)) {
$urlNode->appendChild(
$dom->createElementNS(self::SITEMAP_NS, 'changefreq',
- $changefreq)
+ $changefreq)
);
}
}
@@ -410,7 +414,7 @@ public function getDomSitemap(AbstractContainer $container = null)
$priorityValidator->isValid($priority)) {
$urlNode->appendChild(
$dom->createElementNS(self::SITEMAP_NS, 'priority',
- $priority)
+ $priority)
);
}
}
@@ -420,8 +424,8 @@ public function getDomSitemap(AbstractContainer $container = null)
if ($this->getUseSchemaValidation()) {
if (!@$dom->schemaValidate(self::SITEMAP_XSD)) {
throw new Exception\RuntimeException(sprintf(
- 'Sitemap is invalid according to XML Schema at "%s"',
- self::SITEMAP_XSD
+ 'Sitemap is invalid according to XML Schema at "%s"',
+ self::SITEMAP_XSD
));
}
}
@@ -437,7 +441,7 @@ public function getDomSitemap(AbstractContainer $container = null)
* Implements {@link HelperInterface::render()}.
*
* @param link|AbstractContainer $container [optional] container to render. Default is
- * to render the container registered in the
+ * to render the container registered in the
* helper.
* @return string helper output
*/
@@ -445,8 +449,8 @@ public function render($container = null)
{
$dom = $this->getDomSitemap($container);
$xml = $this->getUseXmlDeclaration() ?
- $dom->saveXML() :
- $dom->saveXML($dom->documentElement);
+ $dom->saveXML() :
+ $dom->saveXML($dom->documentElement);
return rtrim($xml, PHP_EOL);
}
diff --git a/src/Helper/PaginationControl.php b/src/Helper/PaginationControl.php
index 3795b8ba..0bf6093a 100644
--- a/src/Helper/PaginationControl.php
+++ b/src/Helper/PaginationControl.php
@@ -1,34 +1,22 @@
getPages($scrollingStyle));
diff --git a/src/Helper/Partial.php b/src/Helper/Partial.php
index db4410bb..0372b852 100644
--- a/src/Helper/Partial.php
+++ b/src/Helper/Partial.php
@@ -1,22 +1,11 @@
view, 'getEncoding')
) {
$enc = $this->view->getEncoding();
+ $escaper = $this->view->plugin('escapeHtml');
+ return $escaper((string) $string);
}
-
- return htmlspecialchars((string) $string, ENT_COMPAT, $enc);
+ /**
+ * bump this out to a protected method to kill the instance penalty!
+ */
+ $escaper = new \Zend\Escaper\Escaper($enc);
+ return $escaper->escapeHtml((string) $string);
+ /**
+ * Replaced to ensure consistent escaping
+ */
+ //return htmlspecialchars((string) $string, ENT_COMPAT, $enc);
}
/**
* Set container on which to operate
*
* @param \Zend\View\Helper\Placeholder\Container\AbstractContainer $container
- * @return \Zend\View\Helper\Placeholder\Container\Standalone
+ * @return \Zend\View\Helper\Placeholder\Container\AbstractStandalone
*/
public function setContainer(AbstractContainer $container)
{
diff --git a/src/Helper/Placeholder/Registry.php b/src/Helper/Placeholder/Registry.php
index e6820934..369d3248 100644
--- a/src/Helper/Placeholder/Registry.php
+++ b/src/Helper/Placeholder/Registry.php
@@ -1,27 +1,15 @@
setHost($_SERVER['HTTP_HOST']);
- } else if (isset($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'])) {
+ } elseif (isset($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'])) {
$name = $_SERVER['SERVER_NAME'];
$port = $_SERVER['SERVER_PORT'];
@@ -94,7 +81,7 @@ public function __invoke($requestUri = null)
{
if ($requestUri === true) {
$path = $_SERVER['REQUEST_URI'];
- } else if (is_string($requestUri)) {
+ } elseif (is_string($requestUri)) {
$path = $requestUri;
} else {
$path = '';
diff --git a/src/Helper/Translator.php b/src/Helper/Translator.php
deleted file mode 100644
index 6906cd1d..00000000
--- a/src/Helper/Translator.php
+++ /dev/null
@@ -1,194 +0,0 @@
-setTranslator($translate);
- }
- }
-
- /**
- * Mock __invoke for manual call
- *
- * @see __invoke
- * @param string $messageid Id of the message to be translated
- * @return string|\Zend\View\Helper\Translator Translated message
- */
- public function translate($messageid = null)
- {
- $options = func_get_args();
- return call_user_func_array(array($this, '__invoke'), $options);
- }
-
- /**
- * Translate a message
- * You can give multiple params or an array of params.
- * If you want to output another locale just set it as last single parameter
- * Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale);
- * Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale);
- *
- * @param string $messageid Id of the message to be translated
- * @return string|\Zend\View\Helper\Translator Translated message
- */
- public function __invoke($messageid = null)
- {
- if ($messageid === null) {
- return $this;
- }
-
- $translator = $this->getTranslator();
- $options = func_get_args();
-
- array_shift($options);
- $count = count($options);
- $locale = null;
- if ($count > 0) {
- if (Locale::isLocale($options[($count - 1)]) !== false) {
- // Don't treat last option as the locale if doing so will result in an error
- if (is_array($options[0]) || @vsprintf($messageid, array_slice($options, 0, -1)) !== false) {
- $locale = array_pop($options);
- }
- }
- }
-
- if ((count($options) === 1) and (is_array($options[0]) === true)) {
- $options = $options[0];
- }
-
- if ($translator !== null) {
- $messageid = $translator->translate($messageid, $locale);
- }
-
- if (count($options) === 0) {
- return $messageid;
- }
-
- return vsprintf($messageid, $options);
- }
-
- /**
- * Sets a translation Adapter for translation
- *
- * @param Translation|TranslationAdapter $translator
- * @return Translator
- * @throws Exception\InvalidArgumentException When no or a false instance was set
- */
- public function setTranslator($translator)
- {
- if ($translator instanceof TranslationAdapter) {
- $this->translator = $translator;
- } else if ($translator instanceof Translation) {
- $this->translator = $translator->getAdapter();
- } else {
- throw new Exception\InvalidArgumentException(
- 'You must set an instance of Zend\Translator\Translator or Zend\Translator\Adapter'
- );
- }
-
- return $this;
- }
-
- /**
- * Retrieve translation object
- *
- * @return TranslationAdapter|null
- */
- public function getTranslator()
- {
- if ($this->translator === null) {
- if (Registry::isRegistered('Zend_Translator')) {
- $this->setTranslator(Registry::get('Zend_Translator'));
- }
- }
-
- return $this->translator;
- }
-
- /**
- * Set's a new locale for all further translations
- *
- * @param string|Locale $locale New locale to set
- * @return Translator
- * @throws Exception\RuntimeException When no Translation instance was set
- */
- public function setLocale($locale = null)
- {
- $translator = $this->getTranslator();
- if ($translator === null) {
- throw new Exception\RuntimeException(
- 'You must set an instance of Zend\Translator\Translator or Zend\Translator\Adapter'
- );
- }
-
- $translator->setLocale($locale);
- return $this;
- }
-
- /**
- * Returns the set locale for translations
- *
- * @return string|Locale
- * @throws Exception\RuntimeException When no Translation instance was set
- */
- public function getLocale()
- {
- $translator = $this->getTranslator();
- if ($translator === null) {
- throw new Exception\RuntimeException(
- 'You must set an instance of Zend\Translator\Translator or Zend\Translator\Adapter'
- );
- }
-
- return $translator->getLocale();
- }
-}
diff --git a/src/Helper/Url.php b/src/Helper/Url.php
index 067b1a33..9fbea29d 100644
--- a/src/Helper/Url.php
+++ b/src/Helper/Url.php
@@ -1,57 +1,45 @@
router = $router;
return $this;
}
-
+
/**
* Set route match returned by the router.
- *
+ *
* @param RouteMatch $routeMatch
* @return self
*/
@@ -96,18 +84,24 @@ public function __invoke($name = null, array $params = array(), array $options =
if ($this->routeMatch === null) {
throw new Exception\RuntimeException('No RouteMatch instance provided');
}
-
+
$name = $this->routeMatch->getMatchedRouteName();
-
+
if ($name === null) {
throw new Exception\RuntimeException('RouteMatch does not contain a matched route name');
}
}
-
+
if ($reuseMatchedParams && $this->routeMatch !== null) {
- $params = array_merge($this->routeMatch->getParams(), $params);
+ $routeMatchParams = $this->routeMatch->getParams();
+
+ if (isset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
+ $routeMatchParams['controller'] = $routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
+ }
+
+ $params = array_merge($routeMatchParams, $params);
}
-
+
$options['name'] = $name;
return $this->router->assemble($params, $options);
diff --git a/src/Helper/ViewModel.php b/src/Helper/ViewModel.php
index d76564c9..a73cc28f 100644
--- a/src/Helper/ViewModel.php
+++ b/src/Helper/ViewModel.php
@@ -1,22 +1,11 @@
'Zend\View\Helper\Doctype', // overridden by a factory in ViewHelperManagerFactory
'basepath' => 'Zend\View\Helper\BasePath',
- 'currency' => 'Zend\View\Helper\Currency',
+ 'url' => 'Zend\View\Helper\Url',
'cycle' => 'Zend\View\Helper\Cycle',
'declarevars' => 'Zend\View\Helper\DeclareVars',
- 'doctype' => 'Zend\View\Helper\Doctype',
- 'escape' => 'Zend\View\Helper\Escape',
+ 'escapehtml' => 'Zend\View\Helper\EscapeHtml',
+ 'escapehtmlattr' => 'Zend\View\Helper\EscapeHtmlAttr',
+ 'escapejs' => 'Zend\View\Helper\EscapeJs',
+ 'escapecss' => 'Zend\View\Helper\EscapeCss',
+ 'escapeurl' => 'Zend\View\Helper\EscapeUrl',
'gravatar' => 'Zend\View\Helper\Gravatar',
'headlink' => 'Zend\View\Helper\HeadLink',
'headmeta' => 'Zend\View\Helper\HeadMeta',
@@ -63,7 +60,6 @@ class HelperPluginManager extends AbstractPluginManager
'inlinescript' => 'Zend\View\Helper\InlineScript',
'json' => 'Zend\View\Helper\Json',
'layout' => 'Zend\View\Helper\Layout',
- 'navigation' => 'Zend\View\Helper\Navigation',
'paginationcontrol' => 'Zend\View\Helper\PaginationControl',
'partialloop' => 'Zend\View\Helper\PartialLoop',
'partial' => 'Zend\View\Helper\Partial',
@@ -71,8 +67,6 @@ class HelperPluginManager extends AbstractPluginManager
'renderchildmodel' => 'Zend\View\Helper\RenderChildModel',
'rendertoplaceholder' => 'Zend\View\Helper\RenderToPlaceholder',
'serverurl' => 'Zend\View\Helper\ServerUrl',
- 'translator' => 'Zend\View\Helper\Translator',
- 'url' => 'Zend\View\Helper\Url',
'viewmodel' => 'Zend\View\Helper\ViewModel',
);
@@ -85,21 +79,22 @@ class HelperPluginManager extends AbstractPluginManager
* Constructor
*
* After invoking parent constructor, add an initializer to inject the
- * attached renderer, if any, to the currently requested helper.
- *
- * @param null|ConfigurationInterface $configuration
+ * attached renderer and translator, if any, to the currently requested helper.
+ *
+ * @param null|ConfigInterface $configuration
* @return void
*/
- public function __construct(ConfigurationInterface $configuration = null)
+ public function __construct(ConfigInterface $configuration = null)
{
parent::__construct($configuration);
- $this->addInitializer(array($this, 'injectRenderer'));
+ $this->addInitializer(array($this, 'injectRenderer'))
+ ->addInitializer(array($this, 'injectTranslator'));
}
/**
* Set renderer
- *
- * @param Renderer\RendererInterface $renderer
+ *
+ * @param Renderer\RendererInterface $renderer
* @return HelperPluginManager
*/
public function setRenderer(Renderer\RendererInterface $renderer)
@@ -110,7 +105,7 @@ public function setRenderer(Renderer\RendererInterface $renderer)
/**
* Retrieve renderer instance
- *
+ *
* @return null|Renderer\RendererInterface
*/
public function getRenderer()
@@ -121,24 +116,40 @@ public function getRenderer()
/**
* Inject a helper instance with the registered renderer
*
- * @param Helper\HelperInterface $helper
+ * @param Helper\HelperInterface $helper
* @return void
*/
public function injectRenderer($helper)
{
$renderer = $this->getRenderer();
- if (null === $renderer) {
+ if (null === $renderer) {
return;
}
$helper->setView($renderer);
}
+ /**
+ * Inject a helper instance with the registered translator
+ *
+ * @param Helper\HelperInterface $helper
+ * @return void
+ */
+ public function injectTranslator($helper)
+ {
+ if ($helper instanceof TranslatorAwareInterface) {
+ $locator = $this->getServiceLocator();
+ if ($locator && $locator->has('translator')) {
+ $helper->setTranslator($locator->get('translator'));
+ }
+ }
+ }
+
/**
* Validate the plugin
*
* Checks that the helper loaded is an instance of Helper\HelperInterface.
- *
- * @param mixed $plugin
+ *
+ * @param mixed $plugin
* @return void
* @throws Exception\InvalidHelperException if invalid
*/
diff --git a/src/Model/ConsoleModel.php b/src/Model/ConsoleModel.php
new file mode 100644
index 00000000..217d3476
--- /dev/null
+++ b/src/Model/ConsoleModel.php
@@ -0,0 +1,91 @@
+options['errorLevel'] = $errorLevel;
+ }
+
+ /**
+ * @return int
+ */
+ public function getErrorLevel()
+ {
+ if(array_key_exists('errorLevel', $this->options)){
+ return $this->options['errorLevel'];
+ }
+ }
+
+ /**
+ * Set result text.
+ *
+ * @param string $text
+ * @return \Zend\View\Model\ConsoleModel
+ */
+ public function setResult($text){
+ $this->setVariable(self::RESULT, $text);
+ return $this;
+ }
+
+ /**
+ * Get result text.
+ *
+ * @return mixed
+ */
+ public function getResult(){
+ return $this->getVariable(self::RESULT);
+ }
+}
diff --git a/src/Model/FeedModel.php b/src/Model/FeedModel.php
index 3fe5d8f4..650ffc6b 100644
--- a/src/Model/FeedModel.php
+++ b/src/Model/FeedModel.php
@@ -1,28 +1,17 @@
feed instanceof Feed) {
@@ -67,8 +64,8 @@ public function getFeed()
/**
* Set the feed object
- *
- * @param Feed $feed
+ *
+ * @param Feed $feed
* @return FeedModel
*/
public function setFeed(Feed $feed)
@@ -79,7 +76,7 @@ public function setFeed(Feed $feed)
/**
* Get the feed type
- *
+ *
* @return false|string
*/
public function getFeedType()
diff --git a/src/Model/JsonModel.php b/src/Model/JsonModel.php
index b2b81ab6..b22c431b 100644
--- a/src/Model/JsonModel.php
+++ b/src/Model/JsonModel.php
@@ -1,65 +1,52 @@
jsonpCallback))
- {
+ if(!is_null($this->jsonpCallback)) {
return $this->jsonpCallback.'('.Json::encode($variables).');';
} else {
return Json::encode($variables);
diff --git a/src/Model/ModelInterface.php b/src/Model/ModelInterface.php
index 1d3c9f5f..99548c63 100644
--- a/src/Model/ModelInterface.php
+++ b/src/Model/ModelInterface.php
@@ -1,28 +1,17 @@
getVariables();
- $variables[$name] = $value;
+ $this->setVariable($name, $value);
}
/**
* Property overloading: get variable value
- *
- * @param string $name
+ *
+ * @param string $name
* @return mixed
*/
public function __get($name)
@@ -127,8 +121,8 @@ public function __get($name)
/**
* Property overloading: do we have the requested variable value?
- *
- * @param string $name
+ *
+ * @param string $name
* @return bool
*/
public function __isset($name)
@@ -139,8 +133,8 @@ public function __isset($name)
/**
* Property overloading: unset the requested variable
- *
- * @param string $name
+ *
+ * @param string $name
* @return void
*/
public function __unset($name)
@@ -154,10 +148,10 @@ public function __unset($name)
}
/**
- * Set renderer option/hint
- *
- * @param string $name
- * @param mixed $value
+ * Set a single option
+ *
+ * @param string $name
+ * @param mixed $value
* @return ViewModel
*/
public function setOption($name, $value)
@@ -166,10 +160,24 @@ public function setOption($name, $value)
return $this;
}
+ /**
+ * Get a single option
+ *
+ * @param string $name The option to get.
+ * @param mixed|null $default (optional) A default value if the option is not yet set.
+ * @return mixed
+ */
+ public function getOption($name, $default = null)
+ {
+ $name = (string)$name;
+ return array_key_exists($name, $this->options) ? $this->options[$name] : $default;
+ }
+
/**
* Set renderer options/hints en masse
- *
- * @param array|Traversable $name
+ *
+ * @param array|\Traversable $options
+ * @throws \Zend\View\Exception\InvalidArgumentException
* @return ViewModel
*/
public function setOptions($options)
@@ -194,19 +202,36 @@ public function setOptions($options)
/**
* Get renderer options/hints
- *
+ *
* @return array
*/
public function getOptions()
{
return $this->options;
}
-
+
+ /**
+ * Get a single view variable
+ *
+ * @param string $name
+ * @param mixed|null $default (optional) default value if the variable is not present.
+ * @return mixed
+ */
+ public function getVariable($name, $default = null)
+ {
+ $name = (string)$name;
+ if(array_key_exists($name,$this->variables)){
+ return $this->variables[$name];
+ }else{
+ return $default;
+ }
+ }
+
/**
* Set view variable
- *
- * @param string $name
- * @param mixed $value
+ *
+ * @param string $name
+ * @param mixed $value
* @return ViewModel
*/
public function setVariable($name, $value)
@@ -219,8 +244,8 @@ public function setVariable($name, $value)
* Set view variables en masse
*
* Can be an array or a Traversable + ArrayAccess object.
- *
- * @param array|ArrayAccess&Traversable $variables
+ *
+ * @param array|ArrayAccess&Traversable $variables
* @return ViewModel
*/
public function setVariables($variables)
@@ -249,7 +274,7 @@ public function setVariables($variables)
/**
* Get view variables
- *
+ *
* @return array|ArrayAccess|Traversable
*/
public function getVariables()
@@ -258,8 +283,8 @@ public function getVariables()
}
/**
- * Set the template to be used by this model
- *
+ * Set the template to be used by this model
+ *
* @param string $template
* @return ViewModel
*/
@@ -271,7 +296,7 @@ public function setTemplate($template)
/**
* Get the template to be used by this model
- *
+ *
* @return string
*/
public function getTemplate()
@@ -281,17 +306,22 @@ public function getTemplate()
/**
* Add a child model
- *
+ *
* @param ModelInterface $child
* @param null|string $captureTo Optional; if specified, the "capture to" value to set on the child
+ * @param null|bool $append Optional; if specified, append to child with the same capture
* @return ViewModel
*/
- public function addChild(ModelInterface $child, $captureTo = null)
+ public function addChild(ModelInterface $child, $captureTo = null, $append = null)
{
$this->children[] = $child;
if (null !== $captureTo) {
$child->setCaptureTo($captureTo);
}
+ if (null !== $captureTo) {
+ $child->setAppend($append);
+ }
+
return $this;
}
@@ -308,8 +338,8 @@ public function getChildren()
}
/**
- * Does the model have any children?
- *
+ * Does the model have any children?
+ *
* @return bool
*/
public function hasChildren()
@@ -319,8 +349,8 @@ public function hasChildren()
/**
* Set the name of the variable to capture this model to, if it is a child model
- *
- * @param string $capture
+ *
+ * @param string $capture
* @return ViewModel
*/
public function setCaptureTo($capture)
@@ -331,7 +361,7 @@ public function setCaptureTo($capture)
/**
* Get the name of the variable to which to capture this model
- *
+ *
* @return string
*/
public function captureTo()
@@ -341,8 +371,8 @@ public function captureTo()
/**
* Set flag indicating whether or not this is considered a terminal or standalone model
- *
- * @param bool $terminate
+ *
+ * @param bool $terminate
* @return ViewModel
*/
public function setTerminal($terminate)
@@ -353,7 +383,7 @@ public function setTerminal($terminate)
/**
* Is this considered a terminal or standalone model?
- *
+ *
* @return bool
*/
public function terminate()
@@ -361,9 +391,31 @@ public function terminate()
return $this->terminate;
}
+ /**
+ * Set flag indicating whether or not append to child with the same capture
+ *
+ * @param bool $append
+ * @return ViewModel
+ */
+ public function setAppend($append)
+ {
+ $this->append = (bool) $append;
+ return $this;
+ }
+
+ /**
+ * Is this append to child with the same capture?
+ *
+ * @return bool
+ */
+ public function isAppend()
+ {
+ return $this->append;
+ }
+
/**
* Return count of children
- *
+ *
* @return int
*/
public function count()
@@ -373,7 +425,7 @@ public function count()
/**
* Get iterator of children
- *
+ *
* @return ArrayIterator
*/
public function getIterator()
diff --git a/src/Renderer/ConsoleRenderer.php b/src/Renderer/ConsoleRenderer.php
new file mode 100644
index 00000000..c11f042b
--- /dev/null
+++ b/src/Renderer/ConsoleRenderer.php
@@ -0,0 +1,174 @@
+init();
+ }
+
+ public function setResolver(Resolver $resolver){}
+
+ /**
+ * Return the template engine object
+ *
+ * Returns the object instance, as it is its own template engine
+ *
+ * @return PhpRenderer
+ */
+ public function getEngine()
+ {
+ return $this;
+ }
+
+ /**
+ * Allow custom object initialization when extending Zend_View_Abstract or
+ * Zend_View
+ *
+ * Triggered by {@link __construct() the constructor} as its final action.
+ *
+ * @return void
+ */
+ public function init()
+ {
+ }
+
+ /**
+ * Set filter chain
+ *
+ * @param FilterChain $filters
+ * @return Zend\View\PhpRenderer
+ */
+ public function setFilterChain(FilterChain $filters)
+ {
+ $this->__filterChain = $filters;
+ return $this;
+ }
+
+ /**
+ * Retrieve filter chain for post-filtering script content
+ *
+ * @return FilterChain
+ */
+ public function getFilterChain()
+ {
+ if (null === $this->__filterChain) {
+ $this->setFilterChain(new FilterChain());
+ }
+ return $this->__filterChain;
+ }
+
+ /**
+ * Recursively processes all ViewModels and returns output.
+ *
+ * @param string|Model $model A ViewModel instance.
+ * @param null|array|Traversable $values Values to use when rendering. If none
+ * provided, uses those in the composed
+ * variables container.
+ * @return string Console output.
+ */
+ public function render($model, $values = null)
+ {
+ if(!$model instanceof Model){
+ return '';
+ }
+
+ $result = '';
+ $options = $model->getOptions();
+ foreach ($options as $setting => $value) {
+ $method = 'set' . $setting;
+ if (method_exists($this, $method)) {
+ $this->$method($value);
+ }
+ unset($method, $setting, $value);
+ }
+ unset($options);
+
+ $values = $model->getVariables();
+
+ if(isset($values['result'])){
+ // filter and append the result
+ $result .= $this->getFilterChain()->filter($values['result']);
+ }
+
+ if($model->hasChildren()){
+ // recursively render all children
+ foreach($model->getChildren() as $child){
+ $result .= $this->render($child, $values);
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * @see Zend\View\Renderer\TreeRendererInterface
+ * @return bool
+ */
+ public function canRenderTrees()
+ {
+ return true;
+ }
+
+}
diff --git a/src/Renderer/FeedRenderer.php b/src/Renderer/FeedRenderer.php
index 3195597c..f4f36256 100644
--- a/src/Renderer/FeedRenderer.php
+++ b/src/Renderer/FeedRenderer.php
@@ -1,30 +1,19 @@
feedType = $feedType;
return $this;
}
-
+
/**
* Get feed type
*
diff --git a/src/Renderer/JsonRenderer.php b/src/Renderer/JsonRenderer.php
index 850c6b33..97a91f54 100644
--- a/src/Renderer/JsonRenderer.php
+++ b/src/Renderer/JsonRenderer.php
@@ -1,35 +1,24 @@
hasChildren()) {
return $values;
}
@@ -224,6 +211,7 @@ protected function recurseModel(Model $model)
$childValues = $this->recurseModel($child);
if ($captureTo) {
// Capturing to a specific key
+ //TODO please complete if append is true. must change old value to array and append to array?
$values[$captureTo] = $childValues;
} elseif ($mergeChildren) {
// Merging values with parent
diff --git a/src/Renderer/PhpRenderer.php b/src/Renderer/PhpRenderer.php
index bc764dcb..140fd81a 100644
--- a/src/Renderer/PhpRenderer.php
+++ b/src/Renderer/PhpRenderer.php
@@ -1,46 +1,34 @@
__helpers;
}
-
+
/**
* Get plugin instance
- *
+ *
* @param string $plugin Name of plugin to return
* @param null|array $options Options to pass to plugin constructor (if not already instantiated)
* @return Helper
@@ -351,9 +339,9 @@ public function plugin($name, array $options = null)
*
* * If the helper does not define __invoke, it will be returned
* * If the helper does define __invoke, it will be called as a functor
- *
- * @param string $method
- * @param array $argv
+ *
+ * @param string $method
+ * @param array $argv
* @return mixed
*/
public function __call($method, $argv)
@@ -367,8 +355,8 @@ public function __call($method, $argv)
/**
* Set filter chain
- *
- * @param FilterChain $filters
+ *
+ * @param FilterChain $filters
* @return PhpRenderer
*/
public function setFilterChain(FilterChain $filters)
@@ -379,7 +367,7 @@ public function setFilterChain(FilterChain $filters)
/**
* Retrieve filter chain for post-filtering script content
- *
+ *
* @return FilterChain
*/
public function getFilterChain()
@@ -393,12 +381,12 @@ public function getFilterChain()
/**
* Processes a view script and returns the output.
*
- * @param string|Model $nameOrModel Either the template to use, or a
- * ViewModel. The ViewModel must have the
- * template as an option in order to be
+ * @param string|Model $nameOrModel Either the template to use, or a
+ * ViewModel. The ViewModel must have the
+ * template as an option in order to be
* valid.
- * @param null|array|Traversable Values to use when rendering. If none
- * provided, uses those in the composed
+ * @param null|array|Traversable Values to use when rendering. If none
+ * provided, uses those in the composed
* variables container.
* @return string The script output.
* @throws Exception\DomainException if a ViewModel is passed, but does not
@@ -477,12 +465,12 @@ public function render($nameOrModel, $values = null)
/**
* Set flag indicating whether or not we should render trees of view models
*
- * If set to true, the View instance will not attempt to render children
+ * If set to true, the View instance will not attempt to render children
* separately, but instead pass the root view model directly to the PhpRenderer.
- * It is then up to the developer to render the children from within the
+ * It is then up to the developer to render the children from within the
* view script.
- *
- * @param bool $renderTrees
+ *
+ * @param bool $renderTrees
* @return PhpRenderer
*/
public function setCanRenderTrees($renderTrees)
@@ -493,7 +481,7 @@ public function setCanRenderTrees($renderTrees)
/**
* Can we render trees, or are we configured to do so?
- *
+ *
* @return bool
*/
public function canRenderTrees()
@@ -503,8 +491,8 @@ public function canRenderTrees()
/**
* Add a template to the stack
- *
- * @param string $template
+ *
+ * @param string $template
* @return PhpRenderer
*/
public function addTemplate($template)
diff --git a/src/Renderer/RendererInterface.php b/src/Renderer/RendererInterface.php
index 6212ea23..c97355b5 100644
--- a/src/Renderer/RendererInterface.php
+++ b/src/Renderer/RendererInterface.php
@@ -1,36 +1,23 @@
path pairs
- *
- * @param array|Traversable $map
+ *
+ * @param array|Traversable $map
* @return TemplateMapResolver
*/
public function setMap($map)
@@ -93,9 +80,9 @@ public function setMap($map)
/**
* Add an entry to the map
- *
- * @param string|array|Traversable $nameOrMap
- * @param null|string $path
+ *
+ * @param string|array|Traversable $nameOrMap
+ * @param null|string $path
* @return TemplateResolver
*/
public function add($nameOrMap, $path = null)
@@ -126,8 +113,8 @@ public function add($nameOrMap, $path = null)
/**
* Merge internal map with provided map
- *
- * @param array|Traversable $map
+ *
+ * @param array|Traversable $map
* @return TemplateMapResolver
*/
public function merge($map)
@@ -150,8 +137,8 @@ public function merge($map)
/**
* Does the resolver contain an entry for the given name?
- *
- * @param string $name
+ *
+ * @param string $name
* @return bool
*/
public function has($name)
@@ -161,8 +148,8 @@ public function has($name)
/**
* Retrieve a template path by name
- *
- * @param string $name
+ *
+ * @param string $name
* @return false|string
* @throws Exception\DomainException if no entry exists
*/
@@ -176,7 +163,7 @@ public function get($name)
/**
* Retrieve the template map
- *
+ *
* @return array
*/
public function getMap()
@@ -186,9 +173,9 @@ public function getMap()
/**
* Resolve a template/pattern name to a resource the renderer can consume
- *
- * @param string $name
- * @param null|Renderer $renderer
+ *
+ * @param string $name
+ * @param null|Renderer $renderer
* @return string
*/
public function resolve($name, Renderer $renderer = null)
diff --git a/src/Resolver/TemplatePathStack.php b/src/Resolver/TemplatePathStack.php
index 7551458f..ae2a601c 100644
--- a/src/Resolver/TemplatePathStack.php
+++ b/src/Resolver/TemplatePathStack.php
@@ -1,30 +1,19 @@
defaultSuffix = ltrim($this->defaultSuffix, '.');
return $this;
}
-
+
/**
* Get default file suffix
*
@@ -328,7 +315,7 @@ public function resolve($name, Renderer $renderer = null)
if (!file_exists($filePath)) {
break;
}
- }
+ }
if ($this->useStreamWrapper()) {
// If using a stream wrapper, prepend the spec to the path
$filePath = 'zend.view://' . $filePath;
@@ -343,7 +330,7 @@ public function resolve($name, Renderer $renderer = null)
/**
* Get the last lookup failure message, if any
- *
+ *
* @return false|string
*/
public function getLastLookupFailure()
diff --git a/src/Strategy/FeedStrategy.php b/src/Strategy/FeedStrategy.php
index 877e43ad..cca82db2 100644
--- a/src/Strategy/FeedStrategy.php
+++ b/src/Strategy/FeedStrategy.php
@@ -1,41 +1,28 @@
headers();
- if ($headers->has('accept')) {
- $accept = $headers->get('accept');
- foreach ($accept->getPrioritized() as $mediaType) {
- if (0 === strpos($mediaType, 'application/rss+xml')) {
- // application/rss+xml Accept header found
- $this->renderer->setFeedType('rss');
- return $this->renderer;
- }
- if (0 === strpos($mediaType, 'application/atom+xml')) {
- // application/atom+xml Accept header found
- $this->renderer->setFeedType('atom');
- return $this->renderer;
- }
- }
+ $headers = $request->getHeaders();
+ if (!$headers->has('accept')) {
+ return;
+ }
+
+ $accept = $headers->get('accept');
+ if (($match = $accept->match('application/rss+xml, application/atom+xml')) == false) {
+ return;
+ }
+
+ if ($match->getTypeString() == 'application/rss+xml') {
+ $this->renderer->setFeedType('rss');
+ return $this->renderer;
+ }
+
+ if ($match->getTypeString() == 'application/atom+xml') {
+ $this->renderer->setFeedType('atom');
+ return $this->renderer;
}
- // Not matched!
- return;
}
/**
@@ -162,10 +150,20 @@ public function injectResponse(ViewEvent $e)
? 'application/rss+xml'
: 'application/atom+xml';
+ $model = $e->getModel();
+ $charset = '';
+
+ if ($model instanceof Model\FeedModel) {
+
+ $feed = $model->getFeed();
+
+ $charset = '; charset=' . $feed->getEncoding() . ';';
+ }
+
// Populate response
$response = $e->getResponse();
$response->setContent($result);
- $headers = $response->headers();
- $headers->addHeaderLine('content-type', $feedType);
+ $headers = $response->getHeaders();
+ $headers->addHeaderLine('content-type', $feedType . $charset);
}
}
diff --git a/src/Strategy/JsonStrategy.php b/src/Strategy/JsonStrategy.php
index aedce678..dfa2dab0 100644
--- a/src/Strategy/JsonStrategy.php
+++ b/src/Strategy/JsonStrategy.php
@@ -1,40 +1,27 @@
headers();
- if ($headers->has('accept')) {
- $accept = $headers->get('Accept');
- foreach ($accept->getPrioritized() as $mediaType) {
- if (0 === strpos($mediaType, 'application/json')) {
- // application/json Accept header found
- return $this->renderer;
- }
- if (0 === strpos($mediaType, 'application/javascript')) {
- // application/javascript Accept header found
- if (false != ($callback = $request->query()->get('callback'))) {
- $this->renderer->setJsonpCallback($callback);
- }
- return $this->renderer;
- }
- }
+ $headers = $request->getHeaders();
+ if (!$headers->has('accept')) {
+ return;
}
- // Not matched!
- return;
+
+ $accept = $headers->get('Accept');
+ if (($match = $accept->match('application/json, application/javascript')) == false) {
+ return;
+ }
+
+ if ($match->getTypeString() == 'application/json') {
+ // application/json Accept header found
+ return $this->renderer;
+ }
+
+ if ($match->getTypeString() == 'application/javascript') {
+ // application/javascript Accept header found
+ if (false != ($callback = $request->getQuery()->get('callback'))) {
+ $this->renderer->setJsonpCallback($callback);
+ }
+ return $this->renderer;
+ }
}
/**
@@ -154,7 +144,7 @@ public function injectResponse(ViewEvent $e)
// Populate response
$response = $e->getResponse();
$response->setContent($result);
- $headers = $response->headers();
+ $headers = $response->getHeaders();
if ($this->renderer->hasJsonpCallback()) {
$headers->addHeaderLine('content-type', 'application/javascript');
} else {
diff --git a/src/Strategy/PhpRendererStrategy.php b/src/Strategy/PhpRendererStrategy.php
index 72ccb84f..95b11bf9 100644
--- a/src/Strategy/PhpRendererStrategy.php
+++ b/src/Strategy/PhpRendererStrategy.php
@@ -1,39 +1,26 @@
to long-form and ?> to
+ * Convert = ?> to long-form and to
*
*/
$this->_data = preg_replace('/\<\?\=/', "_data);
diff --git a/src/Variables.php b/src/Variables.php
index 260f6bb4..e367b449 100644
--- a/src/Variables.php
+++ b/src/Variables.php
@@ -1,21 +1,11 @@
events instanceof EventManagerInterface) {
$this->setEventManager(new EventManager());
@@ -143,7 +131,7 @@ public function events()
*/
public function addRenderingStrategy($callable, $priority = 1)
{
- $this->events()->attach(ViewEvent::EVENT_RENDERER, $callable, $priority);
+ $this->getEventManager()->attach(ViewEvent::EVENT_RENDERER, $callable, $priority);
return $this;
}
@@ -164,7 +152,7 @@ public function addRenderingStrategy($callable, $priority = 1)
*/
public function addResponseStrategy($callable, $priority = 1)
{
- $this->events()->attach(ViewEvent::EVENT_RESPONSE, $callable, $priority);
+ $this->getEventManager()->attach(ViewEvent::EVENT_RESPONSE, $callable, $priority);
return $this;
}
@@ -186,7 +174,7 @@ public function render(Model $model)
{
$event = $this->getEvent();
$event->setModel($model);
- $events = $this->events();
+ $events = $this->getEventManager();
$results = $events->trigger(ViewEvent::EVENT_RENDERER, $event, function($result) {
return ($result instanceof Renderer);
});
@@ -243,7 +231,12 @@ protected function renderChildren(Model $model)
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
- $model->setVariable($capture, $result);
+ if($child->isAppend()) {
+ $oldResult=$model->{$capture};
+ $model->setVariable($capture, $oldResult.$result);
+ } else {
+ $model->setVariable($capture, $result);
+ }
}
}
}
diff --git a/src/ViewEvent.php b/src/ViewEvent.php
index e11033c5..fbfcf3e7 100644
--- a/src/ViewEvent.php
+++ b/src/ViewEvent.php
@@ -1,37 +1,25 @@
helper = new ConcreteHelper();
+ }
+
+ public function testViewSettersGetters()
+ {
+ $viewMock = $this->getMock('Zend\View\Renderer\RendererInterface');
+
+ $this->helper->setView($viewMock);
+ $this->assertEquals($viewMock, $this->helper->getView());
+ }
+}
diff --git a/test/Helper/BasePathTest.php b/test/Helper/BasePathTest.php
index bf92a6bc..29cbd840 100644
--- a/test/Helper/BasePathTest.php
+++ b/test/Helper/BasePathTest.php
@@ -1,35 +1,22 @@
setBasePath('/foo');
-
+
$this->assertEquals('/foo', $helper());
}
-
+
public function testBasePathWithFile()
{
$helper = new BasePath();
$helper->setBasePath('/foo');
-
+
$this->assertEquals('/foo/bar', $helper('bar'));
}
-
+
public function testBasePathNoDoubleSlashes()
{
$helper = new BasePath();
@@ -63,7 +50,7 @@ public function testBasePathWithFilePrefixedBySlash()
{
$helper = new BasePath();
$helper->setBasePath('/foo');
-
+
$this->assertEquals('/foo/bar', $helper('/bar'));
}
}
diff --git a/test/Helper/CurrencyTest.php b/test/Helper/CurrencyTest.php
deleted file mode 100644
index bfc2eddd..00000000
--- a/test/Helper/CurrencyTest.php
+++ /dev/null
@@ -1,172 +0,0 @@
-clearRegistry();
-
- $cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
- Currency\Currency::setCache($cache);
-
- $this->helper = new Helper\Currency('de_AT');
- }
-
- /**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- *
- * @return void
- */
- public function tearDown()
- {
- unset($this->helper);
- $this->clearRegistry();
- }
-
- public function testCurrencyObjectPassedToConstructor()
- {
- $curr = new Currency\Currency('de_AT');
-
- $helper = new Helper\Currency($curr);
- $this->assertEquals('€ 1.234,56', $helper->__invoke(1234.56));
- $this->assertEquals('€ 0,12', $helper->__invoke(0.123));
- }
-
- public function testLocalCurrencyObjectUsedWhenPresent()
- {
- $curr = new Currency\Currency('de_AT');
-
- $this->helper->setCurrency($curr);
- $this->assertEquals('€ 1.234,56', $this->helper->__invoke(1234.56));
- $this->assertEquals('€ 0,12', $this->helper->__invoke(0.123));
- }
-
- public function testCurrencyObjectInRegistryUsedInAbsenceOfLocalCurrencyObject()
- {
- $curr = new Currency\Currency('de_AT');
- \Zend\Registry::set('Zend_Currency', $curr);
- $this->assertEquals('€ 1.234,56', $this->helper->__invoke(1234.56));
- }
-
- public function testPassingNonNullNonCurrencyObjectToConstructorThrowsException()
- {
- try {
- $helper = new Helper\Currency('something');
- } catch (\Exception $e) {
- if (substr($e->getMessage(), 0, 15) == 'No region found') {
- $this->assertContains('within the locale', $e->getMessage());
- } else {
- $this->assertContains('not found', $e->getMessage());
- }
- }
- }
-
- public function testPassingNonCurrencyObjectToSetCurrencyThrowsException()
- {
- try {
- $this->helper->setCurrency('something');
- } catch (\Exception $e) {
- if (substr($e->getMessage(), 0, 15) == 'No region found') {
- $this->assertContains('within the locale', $e->getMessage());
- } else {
- $this->assertContains('not found', $e->getMessage());
- }
- }
- }
-
- public function testCanOutputCurrencyWithOptions()
- {
- $curr = new Currency\Currency('de_AT');
-
- $this->helper->setCurrency($curr);
- $this->assertEquals("€ 1.234,56", $this->helper->__invoke(1234.56, "de_AT"));
- }
-
- public function testCurrencyObjectNullByDefault()
- {
- $this->assertNotNull($this->helper->getCurrency());
- }
-
- public function testLocalCurrencyObjectIsPreferredOverRegistry()
- {
- $currReg = new Currency\Currency('de_AT');
- \Zend\Registry::set('Zend_Currency', $currReg);
-
- $this->helper = new Helper\Currency();
- $this->assertSame($currReg, $this->helper->getCurrency());
-
- $currLoc = new Currency\Currency('en_US');
- $this->helper->setCurrency($currLoc);
- $this->assertSame($currLoc, $this->helper->getCurrency());
- $this->assertNotSame($currLoc, $currReg);
- }
-
- public function testHelperObjectReturnedWhenNoArgumentsPassed()
- {
- $helper = $this->helper->__invoke();
- $this->assertSame($this->helper, $helper);
-
- $currLoc = new Currency\Currency('de_AT');
- $this->helper->setCurrency($currLoc);
- $helper = $this->helper->__invoke();
- $this->assertSame($this->helper, $helper);
- }
-}
diff --git a/test/Helper/CycleTest.php b/test/Helper/CycleTest.php
index 96215f02..465689a0 100644
--- a/test/Helper/CycleTest.php
+++ b/test/Helper/CycleTest.php
@@ -1,25 +1,15 @@
helper = new Helper\Doctype();
}
@@ -72,16 +56,6 @@ public function tearDown()
unset($this->helper);
}
- public function testRegistryEntryCreatedAfterInstantiation()
- {
- $this->assertTrue(\Zend\Registry::isRegistered('Zend_View_Helper_Doctype'));
- $doctype = \Zend\Registry::get('Zend_View_Helper_Doctype');
- $this->assertTrue($doctype instanceof \ArrayObject);
- $this->assertTrue(isset($doctype['doctype']));
- $this->assertTrue(isset($doctype['doctypes']));
- $this->assertTrue(is_array($doctype['doctypes']));
- }
-
public function testDoctypeMethodReturnsObjectInstance()
{
$doctype = $this->helper->__invoke();
@@ -101,6 +75,7 @@ public function testIsXhtmlReturnsTrueForXhtmlDoctypes()
Helper\Doctype::XHTML1_TRANSITIONAL,
Helper\Doctype::XHTML1_FRAMESET,
Helper\Doctype::XHTML1_RDFA,
+ Helper\Doctype::XHTML1_RDFA11,
Helper\Doctype::XHTML5
);
@@ -165,6 +140,7 @@ public function testIsRdfa()
$this->assertFalse($this->helper->isRdfa());
$this->assertTrue($this->helper->__invoke(Helper\Doctype::XHTML1_RDFA)->isRdfa());
+ $this->assertTrue($this->helper->__invoke(Helper\Doctype::XHTML1_RDFA11)->isRdfa());
// build-in doctypes
$doctypes = array(
@@ -189,7 +165,8 @@ public function testIsRdfa()
$this->assertFalse($doctype->isRdfa());
}
- public function testCanRegisterCustomHtml5Doctype() {
+ public function testCanRegisterCustomHtml5Doctype()
+ {
$doctype = $this->helper->__invoke('');
$this->assertEquals('CUSTOM', $doctype->getDoctype());
$this->assertTrue($doctype->isHtml5());
@@ -222,8 +199,7 @@ public function testStringificationReturnsDoctypeString()
{
$doctype = $this->helper->__invoke(Helper\Doctype::XHTML1_STRICT);
$string = $doctype->__toString();
- $registry = \Zend\Registry::get('Zend_View_Helper_Doctype');
- $this->assertEquals($registry['doctypes'][Helper\Doctype::XHTML1_STRICT], $string);
+ $this->assertEquals('', $string);
}
}
diff --git a/test/Helper/EscapeCssTest.php b/test/Helper/EscapeCssTest.php
new file mode 100644
index 00000000..29014ac0
--- /dev/null
+++ b/test/Helper/EscapeCssTest.php
@@ -0,0 +1,203 @@
+helper = new EscapeHelper;
+ }
+
+ public function testUsesUtf8EncodingByDefault()
+ {
+ $this->assertEquals('UTF-8', $this->helper->getEncoding());
+ }
+
+ /**
+ * @expectedException \Zend\View\Exception\InvalidArgumentException
+ */
+ public function testEncodingIsImmutable()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $this->helper->getEscaper();
+ $this->helper->setEncoding('UTF-8');
+ }
+
+ public function testGetEscaperCreatesDefaultInstanceWithCorrectEncoding()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testSettingEscaperObjectAlsoSetsEncoding()
+ {
+ $escaper = new \Zend\Escaper\Escaper('big5-hkscs');
+ $this->helper->setEscaper($escaper);
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testEscapehtmlCalledOnEscaperObject()
+ {
+ $escaper = $this->getMock('\\Zend\\Escaper\\Escaper');
+ $escaper->expects($this->any())->method('escapeCss');
+ $this->helper->setEscaper($escaper);
+ $this->helper->__invoke('foo');
+ }
+
+ public function testAllowsRecursiveEscapingOfArrays()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $expected = array(
+ 'foo' => '\3C b\3E bar\3C \2F b\3E ',
+ 'baz' => array(
+ '\3C em\3E bat\3C \2F em\3E ',
+ 'second' => array(
+ '\3C i\3E third\3C \2F i\3E ',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($original, EscapeHelper::RECURSE_ARRAY);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testWillCastObjectsToStringsBeforeEscaping()
+ {
+ $object = new TestAsset\Stringified;
+ $test = $this->helper->__invoke($object);
+ $this->assertEquals(
+ 'ZendTest\5C View\5C Helper\5C TestAsset\5C Stringified',
+ $test
+ );
+ }
+
+ public function testCanRecurseObjectImplementingToArray()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new TestAsset\ToArray();
+ $object->array = $original;
+
+ $expected = array(
+ 'foo' => '\3C b\3E bar\3C \2F b\3E ',
+ 'baz' => array(
+ '\3C em\3E bat\3C \2F em\3E ',
+ 'second' => array(
+ '\3C i\3E third\3C \2F i\3E ',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testCanRecurseObjectProperties()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new stdClass();
+ foreach ($original as $key => $value) {
+ $object->$key = $value;
+ }
+
+ $expected = array(
+ 'foo' => '\3C b\3E bar\3C \2F b\3E ',
+ 'baz' => array(
+ '\3C em\3E bat\3C \2F em\3E ',
+ 'second' => array(
+ '\3C i\3E third\3C \2F i\3E ',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * PHP 5.3 instates default encoding on empty string instead of the expected
+ * warning level error for htmlspecialchars() encoding param. PHP 5.4 attempts
+ * to guess the encoding or take it from php.ini default_charset when an empty
+ * string is set. Both are insecure behaviours.
+ */
+ public function testSettingEncodingToEmptyStringShouldThrowException()
+ {
+ $this->helper->setEncoding('');
+ $this->helper->getEscaper();
+ }
+
+ public function testSettingValidEncodingShouldNotThrowExceptions()
+ {
+ foreach ($this->supportedEncodings as $value) {
+ $helper = new EscapeHelper;
+ $helper->setEncoding($value);
+ $helper->getEscaper();
+ }
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * All versions of PHP - when an invalid encoding is set on htmlspecialchars()
+ * a warning level error is issued and escaping continues with the default encoding
+ * for that PHP version. Preventing the continuation behaviour offsets display_errors
+ * off in production env.
+ */
+ public function testSettingEncodingToInvalidValueShouldThrowException()
+ {
+ $this->helper->setEncoding('completely-invalid');
+ $this->helper->getEscaper();
+ }
+}
diff --git a/test/Helper/EscapeHtmlAttrTest.php b/test/Helper/EscapeHtmlAttrTest.php
new file mode 100644
index 00000000..09f663f5
--- /dev/null
+++ b/test/Helper/EscapeHtmlAttrTest.php
@@ -0,0 +1,203 @@
+helper = new EscapeHelper;
+ }
+
+ public function testUsesUtf8EncodingByDefault()
+ {
+ $this->assertEquals('UTF-8', $this->helper->getEncoding());
+ }
+
+ /**
+ * @expectedException \Zend\View\Exception\InvalidArgumentException
+ */
+ public function testEncodingIsImmutable()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $this->helper->getEscaper();
+ $this->helper->setEncoding('UTF-8');
+ }
+
+ public function testGetEscaperCreatesDefaultInstanceWithCorrectEncoding()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testSettingEscaperObjectAlsoSetsEncoding()
+ {
+ $escaper = new \Zend\Escaper\Escaper('big5-hkscs');
+ $this->helper->setEscaper($escaper);
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testEscapehtmlCalledOnEscaperObject()
+ {
+ $escaper = $this->getMock('\\Zend\\Escaper\\Escaper');
+ $escaper->expects($this->any())->method('escapeHtmlAttr');
+ $this->helper->setEscaper($escaper);
+ $this->helper->__invoke('foo');
+ }
+
+ public function testAllowsRecursiveEscapingOfArrays()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $expected = array(
+ 'foo' => '<b>bar</b>',
+ 'baz' => array(
+ '<em>bat</em>',
+ 'second' => array(
+ '<i>third</i>',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($original, EscapeHelper::RECURSE_ARRAY);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testWillCastObjectsToStringsBeforeEscaping()
+ {
+ $object = new TestAsset\Stringified;
+ $test = $this->helper->__invoke($object);
+ $this->assertEquals(
+ 'ZendTest\View\Helper\TestAsset\Stringified',
+ $test
+ );
+ }
+
+ public function testCanRecurseObjectImplementingToArray()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new TestAsset\ToArray();
+ $object->array = $original;
+
+ $expected = array(
+ 'foo' => '<b>bar</b>',
+ 'baz' => array(
+ '<em>bat</em>',
+ 'second' => array(
+ '<i>third</i>',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testCanRecurseObjectProperties()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new stdClass();
+ foreach ($original as $key => $value) {
+ $object->$key = $value;
+ }
+
+ $expected = array(
+ 'foo' => '<b>bar</b>',
+ 'baz' => array(
+ '<em>bat</em>',
+ 'second' => array(
+ '<i>third</i>',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * PHP 5.3 instates default encoding on empty string instead of the expected
+ * warning level error for htmlspecialchars() encoding param. PHP 5.4 attempts
+ * to guess the encoding or take it from php.ini default_charset when an empty
+ * string is set. Both are insecure behaviours.
+ */
+ public function testSettingEncodingToEmptyStringShouldThrowException()
+ {
+ $this->helper->setEncoding('');
+ $this->helper->getEscaper();
+ }
+
+ public function testSettingValidEncodingShouldNotThrowExceptions()
+ {
+ foreach ($this->supportedEncodings as $value) {
+ $helper = new EscapeHelper;
+ $helper->setEncoding($value);
+ $helper->getEscaper();
+ }
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * All versions of PHP - when an invalid encoding is set on htmlspecialchars()
+ * a warning level error is issued and escaping continues with the default encoding
+ * for that PHP version. Preventing the continuation behaviour offsets display_errors
+ * off in production env.
+ */
+ public function testSettingEncodingToInvalidValueShouldThrowException()
+ {
+ $this->helper->setEncoding('completely-invalid');
+ $this->helper->getEscaper();
+ }
+}
diff --git a/test/Helper/EscapeTest.php b/test/Helper/EscapeHtmlTest.php
similarity index 71%
rename from test/Helper/EscapeTest.php
rename to test/Helper/EscapeHtmlTest.php
index a7a091e2..6a81493b 100644
--- a/test/Helper/EscapeTest.php
+++ b/test/Helper/EscapeHtmlTest.php
@@ -1,12 +1,20 @@
assertEquals('UTF-8', $this->helper->getEncoding());
}
- public function testEncodingIsMutable()
+ /**
+ * @expectedException \Zend\View\Exception\InvalidArgumentException
+ */
+ public function testEncodingIsImmutable()
{
$this->helper->setEncoding('BIG5-HKSCS');
- $this->assertEquals('BIG5-HKSCS', $this->helper->getEncoding());
- }
-
- public function testDefaultCallbackIsDefined()
- {
- $callback = $this->helper->getCallback();
- $this->assertTrue(is_callable($callback));
+ $this->helper->getEscaper();
+ $this->helper->setEncoding('UTF-8');
}
- public function testCallbackIsMutable()
+ public function testGetEscaperCreatesDefaultInstanceWithCorrectEncoding()
{
- $this->helper->setCallback('strip_tags'); // Don't do this at home ;)
- $this->assertEquals('strip_tags', $this->helper->getCallback());
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
}
- public function testSettingInvalidCallbackRaisesException()
+ public function testSettingEscaperObjectAlsoSetsEncoding()
{
- $this->setExpectedException('Zend\View\Exception\ExceptionInterface');
- $this->helper->setCallback(3.1415);
+ $escaper = new \Zend\Escaper\Escaper('big5-hkscs');
+ $this->helper->setEscaper($escaper);
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
}
- public function testInvokingCallbackEscapesText()
+ public function testEscapehtmlCalledOnEscaperObject()
{
- $text = 'Hey! This is some Text! Yo!';
- $expected = htmlspecialchars($text, ENT_COMPAT, 'UTF-8', false);
- $test = $this->helper->__invoke($text);
- $this->assertEquals($expected, $test);
+ $escaper = $this->getMock('\\Zend\\Escaper\\Escaper');
+ $escaper->expects($this->any())->method('escapeHtml');
+ $this->helper->setEscaper($escaper);
+ $this->helper->__invoke('foo');
}
public function testAllowsRecursiveEscapingOfArrays()
@@ -152,8 +162,8 @@ public function testCanRecurseObjectProperties()
}
/**
- * @expectedException \Zend\View\Exception\InvalidArgumentException
- *
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
* PHP 5.3 instates default encoding on empty string instead of the expected
* warning level error for htmlspecialchars() encoding param. PHP 5.4 attempts
* to guess the encoding or take it from php.ini default_charset when an empty
@@ -162,18 +172,21 @@ public function testCanRecurseObjectProperties()
public function testSettingEncodingToEmptyStringShouldThrowException()
{
$this->helper->setEncoding('');
+ $this->helper->getEscaper();
}
public function testSettingValidEncodingShouldNotThrowExceptions()
{
foreach ($this->supportedEncodings as $value) {
- $this->helper->setEncoding($value);
+ $helper = new EscapeHelper;
+ $helper->setEncoding($value);
+ $helper->getEscaper();
}
}
/**
- * @expectedException \Zend\View\Exception\InvalidArgumentException
- *
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
* All versions of PHP - when an invalid encoding is set on htmlspecialchars()
* a warning level error is issued and escaping continues with the default encoding
* for that PHP version. Preventing the continuation behaviour offsets display_errors
@@ -182,5 +195,6 @@ public function testSettingValidEncodingShouldNotThrowExceptions()
public function testSettingEncodingToInvalidValueShouldThrowException()
{
$this->helper->setEncoding('completely-invalid');
+ $this->helper->getEscaper();
}
}
diff --git a/test/Helper/EscapeJsTest.php b/test/Helper/EscapeJsTest.php
new file mode 100644
index 00000000..34c7e460
--- /dev/null
+++ b/test/Helper/EscapeJsTest.php
@@ -0,0 +1,203 @@
+helper = new EscapeHelper;
+ }
+
+ public function testUsesUtf8EncodingByDefault()
+ {
+ $this->assertEquals('UTF-8', $this->helper->getEncoding());
+ }
+
+ /**
+ * @expectedException \Zend\View\Exception\InvalidArgumentException
+ */
+ public function testEncodingIsImmutable()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $this->helper->getEscaper();
+ $this->helper->setEncoding('UTF-8');
+ }
+
+ public function testGetEscaperCreatesDefaultInstanceWithCorrectEncoding()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testSettingEscaperObjectAlsoSetsEncoding()
+ {
+ $escaper = new \Zend\Escaper\Escaper('big5-hkscs');
+ $this->helper->setEscaper($escaper);
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testEscapehtmlCalledOnEscaperObject()
+ {
+ $escaper = $this->getMock('\\Zend\\Escaper\\Escaper');
+ $escaper->expects($this->any())->method('escapeJs');
+ $this->helper->setEscaper($escaper);
+ $this->helper->__invoke('foo');
+ }
+
+ public function testAllowsRecursiveEscapingOfArrays()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $expected = array(
+ 'foo' => '\x3Cb\x3Ebar\x3C\x2Fb\x3E',
+ 'baz' => array(
+ '\x3Cem\x3Ebat\x3C\x2Fem\x3E',
+ 'second' => array(
+ '\x3Ci\x3Ethird\x3C\x2Fi\x3E',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($original, EscapeHelper::RECURSE_ARRAY);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testWillCastObjectsToStringsBeforeEscaping()
+ {
+ $object = new TestAsset\Stringified;
+ $test = $this->helper->__invoke($object);
+ $this->assertEquals(
+ 'ZendTest\x5CView\x5CHelper\x5CTestAsset\x5CStringified',
+ $test
+ );
+ }
+
+ public function testCanRecurseObjectImplementingToArray()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new TestAsset\ToArray();
+ $object->array = $original;
+
+ $expected = array(
+ 'foo' => '\x3Cb\x3Ebar\x3C\x2Fb\x3E',
+ 'baz' => array(
+ '\x3Cem\x3Ebat\x3C\x2Fem\x3E',
+ 'second' => array(
+ '\x3Ci\x3Ethird\x3C\x2Fi\x3E',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testCanRecurseObjectProperties()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new stdClass();
+ foreach ($original as $key => $value) {
+ $object->$key = $value;
+ }
+
+ $expected = array(
+ 'foo' => '\x3Cb\x3Ebar\x3C\x2Fb\x3E',
+ 'baz' => array(
+ '\x3Cem\x3Ebat\x3C\x2Fem\x3E',
+ 'second' => array(
+ '\x3Ci\x3Ethird\x3C\x2Fi\x3E',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * PHP 5.3 instates default encoding on empty string instead of the expected
+ * warning level error for htmlspecialchars() encoding param. PHP 5.4 attempts
+ * to guess the encoding or take it from php.ini default_charset when an empty
+ * string is set. Both are insecure behaviours.
+ */
+ public function testSettingEncodingToEmptyStringShouldThrowException()
+ {
+ $this->helper->setEncoding('');
+ $this->helper->getEscaper();
+ }
+
+ public function testSettingValidEncodingShouldNotThrowExceptions()
+ {
+ foreach ($this->supportedEncodings as $value) {
+ $helper = new EscapeHelper;
+ $helper->setEncoding($value);
+ $helper->getEscaper();
+ }
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * All versions of PHP - when an invalid encoding is set on htmlspecialchars()
+ * a warning level error is issued and escaping continues with the default encoding
+ * for that PHP version. Preventing the continuation behaviour offsets display_errors
+ * off in production env.
+ */
+ public function testSettingEncodingToInvalidValueShouldThrowException()
+ {
+ $this->helper->setEncoding('completely-invalid');
+ $this->helper->getEscaper();
+ }
+}
diff --git a/test/Helper/EscapeUrlTest.php b/test/Helper/EscapeUrlTest.php
new file mode 100644
index 00000000..a69ef612
--- /dev/null
+++ b/test/Helper/EscapeUrlTest.php
@@ -0,0 +1,203 @@
+helper = new EscapeHelper;
+ }
+
+ public function testUsesUtf8EncodingByDefault()
+ {
+ $this->assertEquals('UTF-8', $this->helper->getEncoding());
+ }
+
+ /**
+ * @expectedException \Zend\View\Exception\InvalidArgumentException
+ */
+ public function testEncodingIsImmutable()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $this->helper->getEscaper();
+ $this->helper->setEncoding('UTF-8');
+ }
+
+ public function testGetEscaperCreatesDefaultInstanceWithCorrectEncoding()
+ {
+ $this->helper->setEncoding('BIG5-HKSCS');
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testSettingEscaperObjectAlsoSetsEncoding()
+ {
+ $escaper = new \Zend\Escaper\Escaper('big5-hkscs');
+ $this->helper->setEscaper($escaper);
+ $escaper = $this->helper->getEscaper();
+ $this->assertTrue($escaper instanceof \Zend\Escaper\Escaper);
+ $this->assertEquals('big5-hkscs', $escaper->getEncoding());
+ }
+
+ public function testEscapehtmlCalledOnEscaperObject()
+ {
+ $escaper = $this->getMock('\\Zend\\Escaper\\Escaper');
+ $escaper->expects($this->any())->method('escapeUrl');
+ $this->helper->setEscaper($escaper);
+ $this->helper->__invoke('foo');
+ }
+
+ public function testAllowsRecursiveEscapingOfArrays()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $expected = array(
+ 'foo' => '%3Cb%3Ebar%3C%2Fb%3E',
+ 'baz' => array(
+ '%3Cem%3Ebat%3C%2Fem%3E',
+ 'second' => array(
+ '%3Ci%3Ethird%3C%2Fi%3E',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($original, EscapeHelper::RECURSE_ARRAY);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testWillCastObjectsToStringsBeforeEscaping()
+ {
+ $object = new TestAsset\Stringified;
+ $test = $this->helper->__invoke($object);
+ $this->assertEquals(
+ 'ZendTest%5CView%5CHelper%5CTestAsset%5CStringified',
+ $test
+ );
+ }
+
+ public function testCanRecurseObjectImplementingToArray()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new TestAsset\ToArray();
+ $object->array = $original;
+
+ $expected = array(
+ 'foo' => '%3Cb%3Ebar%3C%2Fb%3E',
+ 'baz' => array(
+ '%3Cem%3Ebat%3C%2Fem%3E',
+ 'second' => array(
+ '%3Ci%3Ethird%3C%2Fi%3E',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ public function testCanRecurseObjectProperties()
+ {
+ $original = array(
+ 'foo' => 'bar',
+ 'baz' => array(
+ 'bat',
+ 'second' => array(
+ 'third',
+ ),
+ ),
+ );
+ $object = new stdClass();
+ foreach ($original as $key => $value) {
+ $object->$key = $value;
+ }
+
+ $expected = array(
+ 'foo' => '%3Cb%3Ebar%3C%2Fb%3E',
+ 'baz' => array(
+ '%3Cem%3Ebat%3C%2Fem%3E',
+ 'second' => array(
+ '%3Ci%3Ethird%3C%2Fi%3E',
+ ),
+ ),
+ );
+ $test = $this->helper->__invoke($object, EscapeHelper::RECURSE_OBJECT);
+ $this->assertEquals($expected, $test);
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * PHP 5.3 instates default encoding on empty string instead of the expected
+ * warning level error for htmlspecialchars() encoding param. PHP 5.4 attempts
+ * to guess the encoding or take it from php.ini default_charset when an empty
+ * string is set. Both are insecure behaviours.
+ */
+ public function testSettingEncodingToEmptyStringShouldThrowException()
+ {
+ $this->helper->setEncoding('');
+ $this->helper->getEscaper();
+ }
+
+ public function testSettingValidEncodingShouldNotThrowExceptions()
+ {
+ foreach ($this->supportedEncodings as $value) {
+ $helper = new EscapeHelper;
+ $helper->setEncoding($value);
+ $helper->getEscaper();
+ }
+ }
+
+ /**
+ * @expectedException \Zend\Escaper\Exception\InvalidArgumentException
+ *
+ * All versions of PHP - when an invalid encoding is set on htmlspecialchars()
+ * a warning level error is issued and escaping continues with the default encoding
+ * for that PHP version. Preventing the continuation behaviour offsets display_errors
+ * off in production env.
+ */
+ public function testSettingEncodingToInvalidValueShouldThrowException()
+ {
+ $this->helper->setEncoding('completely-invalid');
+ $this->helper->getEscaper();
+ }
+}
diff --git a/test/Helper/GravatarTest.php b/test/Helper/GravatarTest.php
index 2c3161b3..a4ae0a81 100644
--- a/test/Helper/GravatarTest.php
+++ b/test/Helper/GravatarTest.php
@@ -1,36 +1,23 @@
basePath = __DIR__ . '/_files/modules';
$this->view = new View();
$this->helper = new Helper\HeadLink();
diff --git a/test/Helper/HeadMetaTest.php b/test/Helper/HeadMetaTest.php
index fcde582b..91f00bb0 100644
--- a/test/Helper/HeadMetaTest.php
+++ b/test/Helper/HeadMetaTest.php
@@ -1,30 +1,19 @@
error = false;
- foreach (array(PlaceholderRegistry::REGISTRY_KEY, 'Zend_View_Helper_Doctype') as $key) {
- if (Registry::isRegistered($key)) {
- $registry = Registry::getInstance();
- unset($registry[$key]);
- }
- }
+ PlaceholderRegistry::unsetRegistry();
+ Helper\Doctype::unsetDoctypeRegistry();
$this->basePath = __DIR__ . '/_files/modules';
$this->view = new View();
$this->view->plugin('doctype')->__invoke('XHTML1_STRICT');
@@ -406,37 +389,37 @@ public function testContainerMaintainsCorrectOrderOfItems()
$this->assertEquals($expected, $test);
}
- /**
- * @issue ZF-7722
- */
- public function testCharsetValidateFail()
- {
- $view = new View();
- $view->plugin('doctype')->__invoke('HTML4_STRICT');
+ /**
+ * @issue ZF-7722
+ */
+ public function testCharsetValidateFail()
+ {
+ $view = new View();
+ $view->plugin('doctype')->__invoke('HTML4_STRICT');
$this->setExpectedException('Zend\View\Exception\ExceptionInterface');
$view->plugin('headMeta')->setCharset('utf-8');
- }
+ }
- /**
- * @issue ZF-7722
- */
- public function testCharset()
+ /**
+ * @issue ZF-7722
+ */
+ public function testCharset()
{
- $view = new View();
- $view->plugin('doctype')->__invoke('HTML5');
+ $view = new View();
+ $view->plugin('doctype')->__invoke('HTML5');
- $view->plugin('headMeta')->setCharset('utf-8');
- $this->assertEquals(
- '',
- $view->plugin('headMeta')->toString());
+ $view->plugin('headMeta')->setCharset('utf-8');
+ $this->assertEquals(
+ '',
+ $view->plugin('headMeta')->toString());
- $view->plugin('doctype')->__invoke('XHTML5');
+ $view->plugin('doctype')->__invoke('XHTML5');
- $this->assertEquals(
- '',
- $view->plugin('headMeta')->toString());
- }
+ $this->assertEquals(
+ '',
+ $view->plugin('headMeta')->toString());
+ }
/**
* @group ZF-9743
@@ -496,10 +479,10 @@ public function testOverloadingSetPropertyOverwritesMetaTagStack()
/**
* @group ZF-11835
*/
- public function testConditional()
+ public function testConditional()
{
$html = $this->helper->appendHttpEquiv('foo', 'bar', array('conditional' => 'lt IE 7'))->toString();
-
+
$this->assertRegExp("|^$|", $html);
}
diff --git a/test/Helper/HeadScriptTest.php b/test/Helper/HeadScriptTest.php
index 2080b3ed..efa78428 100644
--- a/test/Helper/HeadScriptTest.php
+++ b/test/Helper/HeadScriptTest.php
@@ -1,25 +1,15 @@
basePath = __DIR__ . '/_files/modules';
$this->helper = new Helper\HeadScript();
}
@@ -361,11 +345,9 @@ public function testCanPerformMultipleSerialCaptures()
$this->helper->__invoke()->captureStart();
echo "this is something captured";
$this->helper->__invoke()->captureEnd();
- try {
- $this->helper->__invoke()->captureStart();
- } catch (View\Exception\ExceptionInterface $e) {
- $this->fail('Serial captures should be allowed');
- }
+
+ $this->helper->__invoke()->captureStart();
+
echo "this is something else captured";
$this->helper->__invoke()->captureEnd();
}
diff --git a/test/Helper/HeadStyleTest.php b/test/Helper/HeadStyleTest.php
index c636d318..326e9605 100644
--- a/test/Helper/HeadStyleTest.php
+++ b/test/Helper/HeadStyleTest.php
@@ -1,25 +1,15 @@
basePath = __DIR__ . '/_files/modules';
$this->helper = new Helper\HeadStyle();
}
@@ -327,11 +311,8 @@ public function testSerialCapturingWorks()
echo "Captured text";
$this->helper->__invoke()->captureEnd();
- try {
- $this->helper->__invoke()->captureStart();
- } catch (View\Exception\ExceptionInterface $e) {
- $this->fail('Serial capturing should work');
- }
+ $this->helper->__invoke()->captureStart();
+
$this->helper->__invoke()->captureEnd();
}
@@ -427,7 +408,7 @@ public function testRenderConditionalCommentsShouldNotContainHtmlEscaping()
{
$style = 'a{display:none;}';
$this->helper->appendStyle($style, array(
- 'conditional' => 'IE 8'
+ 'conditional' => 'IE 8'
));
$value = $this->helper->toString();
diff --git a/test/Helper/HeadTitleTest.php b/test/Helper/HeadTitleTest.php
index 6a82144a..e62dd9cf 100644
--- a/test/Helper/HeadTitleTest.php
+++ b/test/Helper/HeadTitleTest.php
@@ -1,25 +1,16 @@
basePath = __DIR__ . '/_files/modules';
$this->helper = new Helper\HeadTitle();
}
@@ -189,16 +174,37 @@ public function testZF3577()
public function testCanTranslateTitle()
{
- $adapter = new \Zend\Translator\Adapter\Ini(__DIR__ . '/../../Translator/Adapter/_files/translation_en.ini', 'en');
- \Zend\Registry::set('Zend_Translator', $adapter);
- $this->helper->enableTranslation();
+ $loader = new TestAsset\ArrayTranslator();
+ $loader->translations = array(
+ 'Message_1' => 'Message 1 (en)',
+ );
+ $translator = new Translator();
+ $translator->getPluginManager()->setService('default', $loader);
+ $translator->addTranslationFile('default', null);
+
+ $this->helper->setTranslatorEnabled(true);
+ $this->helper->setTranslator($translator);
$this->helper->__invoke('Message_1');
$this->assertEquals('