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 . '' . $output . ''; } + + // Translator methods - Good candidate to refactor as a trait with PHP 5.4 + + /** + * Sets translator to use in helper + * + * @param Translator $translator [optional] translator. + * Default is null, which sets no translator. + * @param string $textDomain [optional] text domain + * Default is null, which skips setTranslatorTextDomain + * @return HeadTitle + */ + public function setTranslator(Translator $translator = null, $textDomain = null) + { + $this->translator = $translator; + if (null !== $textDomain) { + $this->setTranslatorTextDomain($textDomain); + } + return $this; + } + + /** + * Returns translator used in helper + * + * @return Translator|null + */ + public function getTranslator() + { + if (! $this->isTranslatorEnabled()) { + return null; + } + + return $this->translator; + } + + /** + * Checks if the helper has a translator + * + * @return bool + */ + public function hasTranslator() + { + return (bool) $this->getTranslator(); + } + + /** + * Sets whether translator is enabled and should be used + * + * @param bool $enabled [optional] whether translator should be used. + * Default is true. + * @return HeadTitle + */ + public function setTranslatorEnabled($enabled = true) + { + $this->translatorEnabled = (bool) $enabled; + return $this; + } + + /** + * Returns whether translator is enabled and should be used + * + * @return bool + */ + public function isTranslatorEnabled() + { + return $this->translatorEnabled; + } + + /** + * Set translation text domain + * + * @param string $textDomain + * @return HeadTitle + */ + public function setTranslatorTextDomain($textDomain = 'default') + { + $this->translatorTextDomain = $textDomain; + return $this; + } + + /** + * Return the translation text domain + * + * @return string + */ + public function getTranslatorTextDomain() + { + return $this->translatorTextDomain; + } } diff --git a/src/Helper/HelperInterface.php b/src/Helper/HelperInterface.php index b60ba81b..1c3909be 100644 --- a/src/Helper/HelperInterface.php +++ b/src/Helper/HelperInterface.php @@ -1,22 +1,11 @@ view->plugin('escape'); + $escaper = $this->view->plugin('escapeHtml'); $item = $escaper($item); } $list .= '
  • ' . $item . '
  • ' . self::EOL; } else { - if (6 < strlen($list)) { - $list = substr($list, 0, strlen($list) - 6) + $itemLength = 5 + strlen(self::EOL); + if ($itemLength < strlen($list)) { + $list = substr($list, 0, strlen($list) - $itemLength) . $this($item, $ordered, $attribs, $escape) . '' . self::EOL; } else { $list .= '
  • ' . $this($item, $ordered, $attribs, $escape) . '
  • ' . self::EOL; @@ -67,10 +55,7 @@ public function __invoke(array $items, $ordered = false, $attribs = false, $esca $attribs = ''; } - $tag = 'ul'; - if ($ordered) { - $tag = 'ol'; - } + $tag = ($ordered) ? 'ol' : 'ul'; return '<' . $tag . $attribs . '>' . self::EOL . $list . '' . self::EOL; } diff --git a/src/Helper/HtmlObject.php b/src/Helper/HtmlObject.php index 6159c361..9a4ccad3 100644 --- a/src/Helper/HtmlObject.php +++ b/src/Helper/HtmlObject.php @@ -1,22 +1,11 @@ response instanceof Response) { - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $headers->addHeaderLine('Content-Type', 'application/json'); } diff --git a/src/Helper/Layout.php b/src/Helper/Layout.php index 6f740540..e9787e41 100644 --- a/src/Helper/Layout.php +++ b/src/Helper/Layout.php @@ -1,36 +1,23 @@ getInjectTranslator() && !$helper->hasTranslator()) { - $helper->setTranslator($this->getTranslator()); + $helper->setTranslator( + $this->getTranslator(), $this->getTranslatorTextDomain() + ); } } diff --git a/src/Helper/Navigation/AbstractHelper.php b/src/Helper/Navigation/AbstractHelper.php index bacd3175..b68498f3 100644 --- a/src/Helper/Navigation/AbstractHelper.php +++ b/src/Helper/Navigation/AbstractHelper.php @@ -1,33 +1,23 @@ indent; } - /** - * Sets translator to use in helper - * - * Implements {@link HelperInterface::setTranslator()}. - * - * @param mixed $translator [optional] translator. Expects an object of - * type {@link Translator\Adapter\AbstractAdapter} - * or {@link Translator\Translator}, or null. - * Default is null, which sets no translator. - * @return AbstractHelper fluent interface, returns self - */ - public function setTranslator($translator = null) - { - if (null == $translator || - $translator instanceof Translator\Adapter\AbstractAdapter) { - $this->translator = $translator; - } elseif ($translator instanceof Translator\Translator) { - $this->translator = $translator->getAdapter(); - } - - return $this; - } - - /** - * Returns translator used in helper - * - * Implements {@link HelperInterface::getTranslator()}. - * - * @return Translator\Adapter\AbstractAdapter|null translator or null - */ - public function getTranslator() - { - return $this->translator; - } - /** * Sets ACL to use when iterating pages * @@ -390,7 +351,7 @@ public function setRole($role = null) } else { throw new Exception\InvalidArgumentException(sprintf( '$role must be a string, null, or an instance of ' - . 'Zend\Acl\Role\RoleInterface; %s given', + . 'Zend\Permissions\Role\RoleInterface; %s given', (is_object($role) ? get_class($role) : gettype($role)) )); } @@ -463,33 +424,6 @@ public function setRenderInvisible($renderInvisible = true) return $this; } - /** - * Sets whether translator should be used - * - * Implements {@link HelperInterface::setUseTranslator()}. - * - * @param bool $useTranslator [optional] whether translator should be used. - * Default is true. - * @return AbstractHelper fluent interface, returns self - */ - public function setUseTranslator($useTranslator = true) - { - $this->useTranslator = (bool) $useTranslator; - return $this; - } - - /** - * Returns whether translator should be used - * - * Implements {@link HelperInterface::getUseTranslator()}. - * - * @return bool whether translator should be used - */ - public function getUseTranslator() - { - return $this->useTranslator; - } - // Magic overloads: /** @@ -637,18 +571,6 @@ public function hasRole() return null !== $this->role; } - /** - * Checks if the helper has a translator - * - * Implements {@link HelperInterface::hasTranslator()}. - * - * @return bool whether the helper has a translator or not - */ - public function hasTranslator() - { - return null !== $this->translator; - } - /** * Returns an HTML string containing an 'a' element for the given page * @@ -661,12 +583,13 @@ public function htmlify(AbstractPage $page) $label = $page->getLabel(); $title = $page->getTitle(); - 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); } } @@ -679,13 +602,102 @@ public function htmlify(AbstractPage $page) 'target' => $page->getTarget() ); - $escaper = $this->view->plugin('escape'); + $escaper = $this->view->plugin('escapeHtml'); return '_htmlAttribs($attribs) . '>' . $escaper($label) . ''; } + // Translator methods - Good candidate to refactor as a trait with PHP 5.4 + + /** + * Sets translator to use in helper + * + * @param Translator $translator [optional] translator. + * Default is null, which sets no translator. + * @param string $textDomain [optional] text domain + * Default is null, which skips setTranslatorTextDomain + * @return AbstractHelper + */ + public function setTranslator(Translator $translator = null, $textDomain = null) + { + $this->translator = $translator; + if (null !== $textDomain) { + $this->setTranslatorTextDomain($textDomain); + } + return $this; + } + + /** + * Returns translator used in helper + * + * @return Translator|null + */ + public function getTranslator() + { + if (! $this->isTranslatorEnabled()) { + return null; + } + + return $this->translator; + } + + /** + * Checks if the helper has a translator + * + * @return bool + */ + public function hasTranslator() + { + return (bool) $this->getTranslator(); + } + + /** + * Sets whether translator is enabled and should be used + * + * @param bool $enabled [optional] whether translator should be used. + * Default is true. + * @return AbstractHelper + */ + public function setTranslatorEnabled($enabled = true) + { + $this->translatorEnabled = (bool) $enabled; + return $this; + } + + /** + * Returns whether translator is enabled and should be used + * + * @return bool + */ + public function isTranslatorEnabled() + { + return $this->translatorEnabled; + } + + /** + * Set translation text domain + * + * @param string $textDomain + * @return AbstractHelper + */ + public function setTranslatorTextDomain($textDomain = 'default') + { + $this->translatorTextDomain = $textDomain; + return $this; + } + + /** + * Return the translation text domain + * + * @return string + */ + public function getTranslatorTextDomain() + { + return $this->translatorTextDomain; + } + // Iterator filter methods: /** @@ -782,7 +794,7 @@ protected function getWhitespace($indent) /** * Converts an associative array to a string of tag attributes. * - * Overloads {@link View\Helper\HtmlElement::_htmlAttribs()}. + * Overloads {@link View\Helper\AbstractHtmlElement::_htmlAttribs()}. * * @param array $attribs an array where each key-value pair is converted * to an attribute name and value @@ -803,7 +815,7 @@ protected function _htmlAttribs($attribs) /** * Normalize an ID * - * Overrides {@link View\Helper\HtmlElement::_normalizeId()}. + * Overrides {@link View\Helper\AbstractHtmlElement::_normalizeId()}. * * @param string $value * @return string @@ -849,7 +861,7 @@ public static function setDefaultRole($role = null) self::$defaultRole = $role; } else { throw new Exception\InvalidArgumentException(sprintf( - '$role must be null|string|Zend\Acl\Role\RoleInterface; received "%s"', + '$role must be null|string|Zend\Permissions\Role\RoleInterface; received "%s"', (is_object($role) ? get_class($role) : gettype($role)) )); } diff --git a/src/Helper/Navigation/Breadcrumbs.php b/src/Helper/Navigation/Breadcrumbs.php index aec20ac9..39f0c580 100644 --- a/src/Helper/Navigation/Breadcrumbs.php +++ b/src/Helper/Navigation/Breadcrumbs.php @@ -1,22 +1,11 @@ htmlify($active); } else { $html = $active->getLabel(); - if ($this->getUseTranslator() && $t = $this->getTranslator()) { - $html = $t->translate($html); + if (null !== ($translator = $this->getTranslator())) { + $html = $translator->translate($html, $this->getTranslatorTextDomain()); } - $escaper = $this->view->plugin('escape'); + $escaper = $this->view->plugin('escapeHtml'); $html = $escaper($html); } @@ -222,13 +209,13 @@ public function renderStraight($container = null) * so in the script it will be available in $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) . ''; @@ -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 . '' . self::EOL; - } else if ($prevDepth > $depth) { + } elseif ($prevDepth > $depth) { // close li/ul tags until we're at current depth for ($i = $prevDepth; $i > $depth; $i--) { $ind = $indent . str_repeat(' ', $i); @@ -470,9 +458,9 @@ protected function _renderMenu(AbstractContainer $container, * * * @param AbstractContainer $container [optional] container to create menu from. - * Default is to use the container retrieved + * Default is to use the container retrieved * from {@link getContainer()}. - * @param array $options [optional] options for controlling rendering + * @param array $options [optional] options for controlling rendering * @return string rendered menu */ public function renderMenu($container = null, array $options = array()) @@ -555,14 +543,14 @@ public function renderSubMenu(AbstractContainer $container = null, * 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('Message 1 (en)', $this->helper->toString()); } - /** - * @group ZF-8036 - */ + public function testTranslatorMethods() + { + $translatorMock = $this->getMock('Zend\I18n\Translator\Translator'); + $this->helper->setTranslator($translatorMock, 'foo'); + + $this->assertEquals($translatorMock, $this->helper->getTranslator()); + $this->assertEquals('foo', $this->helper->getTranslatorTextDomain()); + $this->assertTrue($this->helper->hasTranslator()); + $this->assertTrue($this->helper->isTranslatorEnabled()); + + $this->helper->setTranslatorEnabled(false); + $this->assertFalse($this->helper->isTranslatorEnabled()); + } + + /** + * @group ZF-8036 + */ public function testHeadTitleZero() { $this->helper->__invoke('0'); diff --git a/test/Helper/HtmlFlashTest.php b/test/Helper/HtmlFlashTest.php index 8db49140..c673ac98 100644 --- a/test/Helper/HtmlFlashTest.php +++ b/test/Helper/HtmlFlashTest.php @@ -1,35 +1,22 @@ basePath = __DIR__ . '/_files/modules'; $this->helper = new Helper\InlineScript(); } diff --git a/test/Helper/JsonTest.php b/test/Helper/JsonTest.php index 20008da2..a9780e56 100644 --- a/test/Helper/JsonTest.php +++ b/test/Helper/JsonTest.php @@ -1,30 +1,19 @@ response->headers(); + $headers = $this->response->getHeaders(); $this->assertTrue($headers->has('Content-Type')); $header = $headers->get('Content-Type'); $this->assertEquals('application/json', $header->getFieldValue()); diff --git a/test/Helper/LayoutTest.php b/test/Helper/LayoutTest.php index 8c385c09..91ab2895 100644 --- a/test/Helper/LayoutTest.php +++ b/test/Helper/LayoutTest.php @@ -1,29 +1,18 @@ false, 'cache_dir' => 'data/cache', 'module_paths' => array(), - ), - 'service_manager' => array( - 'factories' => array( - 'Configuration' => function() use ($config) { - return array( - 'navigation' => array( - 'default' => $config->get('nav_test1') - ) - ); - } - ) + 'extra_config' => array( + 'service_manager' => array( + 'factories' => array( + 'Config' => function() use ($config) { + return array( + 'navigation' => array( + 'default' => $config->get('nav_test1'), + ), + ); + } + ), + ), + ), ), ); - $sm = $this->serviceManager = new ServiceManager(new ServiceManagerConfiguration($smConfig['service_manager'])); - $sm->setService('ApplicationConfiguration', $smConfig); + $sm = $this->serviceManager = new ServiceManager(new ServiceManagerConfig); + $sm->setService('ApplicationConfig', $smConfig); $sm->get('ModuleManager')->loadModules(); $sm->get('Application')->bootstrap(); $sm->setFactory('Navigation', 'Zend\Navigation\Service\DefaultNavigationFactory'); @@ -152,7 +142,7 @@ protected function setUp() } /** - * Returns the contens of the exepcted $file + * Returns the contens of the expected $file * @param string $file * @return string */ @@ -196,7 +186,8 @@ protected function _getAcl() */ protected function _getTranslator() { - $data = array( + $loader = new TestAsset\ArrayTranslator(); + $loader->translations = array( 'Page 1' => 'Side 1', 'Page 1.1' => 'Side 1.1', 'Page 2' => 'Side 2', @@ -205,7 +196,9 @@ protected function _getTranslator() 'Home' => 'Hjem', 'Go home' => 'GÃ¥ hjem' ); - - return new Translator('ArrayAdapter', $data, 'nb_NO'); + $translator = new Translator(); + $translator->getPluginManager()->setService('default', $loader); + $translator->addTranslationFile('default', null); + return $translator; } } diff --git a/test/Helper/Navigation/BreadcrumbsTest.php b/test/Helper/Navigation/BreadcrumbsTest.php index 1c3b68a6..6b45eb74 100644 --- a/test/Helper/Navigation/BreadcrumbsTest.php +++ b/test/Helper/Navigation/BreadcrumbsTest.php @@ -1,22 +1,11 @@ _getTranslator(); - $this->_helper->setTranslator($translator->getAdapter()); + $this->_helper->setTranslator($translator); $expected = $this->_getExpected('bc/translated.html'); $this->assertEquals($expected, $this->_helper->render()); @@ -186,7 +173,7 @@ public function testDisablingTranslation() { $translator = $this->_getTranslator(); $this->_helper->setTranslator($translator); - $this->_helper->setUseTranslator(false); + $this->_helper->setTranslatorEnabled(false); $expected = $this->_getExpected('bc/default.html'); $this->assertEquals($expected, $this->_helper->render()); diff --git a/test/Helper/Navigation/LinksTest.php b/test/Helper/Navigation/LinksTest.php index 7e0decd7..725f6348 100644 --- a/test/Helper/Navigation/LinksTest.php +++ b/test/Helper/Navigation/LinksTest.php @@ -1,34 +1,23 @@ assertEquals($expected, $actual); } + + /** + * Returns the contens of the expected $file, normalizes newlines + * @param string $file + * @return string + */ + protected function _getExpected($file) + { + return str_replace("\n", PHP_EOL, parent::_getExpected($file)); + } } diff --git a/test/Helper/Navigation/MenuTest.php b/test/Helper/Navigation/MenuTest.php index 8a835c31..73abee18 100644 --- a/test/Helper/Navigation/MenuTest.php +++ b/test/Helper/Navigation/MenuTest.php @@ -1,22 +1,11 @@ _getAcl(); $this->_helper->setAcl($acl['acl']); - $this->_helper->setRole(new \Zend\Acl\Role\GenericRole('member')); + $this->_helper->setRole(new \Zend\Permissions\Acl\Role\GenericRole('member')); $expected = $this->_getExpected('menu/acl_role_interface.html'); $this->assertEquals($expected, $this->_helper->render()); @@ -199,7 +186,7 @@ public function testTranslationUsingZendTranslate() public function testTranslationUsingZendTranslateAdapter() { $translator = $this->_getTranslator(); - $this->_helper->setTranslator($translator->getAdapter()); + $this->_helper->setTranslator($translator); $expected = $this->_getExpected('menu/translated.html'); $this->assertEquals($expected, $this->_helper->render()); @@ -209,7 +196,7 @@ public function testDisablingTranslation() { $translator = $this->_getTranslator(); $this->_helper->setTranslator($translator); - $this->_helper->setUseTranslator(false); + $this->_helper->setTranslatorEnabled(false); $expected = $this->_getExpected('menu/default1.html'); $this->assertEquals($expected, $this->_helper->render()); @@ -496,4 +483,14 @@ public function testOptionOnlyActiveBranchNoParentsAndBothDepthsSpecified() $this->assertEquals($expected, $actual); } + + /** + * Returns the contens of the expected $file, normalizes newlines + * @param string $file + * @return string + */ + protected function _getExpected($file) + { + return str_replace("\n", PHP_EOL, parent::_getExpected($file)); + } } diff --git a/test/Helper/Navigation/NavigationTest.php b/test/Helper/Navigation/NavigationTest.php index 9ca978c6..3fcec6db 100644 --- a/test/Helper/Navigation/NavigationTest.php +++ b/test/Helper/Navigation/NavigationTest.php @@ -1,30 +1,19 @@ assertEquals($this->_helper, $returned); $this->assertEquals($this->_nav2, $returned->getContainer()); } - + public function testAcceptAclShouldReturnGracefullyWithUnknownResource() { // setup $acl = $this->_getAcl(); $this->_helper->setAcl($acl['acl']); $this->_helper->setRole($acl['role']); - + $accepted = $this->_helper->accept( new \Zend\Navigation\Page\Uri(array( 'resource' => 'unknownresource', - 'privilege' => 'someprivilege' + 'privilege' => 'someprivilege' ), false) ); @@ -191,6 +178,20 @@ public function testDisablingTranslatorInjection() $this->assertEquals($expected, $actual); } + public function testTranslatorMethods() + { + $translatorMock = $this->getMock('Zend\I18n\Translator\Translator'); + $this->_helper->setTranslator($translatorMock, 'foo'); + + $this->assertEquals($translatorMock, $this->_helper->getTranslator()); + $this->assertEquals('foo', $this->_helper->getTranslatorTextDomain()); + $this->assertTrue($this->_helper->hasTranslator()); + $this->assertTrue($this->_helper->isTranslatorEnabled()); + + $this->_helper->setTranslatorEnabled(false); + $this->assertFalse($this->_helper->isTranslatorEnabled()); + } + public function testSpecifyingDefaultProxy() { $expected = array( @@ -420,4 +421,14 @@ public function testRenderInvisibleItem() $this->assertTrue(strpos($render, 'p2') !== false); } + + /** + * Returns the contens of the expected $file, normalizes newlines + * @param string $file + * @return string + */ + protected function _getExpected($file) + { + return str_replace("\n", PHP_EOL, parent::_getExpected($file)); + } } diff --git a/test/Helper/Navigation/SitemapTest.php b/test/Helper/Navigation/SitemapTest.php index 613d32e7..f85c5c6e 100644 --- a/test/Helper/Navigation/SitemapTest.php +++ b/test/Helper/Navigation/SitemapTest.php @@ -1,22 +1,11 @@ _originaltimezone = date_default_timezone_get(); - date_default_timezone_set('Europe/Berlin'); + date_default_timezone_set('Europe/Berlin'); if (isset($_SERVER['SERVER_NAME'])) { $this->_oldServer['SERVER_NAME'] = $_SERVER['SERVER_NAME']; @@ -186,7 +173,7 @@ public function testDropXmlDeclaration() public function testThrowExceptionOnInvalidLoc() { - $this->markTestIncomplete('Zend\URI changes affect this test'); + $this->markTestIncomplete('Zend\URI changes affect this test'); $nav = clone $this->_nav2; $nav->addPage(array('label' => 'Invalid', 'uri' => 'http://w.')); diff --git a/test/Helper/Navigation/_files/mvc/views/menu.phtml b/test/Helper/Navigation/_files/mvc/views/menu.phtml index 102fadea..004ee04f 100644 --- a/test/Helper/Navigation/_files/mvc/views/menu.phtml +++ b/test/Helper/Navigation/_files/mvc/views/menu.phtml @@ -9,5 +9,5 @@ foreach ($this->vars('container') as $page) { } $pages = implode(', ', $pages); ?> -Is a container: +Is a container: Pages: diff --git a/test/Helper/Navigation/_files/navigation.xml b/test/Helper/Navigation/_files/navigation.xml index 87bb6c1a..caed03f9 100644 --- a/test/Helper/Navigation/_files/navigation.xml +++ b/test/Helper/Navigation/_files/navigation.xml @@ -2,82 +2,82 @@ - + http://www.zym-project.com/ 100 - + page1 - + page1/page1_1 - + - + page2 - + page2/page2_1 - + page2/page2_2 - + page2/page2_2/page2_2_1 - + page2/page2_2/page2_2_2 1 - + - + page2/page2_3 - + page2/page2_3/page2_3_1 - + page2/page2_3/page2_3_2 0 - + page2/page2_3/page2_3_2/1 1 - + page2/page2_3/page2_3_2/2 1 - + @@ -86,127 +86,127 @@ - + - + page2/page2_3/page2_3_3 admin_foo - + page2/page2_3/page2_3_3/1 1 - + page2/page2_3/page2_3_3/2 guest_foo 1 - + - + - + - + page3 - + page3/page3_1 guest_foo - + page3/page3_2 member_foo - + page3/page3_2/page3_2_1 - + page3/page3_2/page3_2_2 admin_foo read - + - + page3/page3_3 special_foo - + page3/page3_3/page3_3_1 0 - + page3/page3_3/page3_3_2 admin_foo - + - + - + index Go home -100 - + - - - + + + - + site1 daily 0.9 - + site2 1 earlier - + site3 often - + - + \ No newline at end of file diff --git a/test/Helper/PaginationControlTest.php b/test/Helper/PaginationControlTest.php index aa21d2d9..58743639 100644 --- a/test/Helper/PaginationControlTest.php +++ b/test/Helper/PaginationControlTest.php @@ -1,37 +1,24 @@ _viewHelper->getView()->paginator = $this->_paginator; Helper\PaginationControl::setDefaultViewPartial('testPagination.phtml'); - try { - $output = $this->_viewHelper->__invoke(); - } catch (\Zend\View\Exception\ExceptionInterface $e) { - $this->fail('Could not find paginator in the view instance'); - } + $output = $this->_viewHelper->__invoke(); $this->assertContains('pagination control', $output, $output); } @@ -147,12 +130,11 @@ public function testThrowsExceptionIfNoPaginatorFound() { Helper\PaginationControl::setDefaultViewPartial('testPagination.phtml'); - try { - $output = $this->_viewHelper->__invoke(); - } catch (\Exception $e) { - $this->assertInstanceOf('Zend\View\Exception\ExceptionInterface', $e); - $this->assertEquals('No paginator instance provided or incorrect type', $e->getMessage()); - } + $this->setExpectedException( + 'Zend\View\Exception\ExceptionInterface', + 'No paginator instance provided or incorrect type' + ); + $this->_viewHelper->__invoke(); } /** @@ -191,11 +173,7 @@ public function testCanUseObjectForScrollingStyle() { $all = new Paginator\ScrollingStyle\All(); - try { - $output = $this->_viewHelper->__invoke($this->_paginator, $all, 'testPagination.phtml'); - } catch (\Exception $e) { - $this->fail('Could not use object for sliding style'); - } + $output = $this->_viewHelper->__invoke($this->_paginator, $all, 'testPagination.phtml'); $this->assertContains('page count (11) equals pages in range (11)', $output, $output); } diff --git a/test/Helper/PartialLoopTest.php b/test/Helper/PartialLoopTest.php index 116daa11..f976419c 100644 --- a/test/Helper/PartialLoopTest.php +++ b/test/Helper/PartialLoopTest.php @@ -1,31 +1,20 @@ resolver()->addPath($this->basePath . '/application/views/scripts'); $this->helper->setView($view); - try { - $result = $this->helper->__invoke('partialLoop.phtml', array()); - } catch (\Exception $e) { - $this->fail('Empty array should not cause partialLoop to throw exception'); - } + $this->helper->__invoke('partialLoop.phtml', array()); } /** diff --git a/test/Helper/PartialTest.php b/test/Helper/PartialTest.php index 363f3683..46d69973 100644 --- a/test/Helper/PartialTest.php +++ b/test/Helper/PartialTest.php @@ -1,29 +1,18 @@ registry = new Registry(); } @@ -171,16 +156,6 @@ public function testGetRegistrySubsequentTimesReturnsSameInstance() $this->assertSame($registry1, $registry2); } - public function testGetRegistryRegistersWithGlobalRegistry() - { - $this->assertFalse(\Zend\Registry::isRegistered(Registry::REGISTRY_KEY)); - $registry = Registry::getRegistry(); - $this->assertTrue(\Zend\Registry::isRegistered(Registry::REGISTRY_KEY)); - - $registered = \Zend\Registry::get(Registry::REGISTRY_KEY); - $this->assertSame($registry, $registered); - } - /** * @group ZF-10793 */ diff --git a/test/Helper/Placeholder/StandaloneContainerTest.php b/test/Helper/Placeholder/StandaloneContainerTest.php index c05a15e7..6f4e5119 100644 --- a/test/Helper/Placeholder/StandaloneContainerTest.php +++ b/test/Helper/Placeholder/StandaloneContainerTest.php @@ -1,22 +1,11 @@ basePath = __DIR__ . '/_files/modules'; $this->helper = new Foo(); } @@ -88,7 +71,7 @@ public function testContainersPersistBetweenInstances() } } -class Foo extends \Zend\View\Helper\Placeholder\Container\Standalone +class Foo extends \Zend\View\Helper\Placeholder\Container\AbstractStandalone { protected $_regKey = 'foo'; public function direct() {} diff --git a/test/Helper/PlaceholderTest.php b/test/Helper/PlaceholderTest.php index ad4f7091..035f4608 100644 --- a/test/Helper/PlaceholderTest.php +++ b/test/Helper/PlaceholderTest.php @@ -1,31 +1,18 @@ placeholder = new Helper\Placeholder(); } @@ -65,26 +51,12 @@ public function setUp() public function tearDown() { unset($this->placeholder); - Registry::getInstance()->offsetUnset(PlaceholderRegistry::REGISTRY_KEY); - } - - /** - * @return void - */ - public function testConstructorCreatesRegistryOffset() - { - $this->assertTrue(Registry::isRegistered(PlaceholderRegistry::REGISTRY_KEY)); + PlaceholderRegistry::unsetRegistry(); } public function testMultiplePlaceholdersUseSameRegistry() { - $this->assertTrue(Registry::isRegistered(PlaceholderRegistry::REGISTRY_KEY)); - $registry = Registry::get(PlaceholderRegistry::REGISTRY_KEY); - $this->assertSame($registry, $this->placeholder->getRegistry()); - $placeholder = new Helper\Placeholder(); - - $this->assertSame($registry, $placeholder->getRegistry()); $this->assertSame($this->placeholder->getRegistry(), $placeholder->getRegistry()); } diff --git a/test/Helper/RenderChildModelTest.php b/test/Helper/RenderChildModelTest.php index 2f9f2ff3..97d2afdd 100644 --- a/test/Helper/RenderChildModelTest.php +++ b/test/Helper/RenderChildModelTest.php @@ -1,38 +1,25 @@ helper->render('child1'); $this->assertContains('Content for layout', $result, $result); } - + public function setupSecondChild() { $child2 = new ViewModel(); @@ -140,7 +127,7 @@ public function testAttemptingToRenderWithNoCurrentModelRaisesException() $renderer = new PhpRenderer(); $renderer->setResolver($this->resolver); $this->setExpectedException('Zend\View\Exception\RuntimeException', 'no view model'); - $this->expectOutputString("Layout start\n\n"); + $this->expectOutputString("Layout start" . PHP_EOL . PHP_EOL); $renderer->render('layout'); } } diff --git a/test/Helper/RenderToPlaceholderTest.php b/test/Helper/RenderToPlaceholderTest.php index 2bc8e214..00aaf712 100644 --- a/test/Helper/RenderToPlaceholderTest.php +++ b/test/Helper/RenderToPlaceholderTest.php @@ -1,35 +1,22 @@ _view->plugin('renderToPlaceholder')->__invoke('rendertoplaceholderscript.phtml', 'fooPlaceholder'); $placeholder = new PlaceholderHelper(); - $this->assertEquals("Foo Bar\n", $placeholder->__invoke('fooPlaceholder')->getValue()); + $this->assertEquals("Foo Bar" . "\n", $placeholder->__invoke('fooPlaceholder')->getValue()); } } diff --git a/test/Helper/ServerUrlTest.php b/test/Helper/ServerUrlTest.php index 9783ad7f..3e24b880 100644 --- a/test/Helper/ServerUrlTest.php +++ b/test/Helper/ServerUrlTest.php @@ -1,25 +1,15 @@ translations); + return $textDomain; + } +} diff --git a/test/Helper/TestAsset/ConcreteHelper.php b/test/Helper/TestAsset/ConcreteHelper.php new file mode 100644 index 00000000..2803224d --- /dev/null +++ b/test/Helper/TestAsset/ConcreteHelper.php @@ -0,0 +1,21 @@ +clearRegistry(); - $this->helper = new Helper\Translator(); - } - - /** - * 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 testTranslationObjectPassedToConstructorUsedForTranslation() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', 'two %1\$s' => 'zwei %1\$s'), 'de'); - - $helper = new Helper\Translator($trans); - $this->assertEquals('eins', $helper->__invoke('one')); - $this->assertEquals('three', $helper->__invoke('three')); - } - - public function testLocalTranslationObjectUsedForTranslationsWhenPresent() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', 'two %1\$s' => 'zwei %1\$s'), 'de'); - - $this->helper->setTranslator($trans); - $this->assertEquals('eins', $this->helper->__invoke('one')); - $this->assertEquals('three', $this->helper->__invoke('three')); - } - - public function testTranslationObjectInRegistryUsedForTranslationsInAbsenceOfLocalTranslationObject() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', 'two %1\$s' => 'zwei %1\$s'), 'de'); - \Zend\Registry::set('Zend_Translator', $trans); - $this->assertEquals('eins', $this->helper->__invoke('one')); - } - - public function testOriginalMessagesAreReturnedWhenNoTranslationObjectPresent() - { - $this->assertEquals('one', $this->helper->__invoke('one')); - $this->assertEquals('three', $this->helper->__invoke('three')); - } - - public function testPassingNonNullNonTranslationObjectToConstructorThrowsException() - { - try { - $helper = new Helper\Translator('something'); - } catch (View\Exception\ExceptionInterface $e) { - $this->assertContains('must set an instance of Zend\Translator', $e->getMessage()); - } - } - - public function testPassingNonTranslationObjectToSetTranslatorThrowsException() - { - try { - $this->helper->setTranslator('something'); - } catch (View\Exception\ExceptionInterface $e) { - $this->assertContains('must set an instance of Zend\Translator', $e->getMessage()); - } - } - - public function testRetrievingLocaleWhenNoTranslationObjectSetThrowsException() - { - try { - $this->helper->getLocale(); - } catch (View\Exception\ExceptionInterface $e) { - $this->assertContains('must set an instance of Zend\Translator', $e->getMessage()); - } - } - - public function testSettingLocaleWhenNoTranslationObjectSetThrowsException() - { - try { - $this->helper->setLocale('de'); - } catch (View\Exception\ExceptionInterface $e) { - $this->assertContains('must set an instance of Zend\Translator', $e->getMessage()); - } - } - - public function testCanSetLocale() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', 'two %1\$s' => 'zwei %1\$s'), 'de'); - $trans->addTranslation(array('one' => 'uno', 'two %1\$s' => 'duo %2\$s'), 'it'); - $trans->setLocale('de'); - - $this->helper->setTranslator($trans); - $this->assertEquals('eins', $this->helper->__invoke('one')); - $new = $this->helper->setLocale('it'); - $this->assertTrue($new instanceof Helper\Translator); - $this->assertEquals('it', $new->getLocale()); - $this->assertEquals('uno', $this->helper->__invoke('one')); - } - - public function testHelperImplementsFluentInterface() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', 'two %1\$s' => 'zwei %1\$s'), 'de'); - $trans->addTranslation(array('one' => 'uno', 'two %1\$s' => 'duo %2\$s'), 'it'); - $trans->setLocale('de'); - - $locale = $this->helper->__invoke()->setTranslator($trans)->getLocale(); - - $this->assertEquals('de', $locale); - } - - public function testCanTranslateWithOptions() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', "two %1\$s" => "zwei %1\$s", - "three %1\$s %2\$s" => "drei %1\$s %2\$s"), 'de'); - $trans->addTranslation(array('one' => 'uno', "two %1\$s" => "duo %2\$s", - "three %1\$s %2\$s" => "tre %1\$s %2\$s"), 'it'); - $trans->setLocale('de'); - - $this->helper->setTranslator($trans); - $this->assertEquals("drei 100 200", $this->helper->__invoke("three %1\$s %2\$s", "100", "200")); - $this->assertEquals("tre 100 200", $this->helper->__invoke("three %1\$s %2\$s", "100", "200", 'it')); - $this->assertEquals("drei 100 it", $this->helper->translate("three %1\$s %2\$s", "100", "it")); - $this->assertEquals("drei 100 200", $this->helper->__invoke("three %1\$s %2\$s", array("100", "200"))); - $this->assertEquals("tre 100 200", $this->helper->__invoke("three %1\$s %2\$s", array("100", "200"), 'it')); - } - - public function testTranslationObjectNullByDefault() - { - $this->assertNull($this->helper->getTranslator()); - } - - public function testLocalTranslationObjectIsPreferredOverRegistry() - { - $transReg = new Translator\Translator('arrayAdapter', array('one' => 'eins')); - \Zend\Registry::set('Zend_Translator', $transReg); - - $this->assertSame($transReg->getAdapter(), $this->helper->getTranslator()); - - $transLoc = new Translator\Translator('arrayAdapter', array('one' => 'uno')); - $this->helper->setTranslator($transLoc); - $this->assertSame($transLoc->getAdapter(), $this->helper->getTranslator()); - $this->assertNotSame($transLoc->getAdapter(), $transReg->getAdapter()); - } - - public function testHelperObjectReturnedWhenNoArgumentsPassed() - { - $helper = $this->helper->__invoke(); - $this->assertSame($this->helper, $helper); - - $transLoc = new Translator\Translator('arrayAdapter', array('one' => 'eins')); - $this->helper->setTranslator($transLoc); - $helper = $this->helper->__invoke(); - $this->assertSame($this->helper, $helper); - } - - /** - * ZF-6724 - */ - public function testTranslationWithPercent() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', "two %1\$s" => "zwei %1\$s", - "three %1\$s %2\$s" => "drei %1\$s %2\$s", 'vier%ig' => 'four%'), 'de'); - $trans->setLocale('de'); - - $this->helper->setTranslator($trans); - $this->assertEquals("four%", $this->helper->__invoke("vier%ig")); - $this->assertEquals("zwei 100", $this->helper->__invoke("two %1\$s", "100")); - } - - /** - * ZF-7937 - */ - public function testTranslationWithoutTranslator() - { - $result = $this->helper->__invoke("test %1\$s", "100"); - $this->assertEquals('test 100', $result); - } - - /** - * @group ZF2-140 - */ - public function testSetTranslatorWithTranslationAdapter() - { - $trans = new Translator\Adapter\ArrayAdapter(array('one' => 'eins', "two %1\$s" => "zwei %1\$s", - "three %1\$s %2\$s" => "drei %1\$s %2\$s", 'vier%ig' => 'four%'), 'de'); - $this->helper->setTranslator($trans); - } - - /** - * @group ZF2-140 - */ - public function testSetTranslatorWithTranslation() - { - $trans = new Translator\Translator('arrayAdapter', array('one' => 'eins', "two %1\$s" => "zwei %1\$s", - "three %1\$s %2\$s" => "drei %1\$s %2\$s", 'vier%ig' => 'four%'), 'de'); - $this->helper->setTranslator($trans); - } -} diff --git a/test/Helper/UrlTest.php b/test/Helper/UrlTest.php index 524539a5..01d41687 100644 --- a/test/Helper/UrlTest.php +++ b/test/Helper/UrlTest.php @@ -1,28 +1,17 @@ assertFalse(isset($model->foo)); $this->assertFalse(isset($variables['foo'])); } + + public function testPropertyOverloadingAllowsWritingPropertiesAfterSetVariablesHasBeenCalled() + { + $model = new ViewModel(); + $model->setVariables(array('foo' => 'bar')); + $model->bar = 'baz'; + + $this->assertTrue(isset($model->bar)); + $this->assertEquals('baz', $model->bar); + $variables = $model->getVariables(); + $this->assertArrayHasKey('bar', $variables); + $this->assertEquals('baz', $variables['bar']); + } } diff --git a/test/PhpRendererTest.php b/test/PhpRendererTest.php index 3d2e2832..348e23e2 100644 --- a/test/PhpRendererTest.php +++ b/test/PhpRendererTest.php @@ -1,39 +1,26 @@ assertContains("
  • $value
  • ", $content); } } - + /** * @group ZF2-68 */ public function testCanSpecifyArrayForVarsAndGetAlwaysArrayObject() { $vars = array('foo' => 'bar'); - $this->renderer->setVars($vars); + $this->renderer->setVars($vars); $this->assertTrue($this->renderer->vars() instanceof Variables); } @@ -265,7 +252,7 @@ public function testRenderingLocalVariables() $this->renderer->resolver()->addPath(__DIR__ . '/_templates'); $test = $this->renderer->render('testLocalVars.phtml'); $this->assertContains($expected, $test); - } + } public function testRendersTemplatesInAStack() { diff --git a/test/Renderer/FeedRendererTest.php b/test/Renderer/FeedRendererTest.php index e1525c1a..eab1bfac 100644 --- a/test/Renderer/FeedRendererTest.php +++ b/test/Renderer/FeedRendererTest.php @@ -1,39 +1,26 @@ assertEquals($expected, $test); } - /** + /** * @dataProvider getNonObjectModels */ public function testRendersNonObjectModelAsJsonWithJsonpCallback($model) diff --git a/test/Renderer/TestAsset/JsonModel.php b/test/Renderer/TestAsset/JsonModel.php index 89883276..8210bdb6 100644 --- a/test/Renderer/TestAsset/JsonModel.php +++ b/test/Renderer/TestAsset/JsonModel.php @@ -1,22 +1,11 @@ headers()->addHeaderLine('Accept', 'application/rss+xml'); + $request->getHeaders()->addHeaderLine('Accept', 'application/rss+xml'); $this->event->setRequest($request); $result = $this->strategy->selectRenderer($this->event); $this->assertSame($this->renderer, $result); @@ -69,7 +56,7 @@ public function testRssAcceptHeaderSelectsFeedStrategy() public function testAtomAcceptHeaderSelectsFeedStrategy() { $request = new HttpRequest(); - $request->headers()->addHeaderLine('Accept', 'application/atom+xml'); + $request->getHeaders()->addHeaderLine('Accept', 'application/atom+xml'); $this->event->setRequest($request); $result = $this->strategy->selectRenderer($this->event); $this->assertSame($this->renderer, $result); @@ -85,7 +72,7 @@ public function testLackOfFeedModelOrAcceptHeaderDoesNotSelectFeedStrategy() protected function assertResponseNotInjected() { $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertTrue(empty($content)); $this->assertFalse($headers->has('content-type')); } @@ -125,12 +112,12 @@ public function testMatchingRendererAndStringResultInjectsResponse() $this->strategy->injectResponse($this->event); $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertEquals($expected, $content); $this->assertTrue($headers->has('content-type')); $this->assertEquals('application/atom+xml', $headers->get('content-type')->getFieldValue()); } - + protected function getFeedData($type) { return array( @@ -182,7 +169,7 @@ public function testMatchingRendererAndFeedResultInjectsResponse() $this->strategy->injectResponse($this->event); $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertEquals($expected->export('atom'), $content); $this->assertTrue($headers->has('content-type')); $this->assertEquals('application/atom+xml', $headers->get('content-type')->getFieldValue()); @@ -198,7 +185,7 @@ public function testResponseContentTypeIsBasedOnFeedType() $this->strategy->injectResponse($this->event); $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertEquals($expected->export('rss'), $content); $this->assertTrue($headers->has('content-type')); $this->assertEquals('application/rss+xml', $headers->get('content-type')->getFieldValue()); diff --git a/test/Strategy/JsonStrategyTest.php b/test/Strategy/JsonStrategyTest.php index 1a9f143f..cf2cce6b 100644 --- a/test/Strategy/JsonStrategyTest.php +++ b/test/Strategy/JsonStrategyTest.php @@ -1,44 +1,31 @@ headers()->addHeaderLine('Accept', 'application/json'); + $request->getHeaders()->addHeaderLine('Accept', 'application/json'); $this->event->setRequest($request); $result = $this->strategy->selectRenderer($this->event); $this->assertSame($this->renderer, $result); @@ -69,7 +56,7 @@ public function testJsonAcceptHeaderSelectsJsonStrategy() public function testJavascriptAcceptHeaderSelectsJsonStrategy() { $request = new HttpRequest(); - $request->headers()->addHeaderLine('Accept', 'application/javascript'); + $request->getHeaders()->addHeaderLine('Accept', 'application/javascript'); $this->event->setRequest($request); $result = $this->strategy->selectRenderer($this->event); $this->assertSame($this->renderer, $result); @@ -79,7 +66,7 @@ public function testJavascriptAcceptHeaderSelectsJsonStrategy() public function testJavascriptAcceptHeaderSelectsJsonStrategyAndSetsJsonpCallback() { $request = new HttpRequest(); - $request->headers()->addHeaderLine('Accept', 'application/javascript'); + $request->getHeaders()->addHeaderLine('Accept', 'application/javascript'); $request->setQuery(new Parameters(array('callback' => 'foo'))); $this->event->setRequest($request); $result = $this->strategy->selectRenderer($this->event); @@ -97,7 +84,7 @@ public function testLackOfJsonModelOrAcceptHeaderDoesNotSelectJsonStrategy() protected function assertResponseNotInjected() { $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertTrue(empty($content)); $this->assertFalse($headers->has('content-type')); } @@ -136,7 +123,7 @@ public function testMatchingRendererAndStringResultInjectsResponse() $this->strategy->injectResponse($this->event); $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertEquals($expected, $content); $this->assertTrue($headers->has('content-type')); $this->assertEquals('application/json', $headers->get('content-type')->getFieldValue()); @@ -152,7 +139,7 @@ public function testMatchingRendererAndStringResultInjectsResponseJsonp() $this->strategy->injectResponse($this->event); $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertEquals($expected, $content); $this->assertTrue($headers->has('content-type')); $this->assertEquals('application/javascript', $headers->get('content-type')->getFieldValue()); @@ -190,7 +177,7 @@ public function testAttachesListenersAtExpectedPriorities() $this->assertTrue($found, 'Listener not found'); } } - + public function testCanAttachListenersAtSpecifiedPriority() { $events = new EventManager(); diff --git a/test/Strategy/PhpRendererStrategyTest.php b/test/Strategy/PhpRendererStrategyTest.php index f91b36a1..ac5dc30f 100644 --- a/test/Strategy/PhpRendererStrategyTest.php +++ b/test/Strategy/PhpRendererStrategyTest.php @@ -1,52 +1,36 @@ offsetUnset(PlaceholderRegistry::REGISTRY_KEY); - } + PlaceholderRegistry::unsetRegistry(); $this->renderer = new PhpRenderer; $this->strategy = new PhpRendererStrategy($this->renderer); @@ -63,7 +47,7 @@ public function testSelectRendererAlwaysSelectsPhpRenderer() protected function assertResponseNotInjected() { $content = $this->response->getContent(); - $headers = $this->response->headers(); + $headers = $this->response->getHeaders(); $this->assertTrue(empty($content)); $this->assertFalse($headers->has('content-type')); } @@ -82,7 +66,7 @@ public function testNonMatchingRendererDoesNotInjectResponse() $this->strategy->injectResponse($this->event); $this->assertResponseNotInjected(); } - + public function testResponseContentSetToContentPlaceholderWhenResultAndArticlePlaceholderAreEmpty() { $this->renderer->placeholder('content')->set('Content'); @@ -155,7 +139,7 @@ public function testAttachesListenersAtExpectedPriorities() $this->assertTrue($found, 'Listener not found'); } } - + public function testCanAttachListenersAtSpecifiedPriority() { $events = new EventManager(); diff --git a/test/TemplatePathStackTest.php b/test/TemplatePathStackTest.php index 2c14efd4..d277a0f3 100644 --- a/test/TemplatePathStackTest.php +++ b/test/TemplatePathStackTest.php @@ -1,22 +1,11 @@ stack->addPath($path); - $test = $this->stack->resolve('foo/hello.phtml'); - $this->assertEquals($path . '/foo/hello.phtml', $test); + $test = $this->stack->resolve('foo' . DIRECTORY_SEPARATOR . 'hello.phtml'); + $this->assertEquals($path . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'hello.phtml', $test); } public function testDefaultFileSuffixIsPhtml() diff --git a/test/TestAsset/Invokable.php b/test/TestAsset/Invokable.php index 63b3c849..3c8aa72d 100644 --- a/test/TestAsset/Invokable.php +++ b/test/TestAsset/Invokable.php @@ -1,39 +1,24 @@ view = $view; - } - - /** - * Get the View object - * - * @return Renderer - */ - public function getView() - { - return $this->view; - } - /** * Invokable functor - * - * @param string $message + * + * @param string $message * @return string */ public function __invoke($message) diff --git a/test/TestAsset/Renderer/VarExportRenderer.php b/test/TestAsset/Renderer/VarExportRenderer.php index eae680e3..3091cfa9 100644 --- a/test/TestAsset/Renderer/VarExportRenderer.php +++ b/test/TestAsset/Renderer/VarExportRenderer.php @@ -1,36 +1,23 @@ view = $view; - return $this; - } - - /** - * Get the View object - * - * @return Renderer - */ - public function getView() - { - return $this->view; - } -} +class Uninvokable extends Helper +{ } diff --git a/test/TestAsset/VariableFunctor.php b/test/TestAsset/VariableFunctor.php index c4b72ee8..e61925f2 100644 --- a/test/TestAsset/VariableFunctor.php +++ b/test/TestAsset/VariableFunctor.php @@ -1,22 +1,11 @@