Fixing issue where a false id would be appended to the route url. Test added. Fixes #1501

This commit is contained in:
mark_story 2011-02-02 21:52:41 -05:00
parent 5b8499c8c7
commit 63308fdbd8
2 changed files with 24 additions and 4 deletions

View file

@ -260,7 +260,7 @@ class FormHelper extends AppHelper {
$options['id'] = $this->domId($options['action'] . 'Form');
}
$options['action'] = array_merge($actionDefaults, (array)$options['url']);
if (empty($options['action'][0])) {
if (empty($options['action'][0]) && !empty($id)) {
$options['action'][0] = $id;
}
} elseif (is_string($options['url'])) {

View file

@ -661,8 +661,6 @@ class FormHelperTest extends CakeTestCase {
*/
function setUp() {
parent::setUp();
Router::reload();
$this->Controller = new ContactTestController();
$this->View = new View($this->Controller);
@ -703,7 +701,7 @@ class FormHelperTest extends CakeTestCase {
* @return void
*/
function tearDown() {
ClassRegistry::flush();
parent::tearDown();
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
Configure::write('Security.salt', $this->oldSalt);
}
@ -5640,6 +5638,28 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* test create() with a custom route
*
* @return void
*/
function testCreateCustomRoute() {
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create('User', array('action' => 'login'));
$expected = array(
'form' => array(
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
'accept-charset' => $encoding
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test that inputDefaults are stored and used.
*