Skip to content

Commit 8b6e37e

Browse files
committed
EnhancedFile form field handler test
1 parent 18fad0d commit 8b6e37e

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"phpunit/phpunit": "^5.7",
2525
"matthiasnoback/symfony-config-test": "~2.0",
2626
"matthiasnoback/symfony-dependency-injection-test": "~1.0",
27-
"friendsofphp/php-cs-fixer": "~2.0"
27+
"friendsofphp/php-cs-fixer": "~2.0",
28+
"netgen/ez-forms-bundle": "^1.3"
2829
},
2930
"suggest": {
3031
"netgen/ez-forms-bundle": "Allows use of Enhanced Binary File with Symfony forms",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}

tests/Form/FieldTypeHandler/test.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)