|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Netgen\Bundle\EnhancedBinaryFileBundle\Tests\Form\FieldTypeHandler; |
| 4 | + |
| 5 | +use eZ\Publish\Core\MVC\ConfigResolverInterface; |
| 6 | +use Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile\Value; |
| 7 | +use Netgen\Bundle\EnhancedBinaryFileBundle\Form\FieldTypeHandler\EnhancedFile; |
| 8 | +use Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Symfony\Component\Finder\SplFileInfo; |
| 11 | +use Symfony\Component\HttpFoundation\File\UploadedFile; |
| 12 | + |
| 13 | +class EnhancedFileTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var EnhancedFile |
| 17 | + */ |
| 18 | + protected $handler; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + protected $configResolver; |
| 24 | + |
| 25 | + public function setUp() |
| 26 | + { |
| 27 | + $this->configResolver = $this->createMock(ConfigResolverInterface::class); |
| 28 | + $this->handler = new EnhancedFile($this->configResolver); |
| 29 | + } |
| 30 | + |
| 31 | + public function testInstanceOfFieldTypeHandler() |
| 32 | + { |
| 33 | + $this->assertInstanceOf(FieldTypeHandler::class, $this->handler); |
| 34 | + } |
| 35 | + |
| 36 | + public function testConvertFieldValueToFormShouldDoNothing() |
| 37 | + { |
| 38 | + $this->handler->convertFieldValueToForm(new Value(), null); |
| 39 | + } |
| 40 | + |
| 41 | + public function testConvertFieldValueFromFormWithNull() |
| 42 | + { |
| 43 | + $this->assertNull($this->handler->convertFieldValueFromForm(null)); |
| 44 | + } |
| 45 | + |
| 46 | + public function testConvertFieldValueFromFormWithFile() |
| 47 | + { |
| 48 | + $file = new UploadedFile(__DIR__ . '/test.txt', 'test.txt'); |
| 49 | + $file->getClientMimeType(); |
| 50 | + $result = $this->handler->convertFieldValueFromForm($file); |
| 51 | + |
| 52 | + $this->assertTrue(is_array($result)); |
| 53 | + $this->assertEquals($file->getFileInfo()->getRealPath(), $result['inputUri']); |
| 54 | + $this->assertEquals($file->getClientOriginalName(), $result['fileName']); |
| 55 | + $this->assertEquals($file->getSize(), $result['fileSize']); |
| 56 | + $this->assertEquals($file->getClientMimeType(), $result['mimeType']); |
| 57 | + } |
| 58 | +} |
0 commit comments