Merge remote branch 'origin/2.0' into 2.0-class-loading

Conflicts:
	lib/Cake/View/Helper.php
This commit is contained in:
José Lorenzo Rodríguez 2010-12-10 01:25:00 -04:30
commit e57b3d8e74
7 changed files with 142 additions and 33 deletions

View file

@ -112,7 +112,7 @@ class Controller extends Object {
* @var array
* @link http://book.cakephp.org/view/1231/Pagination
*/
public $paginate = array('limit' => 20, 'page' => 1);
public $paginate = array('limit' => 20, 'page' => 1, 'maxLimit' => 100);
/**
* The name of the views subfolder containing views for this controller.
@ -1068,8 +1068,8 @@ class Controller extends Object {
unset($defaults[0]);
}
$options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options);
$options['limit'] = (int) $options['limit'];
$options = array_merge(array('page' => 1, 'limit' => 20, 'maxLimit' => 100), $defaults, $options);
$options['limit'] = min((int)$options['limit'], $options['maxLimit']);
if (empty($options['limit']) || $options['limit'] < 1) {
$options['limit'] = 1;
}
@ -1108,7 +1108,7 @@ class Controller extends Object {
} elseif (intval($page) < 1) {
$options['page'] = $page = 1;
}
$page = $options['page'] = (integer)$page;
$page = $options['page'] = (int)$page;
if (method_exists($object, 'paginate')) {
$results = $object->paginate(

View file

@ -1,10 +1,5 @@
<?php
/**
* Deals with Collections of objects. Keeping registries of those objects,
* loading and constructing new objects and triggering callbacks.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@ -13,11 +8,21 @@
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Deals with Collections of objects. Keeping registries of those objects,
* loading and constructing new objects and triggering callbacks. Each subclass needs
* to implement its own load() functionality.
*
* All core subclasses of ObjectCollection by convention loaded objects are stored
* in `$this->_loaded`. Enabled objects are stored in `$this->_enabled`. In addition
* the all support an `enabled` option that controls the enabled/disabled state of the object
* when loaded.
*
* @package cake.libs
* @since CakePHP(tm) v 2.0
*/
abstract class ObjectCollection {
/**

View file

@ -105,6 +105,30 @@ class Helper extends Object {
*/
protected $_View;
/**
* Minimized attributes
*
* @var array
*/
protected $_minimizedAttributes = array(
'compact', 'checked', 'declare', 'readonly', 'disabled', 'selected',
'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'
);
/**
* Format to attribute
*
* @var string
*/
protected $_attributeFormat = '%s="%s"';
/**
* Format to attribute
*
* @var string
*/
protected $_minimizedAttributeFormat = '%s="%s"';
/**
* Default Constructor
*
@ -358,7 +382,7 @@ class Helper extends Object {
foreach ($options as $key => $value) {
if (!isset($exclude[$key]) && $value !== false && $value !== null) {
$attributes[] = $this->__formatAttribute($key, $value, $escape);
$attributes[] = $this->_formatAttribute($key, $value, $escape);
}
}
$out = implode(' ', $attributes);
@ -375,30 +399,21 @@ class Helper extends Object {
* @param string $key The name of the attribute to create
* @param string $value The value of the attribute to create.
* @return string The composed attribute.
* @access private
*/
function __formatAttribute($key, $value, $escape = true) {
protected function _formatAttribute($key, $value, $escape = true) {
$attribute = '';
$attributeFormat = '%s="%s"';
static $minimizedAttributes = array();
if (empty($minimizedAttributes)) {
$minimizedAttributes = array_flip(array(
'compact', 'checked', 'declare', 'readonly', 'disabled',
'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap',
'multiple', 'noresize'
));
}
if (is_array($value)) {
$value = '';
}
if (isset($minimizedAttributes[$key])) {
if (is_numeric($key)) {
$attribute = sprintf($this->_minimizedAttributeFormat, $value, $value);
} elseif (in_array($key, $this->_minimizedAttributes)) {
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
$attribute = sprintf($attributeFormat, $key, $key);
$attribute = sprintf($this->_minimizedAttributeFormat, $key, $key);
}
} else {
$attribute = sprintf($attributeFormat, $key, ($escape ? h($value) : $value));
$attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
}
return $attribute;
}

View file

@ -85,12 +85,12 @@
* Only runs if debug level is greater than zero.
*
* @param boolean $var Variable to show debug information for.
* @param boolean $showHtml If set to true, the method prints the debug data in a screen-friendly way.
* @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way.
* @param boolean $showFrom If set to true, the method prints from where the function was called.
* @link http://book.cakephp.org/view/1190/Basic-Debugging
* @link http://book.cakephp.org/view/1128/debug
*/
function debug($var = false, $showHtml = false, $showFrom = true) {
function debug($var = false, $showHtml = null, $showFrom = true) {
if (Configure::read('debug') > 0) {
$file = '';
$line = '';
@ -116,10 +116,14 @@ TEXT;
$template = $html;
if (php_sapi_name() == 'cli') {
$template = $text;
} else {
if ($showHtml === null) {
$showHtml = true;
}
}
$var = print_r($var, true);
if ($showHtml) {
$var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
$var = str_replace(array('<', '>'), array('&lt;', '&gt;'), $var);
}
printf($template, $file, $line, $var);
}

View file

@ -687,12 +687,20 @@ class BasicsTest extends CakeTestCase {
$this->assertPattern($pattern, $result);
ob_start();
debug('<div>this-is-a-test</div>', true);
debug('<div>this-is-a-test</div>');
$result = ob_get_clean();
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*&lt;div&gt;this-is-a-test&lt;\/div&gt;.*/s';
$this->assertPattern($pattern, $result);
ob_start();
debug('<div>this-is-a-test</div>', false);
$result = ob_get_clean();
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
$pattern .= '.*line.*' . (__LINE__ - 4) . '.*\<div\>this-is-a-test\<\/div\>.*/s';
$this->assertPattern($pattern, $result);
}
/**

View file

@ -751,6 +751,45 @@ class ControllerTest extends CakeTestCase {
$this->assertEqual($Controller->ControllerPaginateModel->extraCount, $expected);
}
/**
* testPaginateMaxLimit
*
* @return void
* @access public
*/
function testPaginateMaxLimit() {
$request = new CakeRequest('controller_posts/index');
$request->params['pass'] = $request->params['named'] = array();
$Controller = new Controller($request);
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 100);
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 100);
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '10');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 10);
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '1000');
$Controller->paginate = array('maxLimit' => 2000);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 1000);
$Controller->passedArgs = array('contain' => array('ControllerComment'), 'limit' => '5000');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['options']['limit'], 2000);
}
/**
* testPaginateFieldsDouble method
*
@ -821,6 +860,7 @@ class ControllerTest extends CakeTestCase {
'fields' => array(),
'order' => '',
'limit' => 5,
'maxLimit' => 100,
'page' => 1,
'recursive' => -1,
'conditions' => array()

View file

@ -184,11 +184,41 @@ class TestHelper extends Helper {
}
}
/**
* Html5TestHelper class
*
* @package cake
* @subpackage cake.tests.cases.libs.view
*/
class Html5TestHelper extends TestHelper {
/**
* Minimized
*
* @var array
*/
protected $_minimizedAttributes = array('require', 'checked');
/**
* Allow compact use in HTML
*
* @var string
*/
protected $_minimizedAttributeFormat = '%s';
/**
* Test to attribute format
*
* @var string
*/
protected $_attributeFormat = 'data-%s="%s"';
}
/**
* HelperTest class
*
* @package cake
* @subpackage cake.tests.cases.libs
* @subpackage cake.tests.cases.libs.view
*/
class HelperTest extends CakeTestCase {
@ -809,6 +839,13 @@ class HelperTest extends CakeTestCase {
$this->assertEqual($helper->parseAttributes($attrs), $expected, '%s Failed on ' . $value);
}
}
$this->assertEqual($helper->parseAttributes(array('compact')), ' compact="compact"');
$helper = new Html5TestHelper($this->View);
$expected = ' require';
$this->assertEqual($helper->parseAttributes(array('require')), $expected);
$this->assertEqual($helper->parseAttributes(array('require' => true)), $expected);
$this->assertEqual($helper->parseAttributes(array('require' => false)), '');
}
/**