Fixing issue #2810, AjaxHelper does not render boolean options properly, and adding tests for it

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5325 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2007-06-21 16:24:13 +00:00
parent 97a10184f3
commit 496e97aaec
2 changed files with 19 additions and 4 deletions

View file

@ -749,6 +749,11 @@ class AjaxHelper extends AppHelper {
foreach ($options as $k => $v) {
if (in_array($k, $acceptable)) {
if ($v === true) {
$v = 'true';
} elseif ($v === false) {
$v = 'false';
}
$out[] = "$k:$v";
}
}
@ -817,7 +822,7 @@ class AjaxHelper extends AppHelper {
*/
function _optionsToString($options, $stringOpts = array()) {
foreach ($stringOpts as $option) {
if (isset($options[$option]) && !$options[$option][0] != "'") {
if (isset($options[$option]) && $options[$option][0] != "'") {
if ($options[$option] === true || $options[$option] === 'true') {
$options[$option] = 'true';
} elseif ($options[$option] === false || $options[$option] === 'false') {

View file

@ -48,10 +48,10 @@
if (!class_exists('Post')) {
class Post extends Model {
var $primaryKey = 'id';
var $useTable = false;
function loadInfo() {
return new Set(array(
array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
@ -94,7 +94,7 @@ class AjaxTest extends UnitTestCase {
function testAutoComplete() {
$result = $this->Ajax->autoComplete('Post/title' , '/posts', array('minChars' => 2));
$this->assertPattern('/^<input[^<>]+name="data\[Post\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result);
$this->assertPattern('/<div[^<>]+id="PostTitle_autoComplete"[^<>]*><\/div>/', $result);
$this->assertPattern('/<div[^<>]+class="auto_complete"[^<>]*><\/div>/', $result);
@ -125,6 +125,16 @@ class AjaxTest extends UnitTestCase {
$this->assertEqual($result, $expected);
}
function testSortable() {
$result = $this->Ajax->sortable('ull', array('constraint'=>false,'ghosting'=>true));
$expected = '<script type="text/javascript">Sortable.create(\'ull\', {constraint:false, ghosting:true});</script>';
$this->assertEqual($result, $expected);
$result = $this->Ajax->sortable('ull', array('constraint'=>'false','ghosting'=>'true'));
$expected = '<script type="text/javascript">Sortable.create(\'ull\', {constraint:false, ghosting:true});</script>';
$this->assertEqual($result, $expected);
}
function testSubmitWithIndicator() {
$result = $this->Ajax->submit('Add', array('div' => false, 'url' => "/controller/action", 'indicator' => 'loading', 'loading' => "doSomething()", 'complete' => 'doSomethingElse() '));
$this->assertPattern('/onLoading:function\(request\) {doSomething\(\);\s+Element.show\(\'loading\'\);}/', $result);