Skip to content

Commit

Permalink
[DomCrawler] Added ability to set file as raw path to file field
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Sep 19, 2012
1 parent c0673d7 commit c902966
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Symfony/Component/DomCrawler/CHANGELOG.md
@@ -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
-----

Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/DomCrawler/Field/FileFormField.php
Expand Up @@ -76,6 +76,16 @@ public function setValue($value)
$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.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/Field/FileFormFieldTest.php
Expand Up @@ -84,4 +84,14 @@ public function testSetErrorCode()
$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());
}

}

0 comments on commit c902966

Please sign in to comment.