From cd59ab9c409ade6e868614da798f8ebd31625e21 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 4 Jan 2016 15:08:31 +0100 Subject: [PATCH] Fix tests --- .../Test/Case/View/Helper/FormHelperTest.php | 52 +++++++------------ lib/Cake/View/Helper/FormHelper.php | 3 ++ 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index d8baf977e2b..38c35ffeed8 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -1784,7 +1784,9 @@ public function testFormValidationAssociated() { $encoding = strtolower(Configure::read('App.encoding')); $expected = array( 'form' => array( - 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm', + 'action' => '/user_forms/login', + 'id' => 'UserFormLoginForm', + 'method' => 'post', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), @@ -8539,7 +8541,9 @@ public function testCreate() { $result = $this->Form->create('User', array('url' => array('action' => 'login'))); $expected = array( 'form' => array( - 'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login', + 'action' => '/users/login', + 'id' => 'UserLoginForm', + 'method' => 'post', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), @@ -8548,7 +8552,7 @@ public function testCreate() { ); $this->assertTags($result, $expected); - $result = $this->Form->create('User', array('action' => 'login')); + $result = $this->Form->create('User', array('url' => array('action' => 'login'))); $expected = array( 'form' => array( 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login', @@ -8562,7 +8566,12 @@ public function testCreate() { $result = $this->Form->create('User', array('url' => '/users/login')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding, 'id' => 'UserAddForm'), + 'form' => array( + 'action' => '/users/login', + 'id' => 'UserAddForm', + 'method' => 'post', + 'accept-charset' => $encoding + ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' @@ -8570,7 +8579,7 @@ public function testCreate() { $this->assertTags($result, $expected); $this->Form->request['controller'] = 'pages'; - $result = $this->Form->create('User', array('action' => 'signup')); + $result = $this->Form->create('User', array('url' => array('action' => 'signup'))); $expected = array( 'form' => array( 'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup', @@ -8588,7 +8597,7 @@ public function testCreate() { $result = $this->Form->create(array('url' => array('action' => 'index', 'param'))); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/index/param', + 'id' => 'ContactIndexForm', 'method' => 'post', 'action' => '/contacts/index/param', 'accept-charset' => 'utf-8' ), 'div' => array('style' => 'display:none;'), @@ -8598,27 +8607,6 @@ public function testCreate() { $this->assertTags($result, $expected); } - -/** - * Test create() with no URL (no "action" attribute for
tag) - * - * @return void - */ - public function testCreateNoUrl() { - $result = $this->Form->create(false, array('url' => false)); - $expected = array( - 'form' => array( - 'id' => 'addForm', - 'method' => 'post', - 'accept-charset' => strtolower(Configure::read('App.encoding')) - ), - 'div' => array('style' => 'display:none;'), - 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), - '/div' - ); - $this->assertHtml($expected, $result); - } - /** * Test the onsubmit option for create() * @@ -8631,7 +8619,7 @@ public function testCreateOnSubmit() { $result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false)); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param', + 'id' => 'ContactIndexForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param', 'accept-charset' => 'utf-8' ), 'div' => array('style' => 'display:none;'), @@ -8651,7 +8639,7 @@ public function testCreateOnSubmit() { $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', + 'id' => 'ContactIndexForm', 'method' => 'post', 'onsubmit' => 'someFunction();event.returnValue = false; return false;', 'action' => '/contacts/index/param', 'accept-charset' => 'utf-8' @@ -8814,7 +8802,7 @@ public function testCreateQuerystringrequest() { )); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', + 'id' => 'ContactActionForm', 'method' => 'post', 'action' => '/controller/action?param1=value1&param2=value2', 'accept-charset' => $encoding @@ -8835,7 +8823,7 @@ public function testCreateQuerystringrequest() { )); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', + 'id' => 'ContactActionForm', 'method' => 'post', 'action' => '/controller/action?param1=value1&param2=value2', 'accept-charset' => $encoding @@ -8891,7 +8879,7 @@ public function testCreatePassedArgs() { )); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', + 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/0/myparam', 'accept-charset' => $encoding diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index f1089a25237..d1d9b3701e8 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -382,6 +382,9 @@ public function create($model = null, $options = array()) { if (isset($options['action'])) { trigger_error('Using key `action` is deprecated, use `url` directly instead.', E_USER_DEPRECATED); } + if (isset($options['url']) && isset($options['url']['action'])) { + $options['action'] = $options['url']['action']; + } if (!isset($options['id'])) { $domId = isset($options['action']) ? $options['action'] : $this->request['action'];