array('for' => 'ContactEmail'),
'Email',
'/label',
array('input' => array(
'type' => 'email', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail', 'maxlength' => 255
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->hidden('Contact.idontexist');
$expected = array('input' => array(
'type' => 'hidden', 'name' => 'data[Contact][idontexist]',
'id' => 'ContactIdontexist'
));
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactEmail'),
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.5.email', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'Contact5Email'),
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][5][email]',
'id' => 'Contact5Email'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
array('input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.email', array(
'type' => 'file', 'class' => 'textbox'
));
$expected = array(
'div' => array('class' => 'input file'),
'label' => array('for' => 'ContactEmail'),
'Email',
'/label',
array('input' => array(
'type' => 'file', 'name' => 'data[Contact][email]', 'class' => 'textbox',
'id' => 'ContactEmail'
)),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
$result = $this->Form->input('Contact.phone');
$expected = array(
'div' => array('class' => 'input tel'),
'label' => array('for' => 'ContactPhone'),
'Phone',
'/label',
array('input' => array(
'type' => 'tel', 'name' => 'data[Contact][phone]',
'value' => 'Hello & World > weird chars',
'id' => 'ContactPhone', 'maxlength' => 255
)),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
$result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'myId'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Model][0][OtherModel][field]',
'value' => 'My value', 'id' => 'myId'
),
'/div'
);
$this->assertTags($result, $expected);
unset($this->Form->request->data);
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors['field'] = array('Badness!');
$result = $this->Form->input('Contact.field');
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
'Badness!',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.field', array(
'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
));
$expected = array(
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
array('span' => array('class' => 'error-message')),
'Badness!',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.field', array(
'type' => 'text', 'error' => array('attributes' => array('class' => 'error'))
));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
array('div' => array('class' => 'error')),
'Badness!',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.field', array(
'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
));
$expected = array(
'span' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
'Badness!',
'/span'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[Contact][field]',
'id' => 'ContactField', 'class' => 'form-error'
),
'A message to you, Rudy',
array('div' => array('class' => 'error-message')),
'Badness!',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$this->Form->setEntity(null);
$this->Form->setEntity('Contact.field');
$result = $this->Form->input('Contact.field', array(
'after' => 'A message to you, Rudy', 'error' => false
));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
'A message to you, Rudy',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ObjectField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'),
'A message to you, Rudy',
'/div'
);
$this->assertTags($result, $expected);
$Contact->validationErrors['field'] = array('minLength');
$result = $this->Form->input('Contact.field', array(
'error' => array(
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large'
)
));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
array('div' => array('class' => 'error-message')),
'Le login doit contenir au moins 2 caractères',
'/div',
'/div'
);
$this->assertTags($result, $expected);
$Contact->validationErrors['field'] = array('maxLength');
$result = $this->Form->input('Contact.field', array(
'error' => array(
'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large',
)
));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ContactField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
array('span' => array('class' => 'error-message', 'rel' => 'fake')),
'login too large',
'/span',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Test that inputs with 0 can be created.
*
* @return void
*/
public function testInputZero() {
$this->Form->create('User');
$result = $this->Form->input('0');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'User0'), '/label',
'input' => array('type' => 'text', 'name' => 'data[User][0]', 'id' => 'User0'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test input() with checkbox creation
*
* @return void
*/
public function testInputCheckbox() {
$result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.disabled', array(
'label' => 'Disabled',
'type' => 'checkbox',
'data-foo' => 'disabled'
));
$expected = array(
'div' => array('class' => 'input checkbox'),
'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
array('input' => array(
'type' => 'checkbox',
'name' => 'data[User][disabled]',
'value' => '1',
'id' => 'UserDisabled',
'data-foo' => 'disabled'
)),
'label' => array('for' => 'UserDisabled'),
'Disabled',
'/label',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test form->input() with time types.
*
*/
public function testInputTime() {
extract($this->dateRegex);
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
$result = explode(':', $result);
$this->assertRegExp('/option value="23"/', $result[0]);
$this->assertNotRegExp('/option value="24"/', $result[0]);
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
$result = explode(':', $result);
$this->assertRegExp('/option value="23"/', $result[0]);
$this->assertNotRegExp('/option value="24"/', $result[0]);
$result = $this->Form->input('Model.field', array(
'type' => 'time', 'timeFormat' => 24, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertRegExp('#
#', $result[1]);
$result = $this->Form->input('Model.field', array(
'type' => 'time', 'timeFormat' => 12, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertRegExp('#
#', $result[1]);
$result = $this->Form->input('prueba', array(
'type' => 'time', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
'maxYear' => date('Y') + 1, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertRegExp('#
#', $result[1]);
$this->assertRegExp('#
#', $result[1]);
$result = $this->Form->input('Random.start_time', array(
'type' => 'time',
'selected' => '18:15'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('published', array('type' => 'time'));
$now = strtotime('now');
$this->assertContains('
', $result);
$now = strtotime('2013-03-09 00:42:21');
$result = $this->Form->input('published', array('type' => 'time', 'selected' => $now));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
}
/**
* Test interval + selected near the hour roll over.
*
* @return void
*/
public function testTimeSelectedWithInterval() {
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'interval' => 15,
'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'interval' => 15,
'selected' => '2012-10-23 15:57:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'timeFormat' => 24,
'type' => 'time',
'interval' => 15,
'selected' => '15:57'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'timeFormat' => 24,
'type' => 'time',
'interval' => 15,
'selected' => '23:57'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.created', array(
'timeFormat' => 24,
'type' => 'datetime',
'interval' => 15,
'selected' => '2012-09-30 23:56'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
}
/**
* Test time with selected values around 12:xx:xx
*
* @return void
*/
public function testTimeSelectedWithIntervalTwelve() {
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => 12,
'interval' => 15,
'selected' => '00:00:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => 12,
'interval' => 15,
'selected' => '12:00:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => 12,
'interval' => 15,
'selected' => '12:15:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
}
/**
* Test interval & timeFormat = 12
*
* @return void
*/
public function testInputTimeWithIntervalAnd12HourFormat() {
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => 12,
'interval' => 5,
'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm')
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 5,
'selected' => '2013-04-19 16:30:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 00:33:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 13:33:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 01:33:00'
));
$this->assertContains('
', $result);
$this->assertContains('
', $result);
$this->assertContains('
', $result);
}
/**
* test form->input() with datetime, date and time types
*
* @return void
*/
public function testInputDatetime() {
extract($this->dateRegex);
$result = $this->Form->input('prueba', array(
'type' => 'datetime', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
'maxYear' => date('Y') + 1, 'interval' => 15
));
$result = explode(':', $result);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertNotRegExp('#
#', $result[1]);
$this->assertRegExp('#
#', $result[1]);
$this->assertRegExp('#
#', $result[1]);
//related to ticket #5013
$result = $this->Form->input('Contact.date', array(
'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
));
$this->assertRegExp('/class="customClass"/', $result);
$this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
$result = $this->Form->input('Contact.date', array(
'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
));
$this->assertRegExp('/id="customIdDay"/', $result);
$this->assertRegExp('/id="customIdMonth"/', $result);
$this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
$result = $this->Form->input('Model.field', array(
'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
));
$this->assertRegExp('/id="customIDDay"/', $result);
$this->assertRegExp('/id="customIDHour"/', $result);
$result = explode('