|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Netgen\Bundle\EnhancedBinaryFileBundle\Tests\FieldHandler; |
| 4 | + |
| 5 | +use eZ\Publish\Core\IO\IOServiceInterface; |
| 6 | +use eZ\Publish\Core\IO\Values\BinaryFileCreateStruct; |
| 7 | +use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; |
| 8 | +use Netgen\Bundle\EnhancedBinaryFileBundle\FieldHandler\EnhancedBinaryFileHandler; |
| 9 | +use Netgen\Bundle\InformationCollectionBundle\FieldHandler\Custom\CustomLegacyFieldHandlerInterface; |
| 10 | +use Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile\Value; |
| 11 | +use eZ\Publish\Core\FieldType\Integer\Value as IntValue; |
| 12 | +use eZ\Publish\Core\IO\Values\BinaryFile; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class EnhancedBinaryFileHandlerTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 19 | + */ |
| 20 | + protected $io; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var EnhancedBinaryFileHandler |
| 24 | + */ |
| 25 | + protected $handler; |
| 26 | + |
| 27 | + public function setUp() |
| 28 | + { |
| 29 | + $this->io = $this->createMock(IOServiceInterface::class); |
| 30 | + $this->handler = new EnhancedBinaryFileHandler($this->io); |
| 31 | + } |
| 32 | + |
| 33 | + public function testInstanceOfCustomLegacyFieldHandlerInterface() |
| 34 | + { |
| 35 | + $this->assertInstanceOf(CustomLegacyFieldHandlerInterface::class, $this->handler); |
| 36 | + } |
| 37 | + |
| 38 | + public function testSupports() |
| 39 | + { |
| 40 | + $this->assertTrue($this->handler->supports(new Value())); |
| 41 | + $this->assertFalse($this->handler->supports(new IntValue(1))); |
| 42 | + } |
| 43 | + |
| 44 | + public function testToString() |
| 45 | + { |
| 46 | + $file = new Value( |
| 47 | + [ |
| 48 | + 'path' => __DIR__ . '/test.txt', |
| 49 | + ] |
| 50 | + ); |
| 51 | + |
| 52 | + $this->assertEquals("", $this->handler->toString($file, new FieldDefinition())); |
| 53 | + } |
| 54 | + |
| 55 | + public function testGetLegacyValue() |
| 56 | + { |
| 57 | + $file = new Value( |
| 58 | + [ |
| 59 | + 'path' => __DIR__ . '/test.txt', |
| 60 | + ] |
| 61 | + ); |
| 62 | + |
| 63 | + $struct = new BinaryFileCreateStruct(); |
| 64 | + $binaryFile = new BinaryFile(); |
| 65 | + |
| 66 | + $this->io->expects($this->once()) |
| 67 | + ->method('newBinaryCreateStructFromLocalFile') |
| 68 | + ->with($file->inputUri) |
| 69 | + ->willReturn($struct); |
| 70 | + |
| 71 | + $this->io->expects($this->once()) |
| 72 | + ->method('createBinaryFile') |
| 73 | + ->with($struct) |
| 74 | + ->willReturn($binaryFile); |
| 75 | + |
| 76 | + $data = $this->handler->getLegacyValue($file, new FieldDefinition(['id' => 123])); |
| 77 | + } |
| 78 | +} |
0 commit comments