Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed Jan 4, 2016
1 parent 7076e6d commit cd59ab9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
52 changes: 20 additions & 32 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -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;'),
Expand Down Expand Up @@ -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;'),
Expand All @@ -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',
Expand All @@ -8562,15 +8566,20 @@ 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'
);
$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',
Expand All @@ -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;'),
Expand All @@ -8598,27 +8607,6 @@ public function testCreate() {
$this->assertTags($result, $expected);
}


/**
* Test create() with no URL (no "action" attribute for <form> 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()
*
Expand All @@ -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;'),
Expand All @@ -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'
Expand Down Expand Up @@ -8814,7 +8802,7 @@ public function testCreateQuerystringrequest() {
));
$expected = array(
'form' => array(
'id' => 'ContactAddForm',
'id' => 'ContactActionForm',
'method' => 'post',
'action' => '/controller/action?param1=value1&amp;param2=value2',
'accept-charset' => $encoding
Expand All @@ -8835,7 +8823,7 @@ public function testCreateQuerystringrequest() {
));
$expected = array(
'form' => array(
'id' => 'ContactAddForm',
'id' => 'ContactActionForm',
'method' => 'post',
'action' => '/controller/action?param1=value1&amp;param2=value2',
'accept-charset' => $encoding
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -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'];
Expand Down

0 comments on commit cd59ab9

Please sign in to comment.