public function testTranslitRename()
 {
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $this->assertSame($this->namer->translitRename($propertyMapping, 'АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя'), 'aabbvvggddeeeezzzziijjkkllmmnnoopprrssttuuffhhccccssssyyeeuuaa');
     $this->assertSame($this->namer->translitRename($propertyMapping, 'En Français on a des caractères accentués !'), 'en-francais-on-a-des-caracteres-accentues');
     $this->assertSame($this->namer->translitRename($propertyMapping, ' ! , Давай-Давай .'), 'davaj-davaj-.');
 }
 public function testRename()
 {
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $namer = $this->getMockBuilder('Iphp\\FileStoreBundle\\Naming\\DefaultNamer')->disableOriginalConstructor()->getMock();
     $this->container->expects($this->once())->method('get')->with('test.service')->will($this->returnValue($namer));
     $namer->expects($this->once())->method('translitRename')->with($propertyMapping, 'sample file name', array('param' => 1))->will($this->returnValue('sample-file-name'));
     $this->assertSame($this->invoker->rename('test.service', 'translit', $propertyMapping, 'sample file name', array('param' => 1)), 'sample-file-name');
 }
 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);
 }
 protected function createPropertyMapping($resolveFrom, $resolveTo, $targetData = array())
 {
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $propertyMapping->expects($this->any())->method('resolveFileName')->with($resolveFrom)->will($this->returnValue($resolveTo));
     if ($targetData) {
         $propertyMapping->expects($this->any())->method('prepareFileName')->with($resolveFrom, $this->storage)->will($this->returnValue($targetData));
     }
     return $propertyMapping;
 }
 function setUp()
 {
     $this->dataStorage = Mocks::getDataStorageMock($this);
     $this->fileStorage = Mocks::getFileStorageMock($this);
     $this->driver = Mocks::getAnnotationDriverMock($this);
     $this->namerServiceInvoker = Mocks::getNamerServiceInvokerMock($this);
     $this->propertyMappingfactory = Mocks::getPropertyMappingFactoryMock($this, $this->namerServiceInvoker, $this->driver);
     $this->fileType = new FileType($this->propertyMappingfactory, $this->dataStorage, $this->fileStorage);
 }
 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');
 }
 function testPreBind()
 {
     $obj = new DummyEntity();
     $class = new \ReflectionClass($obj);
     $formEvent = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $parentForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $formEvent->expects($this->once())->method('getForm')->will($this->returnValue($form));
     $form->expects($this->once())->method('getParent')->will($this->returnValue($parentForm));
     $parentForm->expects($this->once())->method('getData')->will($this->returnValue($obj));
     $this->dataStorage->expects($this->once())->method('getReflectionClass')->with($obj)->will($this->returnValue($class));
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $this->propertyMappingFactory->expects($this->once())->method('getMappingFromField')->with($obj, $class, 'file')->will($this->returnValue($propertyMapping));
     $form->expects($this->once())->method('getName')->will($this->returnValue('file'));
     $this->transformer->expects($this->once())->method('setMapping')->with($propertyMapping);
     $this->subscriber->preBind($formEvent);
 }
 public function testConfiguredNamerRetrievedFromInvoker()
 {
     $obj = new DummyEntity();
     $class = new \ReflectionClass($obj);
     $mappingsConfig = array('dummy_file' => array('upload_dir' => '/www/web/images', 'upload_path' => '/images', 'namer' => array('translit' => array('service' => 'iphp.filestore.namer.default'))));
     $uploadable = Mocks::getUploadableMock($this);
     $fileField = Mocks::getUploadableFieldMock($this);
     $fileField->expects($this->any())->method('getMapping')->will($this->returnValue('dummy_file'));
     $fileField->expects($this->once())->method('getFileUploadPropertyName')->will($this->returnValue('file'));
     $fileField->expects($this->once())->method('getFileDataPropertyName')->will($this->returnValue('file'));
     $this->driver->expects($this->once())->method('readUploadable')->with($class)->will($this->returnValue($uploadable));
     $this->driver->expects($this->once())->method('readUploadableFields')->with($class)->will($this->returnValue(array($fileField)));
     $factory = new PropertyMappingFactory($this->namerServiceInvoker, $this->driver, $mappingsConfig);
     $mappings = $factory->getMappingsFromObject($obj, $class);
     $this->assertEquals(1, count($mappings));
     if (count($mappings) > 0) {
         $mapping = $mappings[0];
         $this->namerServiceInvoker->expects($this->once())->method('rename')->with('iphp.filestore.namer.default', 'translit', $mapping, 'ab cde', array())->will($this->returnValue('ab-cde'));
         $this->assertEquals($mapping->useFileNamer('ab cde'), 'ab-cde');
         $this->assertTrue($mapping->hasNamer());
     }
 }
 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));
 }
 public function testPostRemoveNoDelete()
 {
     $obj = new DummyEntity();
     $args = Mocks::getEventArgsMock($this);
     $propertyMapping = Mocks::getPropertyMappingMock($this);
     $this->setDataStorageObjectMapping($obj, $propertyMapping);
     $propertyMapping->expects($this->once())->method('getDeleteOnRemove')->will($this->returnValue(false));
     $this->fileStorage->expects($this->never())->method('removeFile');
     $listener = $this->getUploaderListener();
     $listener->postRemove($args);
 }
 /**
  * Test that the driver correctly reads two UploadableField
  * properties.
  */
 public function testReadTwoUploadableFields()
 {
     $fileField = Mocks::getUploadableFieldMock($this);
     $fileField->expects($this->once())->method('setFileUploadPropertyName');
     $imageField = Mocks::getUploadableFieldMock($this);
     $imageField->expects($this->once())->method('setFileUploadPropertyName');
     $entity = new TwoFieldsDummyEntity();
     $class = new \ReflectionClass($entity);
     $reader = $this->getMock('Doctrine\\Common\\Annotations\\Reader');
     $reader->expects($this->any())->method('getPropertyAnnotation')->will($this->returnCallback(function () use($fileField, $imageField) {
         $args = func_get_args();
         if ('file' === $args[0]->getName()) {
             return $fileField;
         } elseif ('image' === $args[0]->getName()) {
             return $imageField;
         }
         return null;
     }));
     $driver = new AnnotationDriver($reader);
     $fields = $driver->readUploadableFields($class);
     $this->assertEquals(2, count($fields));
 }