[DomCrawler] Added ability to set file as raw path to file field

This commit is contained in:
Martin Hasoň 2012-08-31 15:38:13 +02:00
parent c0673d77d0
commit c9029664ad
3 changed files with 26 additions and 0 deletions

View File

@ -1,6 +1,12 @@
CHANGELOG
=========
2.2.0
-----
* added a way to set raw path to the file in FileFormField - necessary for
simulating HTTP requests
2.1.0
-----

View File

@ -76,6 +76,16 @@ class FileFormField extends FormField
$this->value = array('name' => $name, 'type' => '', 'tmp_name' => $value, 'error' => $error, 'size' => $size);
}
/**
* Sets path to the file as string for simulating HTTP request
*
* @param string $path The path to the file
*/
public function setFilePath($path)
{
parent::setValue($path);
}
/**
* Initializes the form field.
*

View File

@ -84,4 +84,14 @@ class FileFormFieldTest extends FormFieldTestCase
$this->assertTrue(true, '->setErrorCode() throws a \InvalidArgumentException if the error code is not valid');
}
}
public function testSetRawFilePath()
{
$node = $this->createNode('input', '', array('type' => 'file'));
$field = new FileFormField($node);
$field->setFilePath(__FILE__);
$this->assertEquals(__FILE__, $field->getValue());
}
}