Skip to content

Commit

Permalink
Very basic FormHelper::create() test is passing again.
Browse files Browse the repository at this point in the history
FormHelper doesn't need to add ID's to every element it creates.
Removing id generation on form elements reduces the chances it will
create duplicate ID's requiring developer intervention.
  • Loading branch information
markstory committed Feb 11, 2014
1 parent 11014f9 commit 516b7bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/View/Helper/FormHelper.php
Expand Up @@ -159,7 +159,7 @@ class FormHelper extends Helper {
* @var array
*/
protected $_defaultTemplates = [
'formstart' => '<form {{attrs}}>',
'formstart' => '<form{{attrs}}>',
'formend' => '</form>',
];

Expand Down Expand Up @@ -297,11 +297,6 @@ public function create($model = null, $options = []) {
'encoding' => strtolower(Configure::read('App.encoding')),
], $options);

if (!isset($options['id'])) {
$domId = isset($options['action']) ? $options['action'] : $this->request['action'];
$options['id'] = $this->domId($domId . 'Form');
}

if ($options['action'] === null && $options['url'] === null) {
$options['action'] = $this->request->here(false);
} elseif (empty($options['url']) || is_array($options['url'])) {
Expand Down
6 changes: 2 additions & 4 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -605,16 +605,14 @@ public function testCreateContextSelectionBuiltIn($data, $class) {
* @return void
*/
public function testCreateWithSecurity() {
$this->markTestIncomplete();
$this->Form->request->params['_csrfToken'] = 'testKey';
$encoding = strtolower(Configure::read('App.encoding'));
$article = new Article();
$result = $this->Form->create($article, [
'url' => '/contacts/add',
'context' => ['table' => 'Articles']
]);
$expected = array(
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
Expand All @@ -624,7 +622,7 @@ public function testCreateWithSecurity() {
);
$this->assertTags($result, $expected);

$result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
$result = $this->Form->create($article, ['url' => '/contacts/add', 'id' => 'MyForm']);
$expected['form']['id'] = 'MyForm';
$this->assertTags($result, $expected);
}
Expand Down

0 comments on commit 516b7bb

Please sign in to comment.