/** * Test that hasser returns correct value. */ public function testIsNew() { $mockFile = $this->getMockBuilder('Reskume\\FileBundle\\Entity\\File')->getMock(); $mockFile->expects($this->any())->method('isTmpFile')->willReturn(true); $attachment = new Attachment(); $attachment->setFile($mockFile); $this->assertTrue($attachment->isNew()); }
/** * 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); }