From 496e97aaec598cc52393dc5fdb3d9a4470ea876f Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Thu, 21 Jun 2007 16:24:13 +0000 Subject: [PATCH] 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 --- cake/libs/view/helpers/ajax.php | 7 ++++++- cake/tests/cases/libs/view/helpers/ajax.test.php | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index 0409d46d9..f75eca7a2 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -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') { diff --git a/cake/tests/cases/libs/view/helpers/ajax.test.php b/cake/tests/cases/libs/view/helpers/ajax.test.php index ee10e82c7..f240ed71a 100644 --- a/cake/tests/cases/libs/view/helpers/ajax.test.php +++ b/cake/tests/cases/libs/view/helpers/ajax.test.php @@ -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('/^]+name="data\[Post\]\[title\]"[^<>]+autocomplete="off"[^<>]+\/>/', $result); $this->assertPattern('/]+id="PostTitle_autoComplete"[^<>]*><\/div>/', $result); $this->assertPattern('/]+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 = ''; + $this->assertEqual($result, $expected); + + $result = $this->Ajax->sortable('ull', array('constraint'=>'false','ghosting'=>'true')); + $expected = ''; + $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);