mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Applying correct fix for Ticket #2917, updating FormHelper test cases, and adding Helper test group
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5467 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
99c1e9fe6d
commit
9a915e90ef
3 changed files with 112 additions and 36 deletions
|
@ -676,7 +676,7 @@ class FormHelper extends AppHelper {
|
|||
unset($options['value']);
|
||||
}
|
||||
|
||||
$options = $this->__initInputField($fieldName, am(array('type' => 'checkbox'), $options));
|
||||
$options = $this->__initInputField($fieldName, $options);
|
||||
$this->__secure();
|
||||
|
||||
$model = $this->model();
|
||||
|
@ -698,10 +698,6 @@ class FormHelper extends AppHelper {
|
|||
$options['value'] = $value;
|
||||
}
|
||||
|
||||
if (isset($options['type'])) {
|
||||
unset($options['type']);
|
||||
}
|
||||
|
||||
$output .= sprintf($this->Html->tags['checkbox'], $this->model(), $this->field(), $this->_parseAttributes($options, null, null, ' '));
|
||||
return $this->output($output);
|
||||
}
|
||||
|
@ -805,6 +801,7 @@ class FormHelper extends AppHelper {
|
|||
function hidden($fieldName, $options = array()) {
|
||||
$options = $this->__initInputField($fieldName, $options);
|
||||
$model = $this->model();
|
||||
unset($options['class']);
|
||||
|
||||
if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
|
||||
$model = '_' . $model;
|
||||
|
|
|
@ -473,6 +473,73 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/i', $result);
|
||||
}
|
||||
|
||||
function testCheckbox() {
|
||||
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+type="hidden"[^<>]+\/><input[^<>]+type="checkbox"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+\/><input[^<>]+[^type|name|id|value]=[^<>]*>$/', $result);
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+type="hidden"[^<>]+\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+id="theID_"[^<>]+\/><input[^<>]+\/>$/', $result);
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+type="checkbox"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+value="myvalue"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+id="theID"[^<>]+\/>$/', $result);
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$this->Form->data['Model']['field'] = 'myvalue';
|
||||
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
|
||||
|
||||
$this->assertNoPattern('/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/', $result);
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+class="form-error"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/', $result);
|
||||
|
||||
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
|
||||
$this->assertNoPattern('/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/', $result);
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+id="ModelField_"[^<>]+\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+id="ModelField"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+value="myvalue"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/', $result);
|
||||
|
||||
$this->Form->data['Model']['field'] = '';
|
||||
$result = $this->Form->checkbox('Model.field', array('id' => 'theID'));
|
||||
$this->assertPattern('/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+\/><input[^<>]+value="1"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/', $result);
|
||||
|
||||
unset($this->Form->validationErrors['Model']['field']);
|
||||
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
|
||||
$this->assertNoPattern('/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input[^<>]+\/><input[^<>]+[^type|name|id|value]=[^<>]*>$/', $result);
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="ModelField_" /><input type="checkbox" name="data[Model][field]" value="myvalue" id="ModelField" />');
|
||||
|
||||
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Contact][field]" value="0" id="ContactField_" /><input type="checkbox" name="data[Contact][field]" value="myvalue" id="ContactField" />');
|
||||
|
||||
$result = $this->Form->checkbox('Model.field');
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="ModelField_" /><input type="checkbox" name="data[Model][field]" value="1" id="ModelField" />');
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$this->Form->data['Contact']['published'] = 1;
|
||||
$result = $this->Form->checkbox('Contact.published', array('id'=>'theID'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Contact][published]" value="0" id="theID_" /><input type="checkbox" name="data[Contact][published]" id="theID" value="1" checked="checked" />');
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$this->Form->data['Contact']['published'] = 0;
|
||||
$result = $this->Form->checkbox('Contact.published', array('id'=>'theID'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Contact][published]" value="0" id="theID_" /><input type="checkbox" name="data[Contact][published]" id="theID" value="1" />');
|
||||
}
|
||||
|
||||
function testMonth() {
|
||||
$result = $this->Form->month('Model.field');
|
||||
$this->assertPattern('/' .
|
||||
|
@ -734,37 +801,6 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertEqual($result, '<div class="submit"><input type="submit" value="save" /></div></form>');
|
||||
}
|
||||
|
||||
function testCheckboxField() {
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$this->Form->data['Model']['field'] = 'myvalue';
|
||||
$result = $this->Form->checkbox('Model.field', array('id'=>'theID', 'value' => 'myvalue'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="theID_" class="form-error" /><input type="checkbox" name="data[Model][field]" id="theID" value="myvalue" class="form-error" checked="checked" />');
|
||||
|
||||
$this->Form->data['Model']['field'] = '';
|
||||
$result = $this->Form->checkbox('Model.field', array('id'=>'theID', 'value' => 'myvalue'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="theID_" class="form-error" /><input type="checkbox" name="data[Model][field]" id="theID" value="myvalue" class="form-error" />');
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = 0;
|
||||
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="ModelField_" /><input type="checkbox" name="data[Model][field]" value="myvalue" id="ModelField" />');
|
||||
|
||||
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Contact][field]" value="0" id="ContactField_" /><input type="checkbox" name="data[Contact][field]" value="myvalue" id="ContactField" />');
|
||||
|
||||
$result = $this->Form->checkbox('Model.field');
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="ModelField_" /><input type="checkbox" name="data[Model][field]" value="1" id="ModelField" />');
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$this->Form->data['Contact']['published'] = 1;
|
||||
$result = $this->Form->checkbox('Contact.published', array('id'=>'theID'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Contact][published]" value="0" id="theID_" /><input type="checkbox" name="data[Contact][published]" id="theID" value="1" checked="checked" />');
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$this->Form->data['Contact']['published'] = 0;
|
||||
$result = $this->Form->checkbox('Contact.published', array('id'=>'theID'));
|
||||
$this->assertEqual($result, '<input type="hidden" name="data[Contact][published]" value="0" id="theID_" /><input type="checkbox" name="data[Contact][published]" id="theID" value="1" />');
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
unset($this->Form);
|
||||
}
|
||||
|
|
43
cake/tests/groups/helpers.group.php
Normal file
43
cake/tests/groups/helpers.group.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.groups
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
/** AllCoreHelpersGroupTest
|
||||
*
|
||||
* This test group will run all test in the cases/libs/view/helpers directory.
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.groups
|
||||
*/
|
||||
class AllCoreHelpersGroupTest extends GroupTest {
|
||||
var $label = 'All core helpers';
|
||||
|
||||
function AllCoreHelpersGroupTest() {
|
||||
TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'helpers');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue