Hello,

I have an action that accepts file uploads from a desktop program.
I use a form for validation (see below) and if the form is valid, I
process the uploaded files(see action below). This works as expected.

But the functional tests (see below) do not upload any file (result see
below, result 37 shows, that no file is uploaded, but only the path, and
39 shows that the sfFileValidator complains that the file is required).

I checked the docs, but I only found this
(http://www.symfony-project.org/jobeet/1_4/Doctrine/en/11): "The browser
also simulates file uploads if you pass the absolute path to the file to
upload." which either I don't understand or doesn't work.

Has anyone done file uploads in a functional test, and how?

Thanks
Georg

my functional test:
__________________
$in2 = array('path' => '/path',
  'md5' => 'e1aab77d216d8ad97ff143823a75038e',
  'ci' => '0123456789abcdef0123456789abcdef',
  'file' =>
'/var/www/shared/appxxx/test/fixtures/testdata/images/IMG_0283.JPG');

$browser = new sfTestFunctional(new sfBrowser());
$browser->
//...
info('post remote/upload - returns OK')->
  post('http://client.virtual/remote/upload', $in2)->
  with('request')->begin()->
    isParameter('module', 'remote')->
    isParameter('action', 'upload')->
    isParameter('ci', '0123456789abcdef0123456789abcdef')->
    isParameter('md5', 'e1aab77d216d8ad97ff143823a75038e')->
    isParameter('path', '/path')->
    isParameter('file', '')->
  end()->
  with('response')->begin()->
    isStatusCode(200)->
    matches('#OK#')->
  end();
__________________

the validation form:
__________________
class UploadForm extends BaseForm {

public function configure() {
  $this->setValidators(array(
    'ci' => new sfValidatorString(array('max_length' => 32, 'min_length'
=> 32)),
    'path' => new sfValidatorDoctrineChoice(array('model' => 'Path',
'column' => 'path')),
    'md5' => new sfValidatorString(array('max_length' => 32,
'min_length' => 32)),
    'file' => new sfValidatorFile(array('max_size' => 200000,
'mime_types' => 'web_images')),
      'module' => new sfValidatorPass(),
      'action' => new sfValidatorPass(),
     ));
   $this->disableLocalCSRFProtection();
  }
}
______________________
 and the action looks like this:
______________________
public function executeUpload(sfWebRequest $request) {
  if ($request->isMethod('post')) {
  $this->form = new UploadForm();
  $this->form->bind($request->getParameterHolder()->getAll(),
$request->getFiles());
  if ($this->form->isValid()) {
    // to something
    return $this->renderText('OK');
  } else {
    $result = 'ERROR: ';
    foreach($this->form->getErrorSchema()->getErrors() as $k => $error) {
      $result .= "\n$k: " . $error->getMessage();
    }
    return $this->renderText($result);
  }
}
return $this->renderText('ERROR Invalid method');
}
______________________
and the test result:
______________________
not ok 37 - request parameter file is ""
#     Failed test
(./lib/vendor/symfony/lib/test/sfTesterRequest.class.php at line 48)
#            got:
'/var/www/shared/appxxx/test/fixtures/testdata/images/IMG_0283.JPG'
#       expected: ''
ok 38 - status code is 200
not ok 39 - response content matches regex #OK#
#     Failed test
(./lib/vendor/symfony/lib/test/sfTesterResponse.class.php at line 383)
#                     'ERROR:
file: Required.'
#       doesn't match '#OK#'

--

You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-us...@googlegroups.com.
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en.


Reply via email to