function testReverseTransformNoDeleteFile() { $propertyMapping = Mocks::getPropertyMappingMock($this); $file = Mocks::getFileMock($this); $this->transformer->setMapping($propertyMapping, FileDataTransformer::MODE_UPLOAD_FIELD); $this->fileStorage->expects($this->never())->method('removeFile'); $this->assertSame($this->transformer->reverseTransform(array('delete' => 0, 'file' => $file, 'fileName' => '123.jpg')), $file); }
public function testPropertyRenameByMultiple() { $obj = new DummyEntity(); $obj->setId(12345); $file = Mocks::getFileMock($this); $file->expects($this->once())->method('getSize')->will($this->returnValue('100')); $obj->setFile($file); $propertyMapping = $this->getMappingWithObject($obj); $this->assertSame($this->namer->propertyRename($propertyMapping, 'some-name.jpg', array('field' => 'id/file.size')), '12345/100'); }
public function testGetPropertyName() { $obj = new DummyEntitySeparateDataField(); $class = new \ReflectionClass($obj); $file = Mocks::getFileMock($this); $propertyMapping = $this->getPropertyMapping($obj); $propertyMapping->setFileUploadProperty($class->getProperty('file')); $this->assertSame($propertyMapping->getFileUploadPropertyName(), 'file'); $propertyMapping->setFileDataProperty($class->getProperty('file_data')); $this->assertSame($propertyMapping->getFileDataPropertyName(), 'file_data'); $propertyMapping->setFileUploadPropertyValue($file); $this->assertSame($propertyMapping->getFileUploadPropertyValue(), $file); $propertyMapping->setFileDataPropertyValue(array(1)); $this->assertSame($propertyMapping->getFileDataPropertyValue(), array(1)); }
/** * Test the postFlush method has deferred files */ public function testPostFlushHasDeferred() { $args = Mocks::getEventArgsMock($this); $obj = new DummyEntity(); $file = Mocks::getFileMock($this); $propertyMapping = $this->createFilledPropertyMapping($file); $this->setDataStorageObjectMapping($obj, $propertyMapping); $listener = $this->getUploaderListener(); $listener->prePersist(Mocks::getEventArgsMock($this)); $this->assertEquals($listener->getDeferredObjectNum(), 1); $this->fileStorage->expects($this->once())->method('upload')->with($propertyMapping, $file)->will($this->returnValue(array('fileName' => 'NEW_NAME'))); $propertyMapping->expects($this->once())->method('setFileDataPropertyValue')->with(array('fileName' => 'NEW_NAME')); $this->dataStorage->expects($this->once())->method('postFlush'); $listener->postFlush($args); $this->assertEquals($listener->getDeferredObjectNum(), 0); }