Permalink
Browse files

Updated file() to use new widget.

  • Loading branch information...
1 parent f86063e commit e57215676ac97ce06930f49b014324800da4f643 @ADmad ADmad committed Feb 19, 2014
@@ -171,6 +171,7 @@ class FormHelper extends Helper {
protected $_defaultTemplates = [
'button' => '<button{{attrs}}>{{text}}</button>',
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
+ 'file' => '<input type="file" name="{{name}}"{{attrs}}>',
'formstart' => '<form{{attrs}}>',
'formend' => '</form>',
'hiddenblock' => '<div style="display:none;">{{content}}</div>',
@@ -492,7 +493,7 @@ public function secure($fields = array(), $secureAttributes = array()) {
}
$locked = array();
$unlockedFields = $this->_unlockedFields;
-
+
foreach ($fields as $key => $value) {
if (!is_int($key)) {
$locked[$key] = $value;
@@ -1522,14 +1523,15 @@ public function file($fieldName, $options = array()) {
$options['secure'] = static::SECURE_SKIP;
$options = $this->_initInputField($fieldName, $options);
- $field = $this->entity();
foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $suffix) {
- $this->_secure($secure, array_merge($field, array($suffix)));
+ $this->_secure(
+ $secure,
+ $this->_secureFieldName(['name' => $options['name'] . '[' . $suffix . ']'])
+ );
}
- $exclude = array('name' => null, 'value' => null);
- return $this->Html->useTag('file', $options['name'], array_diff_key($options, $exclude));
+ return $this->widget('file', $options);
}
/**
View
@@ -54,7 +54,8 @@ public function render(array $data) {
'escape' => true,
];
unset($data['val']);
- return $this->_templates->format('fileinput', [
+
+ return $this->_templates->format('file', [
'name' => $data['name'],
'attrs' => $this->_templates->formatAttributes(
$data, ['name', 'val']
@@ -1886,14 +1886,13 @@ public function testSecuredInputCustomName() {
* @return void
*/
public function testFormSecuredFileInput() {
- $this->markTestIncomplete('Need to revisit once models work again.');
- $this->Form->request->params['_csrfToken'] = 'testKey';
$this->assertEquals(array(), $this->Form->fields);
$this->Form->file('Attachment.file');
$expected = array(
- 'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name',
- 'Attachment.file.error', 'Attachment.file.size'
+ 'Attachment.file.name', 'Attachment.file.type',
+ 'Attachment.file.tmp_name', 'Attachment.file.error',
+ 'Attachment.file.size'
);
$this->assertEquals($expected, $this->Form->fields);
}
@@ -6818,25 +6817,21 @@ public function testHiddenField() {
* @return void
*/
public function testFileUploadField() {
- $this->markTestIncomplete('Need to revisit once models work again.');
+ $expected = ['input' => ['type' => 'file', 'name' => 'Model[upload]']];
+
$result = $this->Form->file('Model.upload');
- $this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'Model[upload]', 'id' => 'ModelUpload')));
+ $this->assertTags($result, $expected);
- $this->Form->request->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0);
- $result = $this->Form->input('Model.upload', array('type' => 'file'));
- $expected = array(
- 'div' => array('class' => 'input file'),
- 'label' => array('for' => 'ModelUpload'),
- 'Upload',
- '/label',
- 'input' => array('type' => 'file', 'name' => 'Model[upload]', 'id' => 'ModelUpload'),
- '/div'
- );
+ $this->Form->request->data['Model']['upload'] = [
+ 'name' => '', 'type' => '', 'tmp_name' => '',
+ 'error' => 4, 'size' => 0
+ ];
+ $result = $this->Form->file('Model.upload');
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['upload'] = 'no data should be set in value';
$result = $this->Form->file('Model.upload');
- $this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'Model[upload]', 'id' => 'ModelUpload')));
+ $this->assertTags($result, $expected);
}
/**
@@ -6845,11 +6840,10 @@ public function testFileUploadField() {
* @return void
*/
public function testFileUploadOnOtherModel() {
- $this->markTestIncomplete('Need to revisit once models work again.');
- $this->Form->create('ValidateUser', array('type' => 'file'));
+ $this->Form->create($this->article, array('type' => 'file'));
$result = $this->Form->file('ValidateProfile.city');
$expected = array(
- 'input' => array('type' => 'file', 'name' => 'ValidateProfile[city]', 'id' => 'ValidateProfileCity')
+ 'input' => array('type' => 'file', 'name' => 'ValidateProfile[city]')
);
$this->assertTags($result, $expected);
}
@@ -31,7 +31,7 @@ class FileTest extends TestCase {
public function setUp() {
parent::setUp();
$templates = [
- 'fileinput' => '<input type="file" name="{{name}}"{{attrs}}>',
+ 'file' => '<input type="file" name="{{name}}"{{attrs}}>',
];
$this->templates = new StringTemplate($templates);
}

0 comments on commit e572156

Please sign in to comment.