Skip to content

Commit 63308fd

Browse files
committed
Fixing issue where a false id would be appended to the route url. Test added. Fixes #1501
1 parent 5b8499c commit 63308fd

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

cake/libs/view/helpers/form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function create($model = null, $options = array()) {
260260
$options['id'] = $this->domId($options['action'] . 'Form');
261261
}
262262
$options['action'] = array_merge($actionDefaults, (array)$options['url']);
263-
if (empty($options['action'][0])) {
263+
if (empty($options['action'][0]) && !empty($id)) {
264264
$options['action'][0] = $id;
265265
}
266266
} elseif (is_string($options['url'])) {

cake/tests/cases/libs/view/helpers/form.test.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,6 @@ class FormHelperTest extends CakeTestCase {
661661
*/
662662
function setUp() {
663663
parent::setUp();
664-
Router::reload();
665-
666664

667665
$this->Controller = new ContactTestController();
668666
$this->View = new View($this->Controller);
@@ -703,7 +701,7 @@ function setUp() {
703701
* @return void
704702
*/
705703
function tearDown() {
706-
ClassRegistry::flush();
704+
parent::tearDown();
707705
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
708706
Configure::write('Security.salt', $this->oldSalt);
709707
}
@@ -5640,6 +5638,28 @@ function testCreate() {
56405638
$this->assertTags($result, $expected);
56415639
}
56425640

5641+
/**
5642+
* test create() with a custom route
5643+
*
5644+
* @return void
5645+
*/
5646+
function testCreateCustomRoute() {
5647+
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
5648+
$encoding = strtolower(Configure::read('App.encoding'));
5649+
5650+
$result = $this->Form->create('User', array('action' => 'login'));
5651+
$expected = array(
5652+
'form' => array(
5653+
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
5654+
'accept-charset' => $encoding
5655+
),
5656+
'div' => array('style' => 'display:none;'),
5657+
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
5658+
'/div'
5659+
);
5660+
$this->assertTags($result, $expected);
5661+
}
5662+
56435663
/**
56445664
* test that inputDefaults are stored and used.
56455665
*

0 commit comments

Comments
 (0)