/**
  * Test that a base64 encoded string is returned for the specified pathname.
  */
 public function testCreateUploadThumbnailReturnBase64EncodedString()
 {
     $mockEntityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $configuration = new TestFileStorageConfiguration();
     $twigExtension = new ReskumeFileBundleExtension($configuration, $mockEntityManager);
     $file = new File();
     $file->setTmpPathname(TestPathProvider::getPath() . '/Fixtures/files/test_image.jpeg');
     $this->assertEquals(ThumbnailHelper::getBase64Thumb(new HttpFile(TestPathProvider::getPath() . '/Fixtures/files/thumbs/thumb_test_image.jpeg')), $twigExtension->createThumbnailFunction($file));
     $this->assertEquals(ThumbnailHelper::getBase64Thumb(new HttpFile(TestPathProvider::getPath() . '/Fixtures/files/thumbs/thumb_test_image.jpeg')), $twigExtension->createThumbnailFunction($file, 'base64'));
 }
 /**
  * Test that MIME types that are defined as "not allowed" in the upload configuration class trigger a validation
  * error.
  */
 public function testInvalidUploadConfigMimeTypeNotAllowed()
 {
     $file = new File();
     $file->setTmpPathname(TestPathProvider::getPath() . '/Fixtures/files/test_image.bmp')->setOrigFilename('test_image.jpeg')->setPath('/test/storage/path')->setFileMetadata();
     $attachment = new Attachment();
     $attachment->setFile($file)->setDescription('This is a test description.');
     $constraintViolationBuilder = $this->getMockBuilder('Symfony\\Component\\Validator\\Violation\\ConstraintViolationBuilder')->disableOriginalConstructor()->getMock();
     $mockContext = $this->getMockBuilder('Symfony\\Component\\Validator\\Context\\ExecutionContextInterface')->disableOriginalConstructor()->getMock();
     $mockContext->expects($this->once())->method('buildViolation')->willReturn($constraintViolationBuilder);
     $constraintViolationBuilder->expects($this->any())->method('setParameter')->willReturnSelf();
     $constraintViolationBuilder->expects($this->once())->method('setCode')->willReturnSelf();
     $constraintViolationBuilder->expects($this->once())->method('addViolation');
     $validator = static::$kernel->getContainer()->get('reskume_file.validator.file_attachment');
     $validator->initialize($mockContext);
     $constraint = new FileConstraint();
     $constraint->mimeTypes = array('image/jpeg');
     $validator->validate($attachment, $constraint);
 }
Example #3
0
 /**
  * @return File
  */
 public function create()
 {
     $file = new File();
     $file->setTmpPathname(TestPathProvider::getPath() . '/Fixtures/files/test.txt')->setOrigFilename('test.txt')->setPath('/test/storage/path')->setFileMetadata();
     return $file;
 }
Example #4
0
 /**
  * Test that key string is created.
  */
 public function testCreateKey()
 {
     $file = new File();
     $file->setTmpPathname(TestPathProvider::getPath() . '/Fixtures/files/test.txt')->setFileMetadata()->setPath('/test/path')->createKey();
     $this->assertEquals(1, preg_match('/^(\\/\\w+)+\\.[a-zA-Z]+$/', $file->getKey()));
 }