Skip to content

Commit

Permalink
Fixing issue where a false id would be appended to the route url. Tes…
Browse files Browse the repository at this point in the history
…t added. Fixes #1501
  • Loading branch information
markstory committed Feb 3, 2011
1 parent 5b8499c commit 63308fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/form.php
Expand Up @@ -260,7 +260,7 @@ function create($model = null, $options = array()) {
$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'])) {
Expand Down
26 changes: 23 additions & 3 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -661,8 +661,6 @@ class FormHelperTest extends CakeTestCase {
*/
function setUp() {
parent::setUp();
Router::reload();


$this->Controller = new ContactTestController();
$this->View = new View($this->Controller);
Expand Down Expand Up @@ -703,7 +701,7 @@ function setUp() {
* @return void
*/
function tearDown() {
ClassRegistry::flush();
parent::tearDown();
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
Configure::write('Security.salt', $this->oldSalt);
}
Expand Down Expand Up @@ -5640,6 +5638,28 @@ function testCreate() {
$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.
*
Expand Down

0 comments on commit 63308fd

Please sign in to comment.