/** * Test that the configured mappings are accessed * correctly. */ public function testConfiguredMappingAccess() { $prop = new PropertyMapping(); $prop->setMapping(array('delete_on_remove' => true, 'delete_on_update' => true, 'upload_destination' => '/tmp', 'inject_on_load' => true)); $this->assertEquals($prop->getUploadDir(), '/tmp'); $this->assertTrue($prop->getDeleteOnRemove()); $this->assertTrue($prop->getInjectOnLoad()); }
/** * Test that the configured mappings are accessed * correctly. */ public function testConfiguredMappingAccess() { $object = new DummyEntity(); $prop = new PropertyMapping('file', 'fileName'); $prop->setMapping(array('upload_destination' => '/tmp', 'delete_on_remove' => true, 'delete_on_update' => true, 'inject_on_load' => false)); $this->assertEquals('', $prop->getUploadDir($object)); $this->assertEquals('/tmp', $prop->getUploadDestination()); $this->assertEquals('file', $prop->getFilePropertyName()); $this->assertEquals('fileName', $prop->getFileNamePropertyName()); $this->assertTrue($prop->getDeleteOnRemove()); $this->assertTrue($prop->getDeleteOnUpdate()); $this->assertFalse($prop->getInjectOnLoad()); }
/** * {@inheritDoc} */ public function upload($obj, PropertyMapping $mapping) { $file = $mapping->getFile($obj); if ($file === null || !$file instanceof UploadedFile) { throw new \LogicException('No uploadable file found'); } // determine the file's directory $dir = $mapping->getUploadDir($obj); // determine the file's name if ($mapping->hasNamer()) { $name = $mapping->getNamer()->name($obj, $mapping); } else { $name = $file->getClientOriginalName(); } $mapping->setFileName($obj, $name); $this->doUpload($mapping, $file, $dir, $name); }