$node =
$this->
createNode('input', '',
['type' => 'file'
]);
$field =
new FileFormField($node);
$field->
$method(null
);
$this->
assertEquals(['name' => '', 'type' => '', 'tmp_name' => '', 'error' => \UPLOAD_ERR_NO_FILE, 'size' => 0
],
$field->
getValue(), "->
$method() clears the uploaded file if the value is null"
);
$field->
$method(__FILE__
);
$value =
$field->
getValue();
$this->
assertEquals(basename(__FILE__
),
$value['name'
], "->
$method() sets the name of the file field"
);
$this->
assertEquals('',
$value['type'
], "->
$method() sets the type of the file field"
);
$this->
assertIsString($value['tmp_name'
], "->
$method() sets the tmp_name of the file field"
);
$this->
assertFileExists($value['tmp_name'
], "->
$method() creates a copy of the file at the tmp_name path"
);
$this->
assertEquals(0,
$value['error'
], "->
$method() sets the error of the file field"
);
$this->
assertEquals(filesize(__FILE__
),
$value['size'
], "->
$method() sets the size of the file field"
);
$origInfo =
pathinfo(__FILE__
);
$tmpInfo =
pathinfo($value['tmp_name'
]);
$this->
assertEquals( $origInfo['extension'
],
$tmpInfo['extension'
],
"->
$method() keeps the same file extension in the tmp_name copy"
);