Skip to content
Permalink
Browse files

Adding form encoding default in form create options. Default is alway…

…s taken from Configure::read('App.encoding'). closes #6042
  • Loading branch information...
lorenzo authored and markstory committed Oct 30, 2009
1 parent dfc1014 commit 1c47b2182e06b2455be7bc55969044e24d3f1eeb
Showing with 87 additions and 24 deletions.
  1. +7 −0 cake/libs/view/helpers/form.php
  2. +80 −24 cake/tests/cases/libs/view/helpers/form.test.php
@@ -195,6 +195,7 @@ function create($model = null, $options = array()) {
'action' => null,
'url' => null,
'default' => true,
'encoding' => strtolower(Configure::read('App.encoding')),
'inputDefaults' => array()),
$options);
$this->_inputDefaults = $options['inputDefaults'];
@@ -256,6 +257,12 @@ function create($model = null, $options = array()) {
$htmlAttributes['onsubmit'] = 'event.returnValue = false; return false;';
}
}
if (!empty($options['encoding'])) {
$htmlAttributes['accept-charset'] = $options['encoding'];
unset($options['encoding']);
}
unset($options['default']);
$htmlAttributes = array_merge($options, $htmlAttributes);
@@ -723,18 +723,18 @@ function tearDown() {
*/
function testFormCreateWithSecurity() {
$this->Form->params['_Token'] = array('key' => 'testKey');
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add'),
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
'fieldset' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testKey', 'id'
)),
'/fieldset'
);
$this->assertTags($result, $expected);
$this->assertTags($result, $expected,true);
$result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
$expected['form']['id'] = 'MyForm';
@@ -1078,8 +1078,9 @@ function testFormSecuredInput() {
$this->Form->params['_Token']['key'] = 'testKey';
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add'),
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
'fieldset' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
@@ -1275,9 +1276,11 @@ function testFormValidationAssociated() {
$this->assertFalse($this->UserForm->OpenidUrl->validates());
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm'
'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -1318,8 +1321,9 @@ function testFormValidationAssociatedFirstLevel() {
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id'),
'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id','accept-charset' => $encoding),
'fieldset' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
@@ -1361,8 +1365,9 @@ function testFormValidationAssociatedSecondLevel() {
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id'),
'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id','accept-charset' => $encoding),
'fieldset' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
@@ -4636,9 +4641,11 @@ function testSubmitImage() {
*/
function testFormCreate() {
$result = $this->Form->create('Contact');
$encoding = strtolower(Configure::read('App.encoding'));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -4648,20 +4655,23 @@ function testFormCreate() {
$result = $this->Form->create('Contact', array('type' => 'GET'));
$expected = array('form' => array(
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/',
'accept-charset' => $encoding
));
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('type' => 'get'));
$expected = array('form' => array(
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/',
'accept-charset' => $encoding
));
$this->assertTags($result, $expected);
$result = $this->Form->create('Contact', array('type' => 'put'));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
@@ -4674,7 +4684,8 @@ function testFormCreate() {
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1'
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
@@ -4687,7 +4698,7 @@ function testFormCreate() {
$expected = array(
'form' => array(
'id' => 'ContactNonStandardPkEditForm', 'method' => 'post',
'action' => '/contact_non_standard_pks/edit/1'
'action' => '/contact_non_standard_pks/edit/1','accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
@@ -4697,7 +4708,10 @@ function testFormCreate() {
$result = $this->Form->create('Contact', array('id' => 'TestId'));
$expected = array(
'form' => array('id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1'),
'form' => array(
'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
'/fieldset'
@@ -4707,7 +4721,10 @@ function testFormCreate() {
$this->Form->params['action'] = 'add';
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
$expected = array(
'form' => array('id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login/'),
'form' => array(
'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
@@ -4717,7 +4734,8 @@ function testFormCreate() {
$result = $this->Form->create('User', array('action' => 'login'));
$expected = array(
'form' => array(
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login/'
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -4727,7 +4745,7 @@ function testFormCreate() {
$result = $this->Form->create('User', array('url' => '/users/login'));
$expected = array(
'form' => array('method' => 'post', 'action' => '/users/login'),
'form' => array('method' => 'post', 'action' => '/users/login','accept-charset' => $encoding),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
@@ -4739,7 +4757,8 @@ function testFormCreate() {
$result = $this->Form->create('User', array('action' => 'signup'));
$expected = array(
'form' => array(
'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup/'
'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -4778,6 +4797,7 @@ function testCreateWithInputDefaults() {
*
*/
function testFormCreateQuerystringParams() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array(
'type' => 'post',
'escape' => false,
@@ -4791,7 +4811,8 @@ function testFormCreateQuerystringParams() {
'form' => array(
'id' => 'ContactAddForm',
'method' => 'post',
'action' => '/controller/action/?param1=value1&param2=value2'
'action' => '/controller/action/?param1=value1&param2=value2',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -4807,14 +4828,16 @@ function testFormCreateQuerystringParams() {
* @return void
*/
function testGetFormCreate() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact', array('type' => 'get'));
$this->assertTags($result, array('form' => array(
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/',
'accept-charset' => $encoding
)));
$result = $this->Form->text('Contact.name');
$this->assertTags($result, array('input' => array(
'name' => 'name', 'type' => 'text', 'value' => '', 'id' => 'ContactName'
'name' => 'name', 'type' => 'text', 'value' => '', 'id' => 'ContactName',
)));
$result = $this->Form->password('password');
@@ -4875,10 +4898,12 @@ function testEditFormWithData() {
* @return void
*/
function testFormMagicInput() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -5101,10 +5126,12 @@ function testFormMagicInput() {
* @return void
*/
function testForMagicInputNonExistingNorValidated() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -5161,10 +5188,12 @@ function testForMagicInputNonExistingNorValidated() {
* @return void
*/
function testFormMagicInputLabel() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('Contact');
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/'
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/',
'accept-charset' => $encoding
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
@@ -5597,5 +5626,32 @@ function testMultiRecordFormValidationErrors() {
$result = $this->Form->error('2.city');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
}
function testInputErrorEscape() {
$this->Form->create('ValidateProfile');
$this->Form->validationErrors['ValidateProfile']['city'] = 'required<br>';
$result = $this->Form->input('city',array('error' => array('escape' => true)));
$this->assertPattern('/required&lt;br&gt;/', $result);
$result = $this->Form->input('city',array('error' => array('escape' => false)));
$this->assertPattern('/required<br>/', $result);
}
function testFormEncoding() {
$result = $this->Form->create('UserForm', array(
'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1'
)
);
$expected = array(
'form' => array(
'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm',
'accept-charset' => 'iso-8859-1'
),
'fieldset' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
);
$this->assertTags($result, $expected);
}
}
?>

0 comments on commit 1c47b21

Please sign in to comment.
You can’t perform that action at this time.