['for' => 'contact-email'],
'Email',
'/label',
['input' => [
'type' => 'email', 'name' => 'Contact[email]',
'id' => 'contact-email', 'maxlength' => 255
]],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('Contact.email', ['type' => 'text']);
$expected = [
'div' => ['class' => 'input text'],
'label' => ['for' => 'contact-email'],
'Email',
'/label',
['input' => [
'type' => 'text', 'name' => 'Contact[email]',
'id' => 'contact-email', 'maxlength' => '255'
]],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('Contact.5.email', ['type' => 'text']);
$expected = [
'div' => ['class' => 'input text'],
'label' => ['for' => 'contact-5-email'],
'Email',
'/label',
['input' => [
'type' => 'text', 'name' => 'Contact[5][email]',
'id' => 'contact-5-email', 'maxlength' => '255'
]],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('Contact.password');
$expected = [
'div' => ['class' => 'input password'],
'label' => ['for' => 'contact-password'],
'Password',
'/label',
['input' => [
'type' => 'password', 'name' => 'Contact[password]',
'id' => 'contact-password'
]],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('Contact.email', [
'type' => 'file', 'class' => 'textbox'
]);
$expected = [
'div' => ['class' => 'input file'],
'label' => ['for' => 'contact-email'],
'Email',
'/label',
['input' => [
'type' => 'file', 'name' => 'Contact[email]', 'class' => 'textbox',
'id' => 'contact-email'
]],
'/div'
];
$this->assertHtml($expected, $result);
$entity = new Entity(['phone' => 'Hello & World > weird chars']);
$this->Form->create($entity, ['context' => ['table' => 'Contacts']]);
$result = $this->Form->input('phone');
$expected = [
'div' => ['class' => 'input tel'],
'label' => ['for' => 'phone'],
'Phone',
'/label',
['input' => [
'type' => 'tel', 'name' => 'phone',
'value' => 'Hello & World > weird chars',
'id' => 'phone', 'maxlength' => 255
]],
'/div'
];
$this->assertHtml($expected, $result);
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
$this->Form->create();
$result = $this->Form->input('Model.0.OtherModel.field', ['id' => 'myId']);
$expected = [
'div' => ['class' => 'input text'],
'label' => ['for' => 'myId'],
'Field',
'/label',
'input' => [
'type' => 'text', 'name' => 'Model[0][OtherModel][field]',
'value' => 'My value', 'id' => 'myId'
],
'/div'
];
$this->assertHtml($expected, $result);
$this->Form->request->data = [];
$entity->errors('field', 'Badness!');
$this->Form->create($entity, ['context' => ['table' => 'Contacts']]);
$result = $this->Form->input('field');
$expected = [
'div' => ['class' => 'input text error'],
'label' => ['for' => 'field'],
'Field',
'/label',
'input' => [
'type' => 'text', 'name' => 'field',
'id' => 'field', 'class' => 'form-error'
],
['div' => ['class' => 'error-message']],
'Badness!',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('field', [
'templates' => [
'inputContainerError' => '{{content}}{{error}}',
'error' => '
{{content}}'
]
]);
$expected = [
'label' => ['for' => 'field'],
'Field',
'/label',
'input' => [
'type' => 'text', 'name' => 'field',
'id' => 'field', 'class' => 'form-error'
],
['span' => ['class' => 'error-message']],
'Badness!',
'/span'
];
$this->assertHtml($expected, $result);
$entity->errors('field', ['minLength'], true);
$result = $this->Form->input('field', [
'error' => [
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large'
]
]);
$expected = [
'div' => ['class' => 'input text error'],
'label' => ['for' => 'field'],
'Field',
'/label',
'input' => ['type' => 'text', 'name' => 'field', 'id' => 'field', 'class' => 'form-error'],
['div' => ['class' => 'error-message']],
'Le login doit contenir au moins 2 caractères',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
$entity->errors('field', ['maxLength'], true);
$result = $this->Form->input('field', [
'error' => [
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large',
]
]);
$expected = [
'div' => ['class' => 'input text error'],
'label' => ['for' => 'field'],
'Field',
'/label',
'input' => ['type' => 'text', 'name' => 'field', 'id' => 'field', 'class' => 'form-error'],
['div' => ['class' => 'error-message']],
'login too large',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
}
/**
* Test that input() accepts a template file.
*
* @return void
*/
public function testInputWithTemplateFile()
{
$result = $this->Form->input('field', [
'templates' => 'htmlhelper_tags'
]);
$expected = [
'label' => ['for' => 'field'],
'Field',
'/label',
'input' => [
'type' => 'text', 'name' => 'field',
'id' => 'field'
],
];
$this->assertHtml($expected, $result);
}
/**
* Test id prefix
*
* @return void
*/
public function testCreateIdPrefix()
{
$this->Form->create(false, ['idPrefix' => 'prefix']);
$result = $this->Form->input('field');
$expected = [
'div' => ['class' => 'input text'],
'label' => ['for' => 'prefix-field'],
'Field',
'/label',
'input' => ['type' => 'text', 'name' => 'field', 'id' => 'prefix-field'],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('field', ['id' => 'custom-id']);
$expected = [
'div' => ['class' => 'input text'],
'label' => ['for' => 'custom-id'],
'Field',
'/label',
'input' => ['type' => 'text', 'name' => 'field', 'id' => 'custom-id'],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->radio('Model.field', ['option A']);
$expected = [
'input' => ['type' => 'hidden', 'name' => 'Model[field]', 'value' => ''],
'label' => ['for' => 'prefix-model-field-0'],
['input' => [
'type' => 'radio',
'name' => 'Model[field]',
'value' => '0',
'id' => 'prefix-model-field-0'
]],
'option A',
'/label'
];
$this->assertHtml($expected, $result);
$result = $this->Form->radio('Model.field', ['option A', 'option']);
$expected = [
'input' => ['type' => 'hidden', 'name' => 'Model[field]', 'value' => ''],
'label' => ['for' => 'prefix-model-field-0'],
['input' => [
'type' => 'radio',
'name' => 'Model[field]',
'value' => '0',
'id' => 'prefix-model-field-0'
]],
'option A',
'/label'
];
$this->assertHtml($expected, $result);
$result = $this->Form->select(
'Model.multi_field',
['first'],
['multiple' => 'checkbox']
);
$expected = [
'input' => [
'type' => 'hidden', 'name' => 'Model[multi_field]', 'value' => ''
],
['div' => ['class' => 'checkbox']],
['label' => ['for' => 'prefix-model-multi-field-0']],
['input' => [
'type' => 'checkbox', 'name' => 'Model[multi_field][]',
'value' => '0', 'id' => 'prefix-model-multi-field-0'
]],
'first',
'/label',
'/div',
];
$this->assertHtml($expected, $result);
$this->Form->end();
$result = $this->Form->input('field');
$expected = [
'div' => ['class' => 'input text'],
'label' => ['for' => 'field'],
'Field',
'/label',
'input' => ['type' => 'text', 'name' => 'field', 'id' => 'field'],
'/div'
];
$this->assertHtml($expected, $result);
}
/**
* Test that inputs with 0 can be created.
*
* @return void
*/
public function testInputZero()
{
TableRegistry::get('Contacts', [
'className' => __NAMESPACE__ . '\ContactsTable'
]);
$this->Form->create([], ['context' => ['table' => 'Contacts']]);
$result = $this->Form->input('0');
$expected = [
'div' => ['class' => 'input text'],
'label' => ['for' => '0'], '/label',
'input' => ['type' => 'text', 'name' => '0', 'id' => '0'],
'/div'
];
$this->assertHtml($expected, $result);
}
/**
* test input() with checkbox creation
*
* @return void
*/
public function testInputCheckbox()
{
$result = $this->Form->input('User.active', ['label' => false, 'checked' => true]);
$expected = [
'div' => ['class' => 'input checkbox'],
'input' => ['type' => 'hidden', 'name' => 'User[active]', 'value' => '0'],
['input' => ['type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'user-active', 'checked' => 'checked']],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('User.active', ['label' => false, 'checked' => 1]);
$expected = [
'div' => ['class' => 'input checkbox'],
'input' => ['type' => 'hidden', 'name' => 'User[active]', 'value' => '0'],
['input' => ['type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'user-active', 'checked' => 'checked']],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('User.active', ['label' => false, 'checked' => '1']);
$expected = [
'div' => ['class' => 'input checkbox'],
'input' => ['type' => 'hidden', 'name' => 'User[active]', 'value' => '0'],
['input' => ['type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'user-active', 'checked' => 'checked']],
'/div'
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('User.disabled', [
'label' => 'Disabled',
'type' => 'checkbox',
'data-foo' => 'disabled'
]);
$expected = [
'div' => ['class' => 'input checkbox'],
'input' => ['type' => 'hidden', 'name' => 'User[disabled]', 'value' => '0'],
'label' => ['for' => 'user-disabled'],
['input' => [
'type' => 'checkbox',
'name' => 'User[disabled]',
'value' => '1',
'id' => 'user-disabled',
'data-foo' => 'disabled'
]],
'Disabled',
'/label',
'/div'
];
$this->assertHtml($expected, $result);
}
/**
* Test that input() does not create wrapping div and label tag for hidden fields
*
* @return void
*/
public function testInputHidden()
{
TableRegistry::get('ValidateUsers', [
'className' => __NAMESPACE__ . '\ValidateUsersTable'
]);
$this->Form->create([], ['context' => ['table' => 'ValidateUsers']]);
$result = $this->Form->input('ValidateUser.id');
$expected = [
'input' => ['name', 'type' => 'hidden', 'id']
];
$this->assertHtml($expected, $result);
$result = $this->Form->input('ValidateUser.custom', ['type' => 'hidden']);
$expected = [
'input' => ['name', 'type' => 'hidden', 'id']
];
$this->assertHtml($expected, $result);
}
/**
* test form->input() with datetime
*
* @return void
*/
public function testInputDatetime()
{
$this->Form = $this->getMock(
'Cake\View\Helper\FormHelper',
['datetime'],
[new View()]
);
$this->Form->expects($this->once())->method('datetime')
->with('prueba', [
'type' => 'datetime',
'timeFormat' => 24,
'minYear' => 2008,
'maxYear' => 2011,
'interval' => 15,
'options' => null,
'empty' => false,
'id' => 'prueba',
'required' => false,
])
->will($this->returnValue('This is it!'));
$result = $this->Form->input('prueba', [
'type' => 'datetime', 'timeFormat' => 24, 'minYear' => 2008,
'maxYear' => 2011, 'interval' => 15
]);
$expected = [
'div' => ['class' => 'input datetime'],
'