diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 68b255fc7..323b762d0 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -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( diff --git a/lib/Cake/Utility/ObjectCollection.php b/lib/Cake/Utility/ObjectCollection.php index b2a6eb443..e9dd53abe 100644 --- a/lib/Cake/Utility/ObjectCollection.php +++ b/lib/Cake/Utility/ObjectCollection.php @@ -1,10 +1,5 @@ _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 { /** diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 25f62f2be..f9d26e447 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -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; } diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index 2d23d220d..190deb3cc 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -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('<', '<', str_replace('>', '>', $var)); + $var = str_replace(array('<', '>'), array('<', '>'), $var); } printf($template, $file, $line, $var); } diff --git a/lib/Cake/tests/cases/basics.test.php b/lib/Cake/tests/cases/basics.test.php index b3b028cd4..7251ab82d 100644 --- a/lib/Cake/tests/cases/basics.test.php +++ b/lib/Cake/tests/cases/basics.test.php @@ -687,12 +687,20 @@ class BasicsTest extends CakeTestCase { $this->assertPattern($pattern, $result); ob_start(); - debug('
this-is-a-test
', true); + debug('
this-is-a-test
'); $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); + + ob_start(); + debug('
this-is-a-test
', false); + $result = ob_get_clean(); + $pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|'; + $pattern .= preg_quote(substr(__FILE__, 1), '/') . ')'; + $pattern .= '.*line.*' . (__LINE__ - 4) . '.*\this-is-a-test\<\/div\>.*/s'; + $this->assertPattern($pattern, $result); } /** diff --git a/lib/Cake/tests/cases/libs/controller/controller.test.php b/lib/Cake/tests/cases/libs/controller/controller.test.php index 411df3309..19fa1c2f0 100644 --- a/lib/Cake/tests/cases/libs/controller/controller.test.php +++ b/lib/Cake/tests/cases/libs/controller/controller.test.php @@ -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() diff --git a/lib/Cake/tests/cases/libs/view/helper.test.php b/lib/Cake/tests/cases/libs/view/helper.test.php index b30c2a767..ba401fe6e 100644 --- a/lib/Cake/tests/cases/libs/view/helper.test.php +++ b/lib/Cake/tests/cases/libs/view/helper.test.php @@ -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)), ''); } /**