From 63308fdbd8308440c6c0f5aefbf41ae36f9351c6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 2 Feb 2011 21:52:41 -0500 Subject: [PATCH] Fixing issue where a false id would be appended to the route url. Test added. Fixes #1501 --- cake/libs/view/helpers/form.php | 2 +- .../cases/libs/view/helpers/form.test.php | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 1eb2b315f2a..92e87fb3e6e 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -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'])) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index bb389396a8c..ed3af90d180 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -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 @@ 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); } @@ -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. *