Skip to content

Commit

Permalink
Merge pull request dustin10#405 from Restless-ET/patch-1
Browse files Browse the repository at this point in the history
Fix default filename suffix usage
  • Loading branch information
K-Phoen committed Jun 30, 2015
2 parents 3cc9e87 + 4a9d075 commit d6a9730
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Mapping/PropertyMappingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function createMapping($obj, $fieldName, array $mappingData)

$config = $this->mappings[$mappingData['mapping']];
$fileProperty = isset($mappingData['propertyName']) ? $mappingData['propertyName'] : $fieldName;
$fileNameProperty = empty($mappingData['fileNameProperty']) ? $fileProperty . '_name' : $mappingData['fileNameProperty'];
$fileNameProperty = empty($mappingData['fileNameProperty']) ? $fileProperty . $this->defaultFilenameAttributeSuffix : $mappingData['fileNameProperty'];

$mapping = new PropertyMapping($fileProperty, $fileNameProperty);
$mapping->setMappingName($mappingData['mapping']);
Expand Down
30 changes: 30 additions & 0 deletions Tests/Mapping/PropertyMappingFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,36 @@ public function testFromFieldReturnsNullOnInvalidFieldName()
$this->assertNull($mapping);
}

public function testCustomFileNameProperty()
{
$mappings = array(
'dummy_file' => array(
'namer' => false,
'directory_namer' => false
)
);

$this->metadata
->expects($this->once())
->method('isUploadable')
->with('Vich\UploaderBundle\Tests\DummyEntity')
->will($this->returnValue(true));

$this->metadata
->expects($this->once())
->method('getUploadableField')
->with('Vich\UploaderBundle\Tests\DummyEntity')
->will($this->returnValue(array(
'mapping' => 'dummy_file',
'propertyName' => 'file'
)));

$factory = new PropertyMappingFactory($this->container, $this->metadata, $mappings, '_suffix');
$mapping = $factory->fromField(new DummyEntity(), 'file');

$this->assertEquals('file_suffix', $mapping->getFileNamePropertyName());
}

public function testConfiguredNamersAreRetrievedFromContainer()
{
$mappings = array(
Expand Down

0 comments on commit d6a9730

Please sign in to comment.