I found this: http://www.devcomments.com/Uploads-on-functional-test-for-REST-services-to189066.htm#filtered
But I had to modify it a little bit in order to get it to work with Symfony 1.4. As a matter of form I introduced a new class 'Browser', which extends 'sfBrowser' and 'TestFunctional', which extends 'sfTestFunctional'.
Browser::uploadFile():
I added a $type parameter for the content-type, otherwise the test fails ('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 have to take care about naming:
$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'
)))
;