I found this: http://www.devcomments.com/Uploads-on-functional-test-for-REST-services-to189066.htm#filtered
But I had to modify it a bit to get it working with Symfony 1.4. As a form, I introduced a new class called “Browser”, which extends “sfBrowser” and “TestFunctional”, which extends “sfTestFunctional”.
Browser :: uploadFile ():
I added a parameter of type $ for the content type, otherwise the test will fail ("invalid mime type")
public function uploadFile($fieldName, $filename, $type = '')
{
if (is_readable($filename))
{
$fileError = UPLOAD_ERR_OK;
$fileSize = filesize($filename);
}
else
{
$fileError = UPLOAD_ERR_NO_FILE;
$fileSize = 0;
}
$this->parseArgumentAsArray($fieldName, array('name' => basename($filename), 'type' => $type, 'tmp_name' => $filename, 'error' => $fileError, 'size' => $fileSize), $this->files);
return $this;
}
TestFunctional :: uploadFile ()
public function uploadFile($fieldName, $filename, $type = '')
{
$this->browser->uploadFile($fieldName, $filename, $type);
return $this;
}
You need to take care of the name:
$browser = new TestFunctional(new Browser());
$browser->
uploadFile('article_image[image]', '/path/to/your/image.gif', 'image/gif')->
post('/articles/1/images.json', array('article_image' => array(
'title' => 'foobar',
'description' => 'lorum ipsum'
)))
;