Skip to content
Browse files

adding more tests and refactoring `\template`. Most of the changes ar…

…e in `\template\helper`
  • Loading branch information...
1 parent c11e0e4 commit f8d75ca0b84deca60e23df4c5226e5339bb2e0e1 @gwoo gwoo committed
View
26 libraries/lithium/template/Helper.php
@@ -86,6 +86,20 @@ public function escape($value, $method = null, array $options = array()) {
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
+ /**
+ * Takes the defaults and current options, merges them and returns options which have
+ * the default keys removed and full set of options as the scope.
+ *
+ * @param array $defaults
+ * @param array $scope the complete set of options
+ * @return array $scope, $options
+ */
+ protected function _options(array $defaults, array $scope) {
+ $scope += $defaults;
+ $options = array_diff_key($scope, $defaults);
+ return array($scope, $options);
+ }
+
protected function _render($method, $string, $params, array $options = array()) {
foreach ($params as $key => $value) {
$params[$key] = $this->_context->applyHandler($this, $method, $key, $value, $options);
@@ -98,11 +112,9 @@ protected function _attributes($params, $method = null, array $options = array()
if (!is_array($params)) {
return empty($params) ? '' : ' ' . $params;
}
-
$defaults = array('escape' => true, 'prepend' => ' ', 'append' => '');
$options += $defaults;
$result = array();
-
foreach ($params as $key => $value) {
$result[] = $this->_formatAttr($key, $value, $options);
}
@@ -110,23 +122,21 @@ protected function _attributes($params, $method = null, array $options = array()
}
protected function _formatAttr($key, $value, array $options = array()) {
- $defaults = array('escape' => true);
+ $defaults = array('escape' => true, 'format' => '%s="%s"');
$options += $defaults;
- $format = '%s="%s"';
- $value = (string) $value;
-
if (in_array($key, $this->_minimized)) {
$isMini = ($value == 1 || $value === true || $value === 'true' || $value == $key);
if (!($value = $isMini ? $key : $value)) {
return null;
}
}
+ $value = (string) $value;
if ($options['escape']) {
- return sprintf($format, $this->escape($key), $this->escape($value));
+ return sprintf($options['format'], $this->escape($key), $this->escape($value));
}
- return sprintf($format, $key, $value);
+ return sprintf($options['format'], $key, $value);
}
}
View
80 libraries/lithium/template/helper/Form.php
@@ -45,7 +45,7 @@ class Form extends \lithium\template\Helper {
'error' => '<div{:options}>{:content}</div>',
'errors' => '{:content}',
'file' => '<input type="file" name="{:name}"{:options} />',
- 'form' => '<form action="{:url}"{:options}>',
+ 'form' => '<form action="{:url}"{:options}>{:content}',
'form-end' => '</form>',
'hidden' => '<input type="hidden" name="{:name}"{:options} />',
'field' => '<div{:wrap}>{:label}{:input}{:error}</div>',
@@ -55,7 +55,7 @@ class Form extends \lithium\template\Helper {
'option-group' => '<optgroup label="{:label}"{:options}>',
'option-group-end' => '</optgroup>',
'password' => '<input type="password" name="{:name}"{:options} />',
- 'radio' => '<input type="radio" name="{:name}" id="{:id}"{:options} />{:label}',
+ 'radio' => '<input type="radio" name="{:name}" id="{:id}"{:options} />{:label}',
'select-start' => '<select name="{:name}"{:options}>',
'select-multi-start' => '<select name="{:name}[]"{:options}>',
'select-empty' => '<option value=""{:options}>&nbsp;</option>',
@@ -184,39 +184,38 @@ public function create($binding = null, array $options = array()) {
'method' => $binding ? ($binding->exists() ? 'put' : 'post') : 'post'
);
list(, $options, $template) = $this->_defaults(__FUNCTION__, null, $options);
- $options = (array) $options + $defaults;
+ list($scope, $options) = $this->_options($defaults, $options);
+
$_binding =& $this->_binding;
$method = __METHOD__;
- $params = compact('binding', 'options');
+ $params = compact('scope', 'options', 'binding');
$filter = function($self, $params, $chain) use ($method, $template, $defaults, &$_binding) {
- extract($params);
- $_binding = $binding;
- $append = '';
-
- if ($options['type'] == 'file') {
- if (strtolower($options['method']) == 'get') {
- $options['method'] = 'post';
+ $scope = $params['scope'];
+ $options = $params['options'];
+ $_binding = $params['binding'];
+ $content = null;
+
+ if (!in_array(strtolower($scope['method']), array('get', 'post'))) {
+ $content = $self->hidden('_method', array(
+ 'name' => '_method', 'value' => strtoupper($scope['method'])
+ ));
+ }
+ if ($scope['type'] == 'file') {
+ if (strtolower($scope['method']) == 'get') {
+ $scope['method'] = 'post';
}
$options['enctype'] = 'multipart/form-data';
}
- unset($options['type']);
- if (!in_array(strtolower($options['method']), array('get', 'post'))) {
- $append .= $self->hidden('_method', array(
- 'name' => '_method', 'value' => strtoupper($options['method'])
- ));
- }
-
- $url = $options['action'] ? array('action' => $options['action']) : $options['url'];
- unset($options['url'], $options['action']);
- $options['method'] = strtoupper($options['method']);
+ $url = $scope['action'] ? array('action' => $scope['action']) : $scope['url'];
+ $options['method'] = strtoupper($scope['method']);
return $self->invokeMethod('_render', array(
- $method, $template, compact('url', 'options')
+ $method, $template, compact('url', 'content', 'options')
));
};
- return $this->_filter(__METHOD__, $params, $filter);
+ return $this->_filter($method, $params, $filter);
}
public function end() {
@@ -253,7 +252,7 @@ public function field($name, array $options = array()) {
'wrap' => null,
'list' => null
);
- $options += $defaults;
+ list($options, $fieldOptions) = $this->_options($defaults, $options);
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
if ($options['template'] != $defaults['template']) {
@@ -266,7 +265,6 @@ public function field($name, array $options = array()) {
if ($options['label'] === null || !empty($options['label'])) {
$label = $this->label($name, $options['label']);
}
- $fieldOptions = array_diff_key($options, $defaults);
switch (true) {
case ($type == 'select'):
@@ -303,8 +301,8 @@ public function submit($title = null, array $options = array()) {
*/
public function textarea($name, array $options = array()) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
- $value = isset($options['value']) ? $options['value'] : '';
- unset($options['value']);
+ list($scope, $options) = $this->_options(array('value' => null), $options);
+ $value = isset($scope['value']) ? $scope['value'] : '';
return $this->_render(__METHOD__, $template, compact('name', 'options', 'value'));
}
@@ -343,24 +341,20 @@ public function text($name, array $options = array()) {
public function select($name, $list = array(), array $options = array()) {
$defaults = array('empty' => false, 'value' => null);
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
+ list($scope, $options) = $this->_options($defaults, $options);
- $options += $defaults;
- $val = $options['value'];
- $empty = $options['empty'];
- unset($options['value'], $options['empty']);
-
- if ($empty) {
- $list = array('' => ($empty === true) ? '' : $empty) + $list;
+ if ($scope['empty']) {
+ $list = array('' => ($scope['empty'] === true) ? '' : $scope['empty']) + $list;
}
- $startTemplate = ($options['multiple']) ? 'select-multi-start' : 'select-start';
+ $startTemplate = ($scope['multiple']) ? 'select-multi-start' : 'select-start';
$output = $this->_render(__METHOD__, $startTemplate, compact('name', 'options'));
foreach ($list as $value => $title) {
$selected = false;
- if (is_array($val) && in_array($value, $val)) {
+ if (is_array($scope['value']) && in_array($value, $scope['value'])) {
$selected = true;
- } elseif ($val == $value) {
+ } elseif ($scope['value'] == $value) {
$selected = true;
}
$options = $selected ? array('selected' => true) : array();
@@ -381,11 +375,11 @@ public function select($name, $list = array(), array $options = array()) {
*/
public function checkbox($name, array $options = array()) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
+ list($scope, $options) = $this->_options(array('value' => null), $options);
- if (!isset($options['checked'])) {
- $options['checked'] = isset($options['value']) ? $options['value'] : false;
+ if (!isset($scope['checked'])) {
+ $options['checked'] = isset($scope['value']) ? $scope['value'] : false;
}
- unset($options['value']);
return $this->_render(__METHOD__, $template, compact('name', 'options'));
}
@@ -422,9 +416,13 @@ public function hidden($name, array $options = array()) {
* @return string Returns a `<label>` tag for the name and with HTML attributes.
*/
public function label($name, $title = null, array $options = array()) {
+ $defaults = array('escape' => true);
$title = $title ?: Inflector::humanize($name);
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
- return $this->_render(__METHOD__, $template, compact('name', 'title', 'options'));
+ list($scope, $options) = $this->_options($defaults, $options);
+ return $this->_render(
+ __METHOD__, $template, compact('name', 'title', 'options'), $scope
+ );
}
/**
View
103 libraries/lithium/template/helper/Html.php
@@ -57,7 +57,7 @@ class Html extends \lithium\template\Helper {
*/
protected $_metaLinks = array(
'atom' => array('type' => 'application/atom+xml', 'rel' => 'alternate'),
- 'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate'),
+ 'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate'),
'icon' => array('type' => 'image/x-icon', 'rel' => 'icon')
);
@@ -101,23 +101,20 @@ public function charset($charset = null) {
* applcation, an external URL (starts with `'http://'` or `'https://'`), an anchor
* name starting with `'#'` (i.e. `'#top'`), or an array defining a set of request
* parameters that should be matched against a route in `Router`.
- * @param array $options Array of HTML attributes.
+ * @param array $options Array of HTML s and other options.
* @return string Returns an `<a />` or `<link />` element.
*/
public function link($title, $url = null, array $options = array()) {
- $defaults = array('escape' => true);
- $options += $defaults;
+ $defaults = array('escape' => true, 'type' => null);
+ list($scope, $options) = $this->_options($defaults, $options);
- if (isset($options['type']) && $type = $options['type']) {
- unset($options['type']);
- $options = array_diff_key($options, $defaults) + compact('title');
+ if (isset($scope['type']) && $type = $scope['type']) {
+ $options += compact('title');
return $this->_metaLink($type, $url, $options);
}
$url = is_null($url) ? $title : $url;
- $params = $options;
- $options = array_diff_key($options, $defaults);
- return $this->_render(__METHOD__, 'link', compact('title', 'url', 'options'), $params);
+ return $this->_render(__METHOD__, 'link', compact('title', 'url', 'options'), $scope);
}
/**
@@ -128,25 +125,25 @@ public function link($title, $url = null, array $options = array()) {
* @param mixed $path String path to JavaScript file, or an array of paths.
* @param array $options
* @return string
+ * @filter This method can be filtered.
*/
public function script($path, array $options = array()) {
$defaults = array('inline' => true);
- $options += $defaults;
- $m = __METHOD__;
+ list($scope, $options) = $this->_options($defaults, $options);
if (is_array($path)) {
foreach ($path as $i => $item) {
- $path[$i] = $this->script($item, $options);
+ $path[$i] = $this->script($item, $scope);
}
- return ($options['inline']) ? join("\n\t", $path) . "\n" : null;
+ return ($scope['inline']) ? join("\n\t", $path) . "\n" : null;
}
- $params = compact('path') + array('options' => array_diff_key($options, $defaults));
+ $m = __METHOD__;
+ $params = compact('path', 'options');
$script = $this->_filter(__METHOD__, $params, function($self, $params, $chain) use ($m) {
return $self->invokeMethod('_render', array($m, 'script', $params));
});
-
- if ($options['inline']) {
+ if ($scope['inline']) {
return $script;
}
if ($this->_context) {
@@ -165,28 +162,24 @@ public function script($path, array $options = array()) {
*/
public function style($path, array $options = array()) {
$defaults = array('type' => 'stylesheet', 'inline' => true);
- $options += $defaults;
+ list($scope, $options) = $this->_options($defaults, $options);
if (is_array($path)) {
foreach ($path as $i => $item) {
- $path[$i] = $this->style($item, $options);
+ $path[$i] = $this->style($item, $scope);
}
- return ($options['inline']) ? join("\n\t", $path) . "\n" : null;
+ return ($scope['inline']) ? join("\n\t", $path) . "\n" : null;
}
- $params = compact('path', 'options');
$method = __METHOD__;
-
+ $type = $scope['type'];
+ $params = compact('type', 'path', 'options');
$filter = function($self, $params, $chain) use ($defaults, $method) {
- extract($params);
- $type = $options['type'];
- $options = array_diff_key($options, $defaults);
- $template = ($type == 'import') ? 'style-import' : 'style-link';
- $params = compact('type', 'path', 'options');
+ $template = ($params['type'] == 'import') ? 'style-import' : 'style-link';
return $self->invokeMethod('_render', array($method, $template, $params));
};
- $style = $this->_filter(__METHOD__, $params, $filter);
+ $style = $this->_filter($method, $params, $filter);
- if ($options['inline']) {
+ if ($scope['inline']) {
return $style;
}
if ($this->_context) {
@@ -200,8 +193,9 @@ public function style($path, array $options = array()) {
* @param string $path Path to the image file, relative to the app/webroot/img/ directory.
* @param array $options Array of HTML attributes.
* @return string
+ * @filter This method can be filtered.
*/
- public function image($path, array $options = array()) {
+ public function image($path, array $options = array()) {
$defaults = array('alt' => '');
$options += $defaults;
$path = is_array($path) ? $this->_context->url($path) : $path;
@@ -217,49 +211,20 @@ public function image($path, array $options = array()) {
* Returns a formatted block tag, i.e <div />, <span />, <p />.
*
* @param string $name Tag name.
+ * @param string $class the css class for the given tag
* @param string $content String content that will appear inside the div element.
- * If null, only a start tag will be printed
+ * If null, only a start tag will be printed
* @param array $options Additional HTML attributes of the DIV tag
* @return string The formatted tag element
*/
- function tag($name, $content = null, $options = array()) {
- $options = is_array($options) ? $options : array('class' => $options);
- return $this->_render(__METHOD__, ($content === null) ? 'tag-start' : 'tag', compact(
- 'name', 'options', 'content'
- ));
- }
-
- /**
- * Returns a formatted DIV tag for HTML FORMs.
- *
- * @param string $class CSS class name of the div element.
- * @param string $content String content that will appear inside the div element.
- * If null, only a start tag will be printed
- * @param array $options Additional HTML attributes of the DIV tag
- * @return string The formatted DIV element
- */
- function block($class = null, $content = null, array $options = array()) {
- if ($class) {
- $options['class'] = $class;
- }
- return $this->_render(__METHOD__, 'block', compact('content', 'options'));
- }
+ function tag($name, $class, $content = null, array $options = array()) {
+ $defaults = array('escape' => true);
+ list($scope, $options) = $this->_options($defaults, $options += compact('class'));
- /**
- * Returns a formatted P tag.
- *
- * @param string $class CSS class name of the p element.
- * @param string $content String content that will appear inside the p element.
- * @param array $options Additional HTML attributes of the P tag
- * @return string The formatted P element
- */
- function para($class, $content, array $options = array()) {
- if ($class) {
- $options['class'] = $class;
- }
- return $this->_render(__METHOD__, ($content === null) ? 'para-start' : 'para', compact(
- 'content', 'options'
- ));
+ return $this->_render(
+ __METHOD__, ($content === null) ? 'tag-start' : 'tag',
+ compact('name', 'options', 'content'), $scope
+ );
}
/**
@@ -280,13 +245,11 @@ protected function _metaLink($type, $url = null, array $options = array()) {
'handlers' => array('url' => 'path')
));
$options['rel'] = 'shortcut icon';
-
$ieFix = $this->_render(__METHOD__, 'meta-link', compact('url', 'options'), array(
'handlers' => array('url' => 'path')
));
return "{$standard}\n\t{$ieFix}";
}
-
return $this->_render(__METHOD__, 'meta-link', compact('url', 'options'), array(
'handlers' => array()
));
View
39 libraries/lithium/template/view/Renderer.php
@@ -46,8 +46,8 @@
* `Renderer`'s dependencies. These classes are used by the output handlers to generate URLs
* for dynamic resources and static assets.
*
- * @var array
* @see Renderer::$_handlers
+ * @var array
*/
protected $_classes = array(
'router' => 'lithium\net\http\Router',
@@ -82,9 +82,9 @@
* helper method renders a template string (using `_render()`) and a key which is to be embedded
* in the template string matches an array key of a corresponding handler.
*
- * @var array
* @see lithium\template\view\Renderer::applyHandler()
* @see lithium\template\view\Renderer::handlers()
+ * @var array
*/
protected $_handlers = array();
@@ -98,6 +98,22 @@
*/
protected $_data = array();
+ /**
+ * Render the template with given data.
+ * Abstract. Must be added to subclasses.
+ *
+ * @param string $template
+ * @param string $data
+ * @param array $options
+ * @return void
+ */
+ abstract public function render($template, $data = array(), array $options = array());
+
+ /**
+ * undocumented function
+ *
+ * @param array $config
+ */
public function __construct(array $config = array()) {
$defaults = array(
'view' => null,
@@ -147,8 +163,6 @@ protected function _init() {
unset($this->_config['view']);
}
- abstract public function render($template, $data = array(), array $options = array());
-
public function __isSet($property) {
return isset($this->_context[$property]);
}
@@ -177,13 +191,13 @@ public function __get($property) {
* `$method` is a key in `Renderer::$_handlers`, the value passed as the first parameter in the
* method call will be passed through the handler and returned.
*
+ * @see lithium\template\view\Renderer::$_context
+ * @see lithium\template\view\Renderer::$_handlers
+ * @see lithium\template\view\Renderer::applyHandler()
* @param string $method The method name to call, usually either a rendering context value or a
* content handler.
* @param array $params
* @return mixed
- * @see lithium\template\view\Renderer::$_context
- * @see lithium\template\view\Renderer::$_handlers
- * @see lithium\template\view\Renderer::applyHandler()
*/
public function __call($method, $params) {
if (!isset($this->_context[$method]) && !isset($this->_handlers[$method])) {
@@ -242,11 +256,11 @@ public function strings($strings = null) {
* across all templates rendered in the current context, and are usually outputted in a layout
* template.
*
+ * @see lithium\template\view\Renderer::$_context
* @param string $property If unspecified, an associative array of all context values is
* returned. If a string is specified, the context value matching the name given
* will be returned, or `null` if that name does not exist.
* @return mixed A string or array, depending on whether `$property` is specified.
- * @see lithium\template\view\Renderer::$_context
*/
public function context($property = null) {
if (!empty($property)) {
@@ -260,6 +274,8 @@ public function context($property = null) {
* `$handlers`. For more on how to implement handlers and the various types, see
* `applyHandler()`.
*
+ * @see lithium\template\view\Renderer::applyHandler()
+ * @see lithium\template\view\Renderer::$_handlers
* @param mixed $handlers If `$handlers` is empty or no value is provided, the current list
* of handlers is returned. If `$handlers` is a string, the handler with the name
* matching the string will be returned, or null if one does not exist. If
@@ -268,8 +284,6 @@ public function context($property = null) {
* taking precedence over those newly added.
* @return mixed Returns an array of handlers or a single handler reference, depending on the
* value of `$handlers`.
- * @see lithium\template\view\Renderer::applyHandler()
- * @see lithium\template\view\Renderer::$_handlers
*/
public function handlers($handlers = null) {
if (is_array($handlers)) {
@@ -293,6 +307,8 @@ public function handlers($handlers = null) {
* the calling helper and the calling method name as the second, and `$options` as the third.
* In all cases, handlers should return the transformed version of `$value`.
*
+ * @see lithium\template\view\Renderer::handlers()
+ * @see lithium\template\view\Renderer::$_handlers
* @param object $helper The instance of the object (usually a helper) that is invoking
* @param string $method The object (helper) method which is applying the handler to the content
* @param string $name The name of the value to which the handler is applied, i.e. `'url'`,
@@ -300,14 +316,11 @@ public function handlers($handlers = null) {
* @param mixed $value The value to be transformed by the handler, which is ultimately returned.
* @param array $options Any options which should be passed to the handler used in this call.
* @return mixed The transformed value of `$value`, after it has been processed by a handler.
- * @see lithium\template\view\Renderer::handlers()
- * @see lithium\template\view\Renderer::$_handlers
*/
public function applyHandler($helper, $method, $name, $value, array $options = array()) {
if (!(isset($this->_handlers[$name]) && $handler = $this->_handlers[$name])) {
return $value;
}
-
switch (true) {
case is_string($handler) && is_object($helper):
return $helper->invokeMethod($handler, array($value, $method, $options));
View
5 libraries/lithium/template/view/adapter/Simple.php
@@ -20,11 +20,6 @@
*/
class Simple extends \lithium\template\view\Renderer {
- public function __construct(array $config = array()) {
- $defaults = array('classes' => array());
- parent::__construct($config + $defaults);
- }
-
/**
* Renders content from a template file provided by `template()`.
*
View
43 libraries/lithium/tests/cases/template/HelperTest.php
@@ -31,9 +31,8 @@ public function testObjectConstructionWithParameters() {
'context' => new MockRenderer(),
'handlers' => array('content' => function($value) { return "\n{$value}\n"; })
);
- $this->helper = new MockHelper($params);
-
- $this->assertEqual($this->helper->_context, $params['context']);
+ $helper = new MockHelper($params);
+ $this->assertEqual($helper->_context, $params['context']);
}
/**
@@ -65,6 +64,44 @@ public function testUnescapedValue() {
$result = $this->helper->escape($value, null, array('escape' => false));
$this->assertEqual($value, $result);
}
+
+ public function testOptions() {
+ $defaults = array('value' => null);
+ $options = array('value' => 1, 'title' => 'one');
+ $expected = array(
+ array('value' => 1, 'title' => 'one'),
+ array('title' => 'one')
+ );
+ $result = $this->helper->testOptions($defaults, $options);
+ $this->assertEqual($expected, $result);
+ }
+
+ public function testAttributes() {
+ $attributes = array('value' => 1, 'title' => 'one');
+ $expected = ' value="1" title="one"';
+ $result = $this->helper->testAttributes($attributes);
+ $this->assertEqual($expected, $result);
+
+ $attributes = array('checked' => true, 'title' => 'one');
+ $expected = ' checked="checked" title="one"';
+ $result = $this->helper->testAttributes($attributes);
+ $this->assertEqual($expected, $result);
+ }
+
+ public function testRender() {
+ $params = array(
+ 'context' => new MockRenderer(),
+ 'handlers' => array('content' => function($value) { return "\n{$value}\n"; })
+ );
+ $helper = new MockHelper($params);
+ $title = 'cool';
+ $url = '/here';
+ $options = array('value' => 1, 'title' => 'one');
+
+ $expected = '<a href="/here" value="1" title="one">cool</a>';
+ $result = $helper->testRender('link', 'link', compact('title', 'url', 'options'));
+ $this->assertEqual($expected, $result);
+ }
}
?>
View
22 libraries/lithium/tests/cases/template/helper/FormTest.php
@@ -74,12 +74,16 @@ public function testFormCreation() {
$result = $this->form->create(null, array('type' => 'file'));
$this->assertTags($result, array('form' => array(
- 'action' => "{$this->base}posts/add", 'method' => 'POST', 'enctype' => 'multipart/form-data'
+ 'action' => "{$this->base}posts/add",
+ 'enctype' => 'multipart/form-data',
+ 'method' => 'POST',
)));
$result = $this->form->create(null, array('method' => 'GET', 'type' => 'file'));
$this->assertTags($result, array('form' => array(
- 'action' => "{$this->base}posts/add", 'method' => 'POST', 'enctype' => 'multipart/form-data'
+ 'action' => "{$this->base}posts/add",
+ 'method' => 'POST',
+ 'enctype' => 'multipart/form-data'
)));
}
@@ -96,7 +100,9 @@ public function testRestFormCreation() {
$result = $this->form->create(null, array('method' => 'put', 'type' => 'file'));
$this->assertTags($result, array('form' => array(
- 'action' => "{$this->base}posts/add", 'method' => 'PUT', 'enctype' => 'multipart/form-data'
+ 'action' => "{$this->base}posts/add",
+ 'method' => 'PUT',
+ 'enctype' => 'multipart/form-data'
)));
}
@@ -110,7 +116,6 @@ public function testFormCreationWithBinding() {
'body' => 'This is the body of the saved post'
)
));
-
$result = $this->form->create($record);
}
@@ -219,6 +224,15 @@ public function testLabelGeneration() {
));
}
+ public function testLabelGenerationWithNoEscape() {
+ $result = $this->form->label('next', 'Enter the next value >>', array('escape' => false));
+ $this->assertTags($result, array(
+ 'label' => array('for' => 'next'),
+ 'Enter the next value >>',
+ '/label'
+ ));
+ }
+
public function testSubmitGeneration() {
$result = $this->form->submit('Continue >');
$this->assertTags($result, array('input' => array(
View
106 libraries/lithium/tests/cases/template/helper/HtmlTest.php
@@ -82,7 +82,6 @@ public function testMetaLink() {
array('controller' => 'posts', 'type' => 'rss'),
array('type' => 'rss')
);
-
$this->assertTags($result, array('link' => array(
'href' => 'regex:/.*\/posts\/index\.rss/',
'type' => 'application/rss+xml',
@@ -306,7 +305,6 @@ public function testImageLinking() {
* @return void
*/
function testImage() {
-
$result = $this->html->image('test.gif');
$this->assertTags($result, array('img' => array('src' => '/img/test.gif', 'alt' => '')));
@@ -346,60 +344,6 @@ public function testStyleLink() {
$result = $this->html->style('http://whatever.com/screen.css?1234');
$expected['link']['href'] = 'regex:/http:\/\/.*\/screen\.css\?1234/';
$this->assertTags($result, $expected);
-
-// Configure::write('Asset.filter.css', 'css.php');
-// $result = $this->html->style('lithium.generic');
-// $expected['link']['href'] = 'regex:/.*ccss\/lithium\.generic\.css/';
-// $this->assertTags($result, $expected);
-// Configure::write('Asset.filter.css', false);
-//
-// $result = explode("\n", trim($this->html->style(array('lithium.generic', 'vendor.generic'))));
-// $expected['link']['href'] = 'regex:/.*css\/lithium\.generic\.css/';
-// $this->assertTags($result[0], $expected);
-// $expected['link']['href'] = 'regex:/.*css\/vendor\.generic\.css/';
-// $this->assertTags($result[1], $expected);
-// $this->assertEqual(count($result), 2);
-//
-// Configure::write('Asset.timestamp', true);
-//
-// Configure::write('Asset.filter.css', 'css.php');
-// $result = $this->html->style('lithium.generic');
-// $expected['link']['href'] = 'regex:/.*ccss\/lithium\.generic\.css\?[0-9]+/';
-// $this->assertTags($result, $expected);
-// Configure::write('Asset.filter.css', false);
-//
-// $result = $this->html->style('lithium.generic');
-// $expected['link']['href'] = 'regex:/.*css\/lithium\.generic\.css\?[0-9]+/';
-// $this->assertTags($result, $expected);
-//
-// $debug = Configure::read('debug');
-// Configure::write('debug', 0);
-//
-// $result = $this->html->style('lithium.generic');
-// $expected['link']['href'] = 'regex:/.*css\/lithium\.generic\.css/';
-// $this->assertTags($result, $expected);
-//
-// Configure::write('Asset.timestamp', 'force');
-//
-// $result = $this->html->style('lithium.generic');
-// $expected['link']['href'] = 'regex:/.*css\/lithium\.generic\.css\?[0-9]+/';
-// $this->assertTags($result, $expected);
-//
-// $webroot = $this->html->webroot;
-// $this->html->webroot = '/testing/';
-// $result = $this->html->style('lithium.generic');
-// $expected['link']['href'] = 'regex:/\/testing\/css\/lithium\.generic\.css\?/';
-// $this->assertTags($result, $expected);
-// $this->html->webroot = $webroot;
-//
-// $webroot = $this->html->webroot;
-// $this->html->webroot = '/testing/longer/';
-// $result = $this->html->style('lithium.generic');
-// $expected['link']['href'] = 'regex:/\/testing\/longer\/css\/lithium\.generic\.css\?/';
-// $this->assertTags($result, $expected);
-// $this->html->webroot = $webroot;
-//
-// Configure::write('debug', $debug);
}
/**
@@ -474,46 +418,27 @@ public function testMultiNonInlineScriptsAndStyles() {
$this->assertTags($result, $expected);
}
-
- /**
- * Tests arbitrary tag generation.
- *
- * @return void
- */
- public function testTag() {
- $result = $this->html->tag('div');
- $this->assertTags($result, '<div');
-
- $result = $this->html->tag('div', 'text');
- $this->assertTags($result, '<div', 'text', '/div');
-
- $result = $this->html->tag('div', '<text>', array('class' => 'class-name'), true);
- $this->assertTags($result, array(
- 'div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'
- ));
-
- $result = $this->html->tag('div', '<text>', 'class-name', true);
- $this->assertTags($result, array(
- 'div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'
- ));
- }
-
/**
* Tests generation of block-level element (<div />).
*
* @return void
*/
- public function testBlock() {
- $result = $this->html->block('class-name');
+ public function testDivBlock() {
+ $result = $this->html->tag('div', 'class-name');
$this->assertTags($result, array('div' => array('class' => 'class-name')));
- $result = $this->html->block('class-name', 'text');
+ $result = $this->html->tag('div', 'class-name', 'text');
$this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div'));
- $result = $this->html->block('class-name', '<text>', array(), true);
+ $result = $this->html->tag('div', 'class-name', '<text>');
$this->assertTags($result, array(
'div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'
));
+
+ $result = $this->html->tag('div', 'class-name', '&text', array('escape' => false));
+ $this->assertTags($result, array(
+ 'div' => array('class' => 'class-name'), '&text', '/div'
+ ));
}
/**
@@ -521,17 +446,22 @@ public function testBlock() {
*
* @return void
*/
- function testPara() {
- $result = $this->html->para('class-name', '');
+ function testPTag() {
+ $result = $this->html->tag('p', 'class-name');
$this->assertTags($result, array('p' => array('class' => 'class-name')));
- $result = $this->html->para('class-name', 'text');
+ $result = $this->html->tag('p', 'class-name', 'text');
$this->assertTags($result, array('p' => array('class' => 'class-name'), 'text', '/p'));
- $result = $this->html->para('class-name', '<text>', array(), true);
+ $result = $this->html->tag('p', 'class-name', '<text>');
$this->assertTags($result, array(
'p' => array('class' => 'class-name'), '&lt;text&gt;', '/p'
));
+
+ $result = $this->html->tag('p', 'class-name', '&text', array('escape' => false));
+ $this->assertTags($result, array(
+ 'p' => array('class' => 'class-name'), '&text', '/p'
+ ));
}
}
View
4 libraries/lithium/tests/cases/template/view/RendererTest.php
@@ -85,7 +85,9 @@ public function testHandlerInsertion() {
$foo = function($value) { return "Foo: {$value}"; };
- $expected = array('url', 'path', 'options', 'content', 'title', 'scripts', 'styles', 'foo');
+ $expected = array(
+ 'url', 'path', 'options', 'content', 'title', 'scripts', 'styles', 'foo'
+ );
$result = array_keys($this->subject->handlers(compact('foo')));
$this->assertEqual($expected, $result);
View
13 libraries/lithium/tests/mocks/template/MockHelper.php
@@ -10,6 +10,7 @@
class MockHelper extends \lithium\template\Helper {
+ protected $_strings = array('link' => '<a href="{:url}"{:options}>{:title}</a>');
/**
* Hack to expose protected properties for testing.
*
@@ -19,6 +20,18 @@ class MockHelper extends \lithium\template\Helper {
public function __get($property) {
return isset($this->{$property}) ? $this->{$property} : null;
}
+
+ public function testOptions($defaults, $options) {
+ return $this->_options($defaults, $options);
+ }
+
+ public function testAttributes($params, $method = null, array $options = array()) {
+ return $this->_attributes($params, $method, $options);
+ }
+
+ public function testRender($method, $string, $params, array $options = array()) {
+ return $this->_render($method, $string, $params, $options);
+ }
}
?>

0 comments on commit f8d75ca

Please sign in to comment.
Something went wrong with that request. Please try again.