Skip to content

Commit fddcd58

Browse files
committed
Complete Type test
1 parent 8b6e37e commit fddcd58

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

tests/Core/FieldType/EnhancedBinaryFile/TypeTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,46 @@ public function testValidateWithMineTypesFromConfig()
127127

128128
$this->type->validate($fieldDefinition, $value);
129129
}
130+
131+
public function testValidateFieldSettingsWithEmptyArray()
132+
{
133+
$result = $this->type->validateFieldSettings([]);
134+
$this->assertTrue(is_array($result));
135+
$this->assertTrue(empty($result));
136+
}
137+
138+
public function testValidateFieldSettingsWithBool()
139+
{
140+
$result = $this->type->validateFieldSettings(false);
141+
$this->assertTrue(is_array($result));
142+
$this->assertFalse(empty($result));
143+
$this->assertEquals(new ValidationError('Field settings must be in form of an array'), $result[0]);
144+
}
145+
146+
public function testValidateFieldSettingsWithFieldSettings()
147+
{
148+
$fieldSettings = [
149+
"allowedTypes" => [],
150+
"some_settings" => [],
151+
];
152+
$result = $this->type->validateFieldSettings($fieldSettings);
153+
$this->assertTrue(is_array($result));
154+
$this->assertFalse(empty($result));
155+
$this->assertEquals(
156+
new ValidationError(
157+
"Setting '%setting%' is unknown",
158+
null,
159+
['setting' => 'some_settings']
160+
),
161+
$result[0]
162+
);
163+
}
164+
165+
public function testFromHash()
166+
{
167+
$result = $this->type->fromHash([]);
168+
169+
$this->assertInstanceOf(Value::class, $result);
170+
$this->assertEquals(new Value(), $result);
171+
}
130172
}

tests/Form/FieldTypeHandler/EnhancedFileTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
namespace Netgen\Bundle\EnhancedBinaryFileBundle\Tests\Form\FieldTypeHandler;
44

55
use eZ\Publish\Core\MVC\ConfigResolverInterface;
6+
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition;
67
use Netgen\Bundle\EnhancedBinaryFileBundle\Core\FieldType\EnhancedBinaryFile\Value;
78
use Netgen\Bundle\EnhancedBinaryFileBundle\Form\FieldTypeHandler\EnhancedFile;
89
use Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler;
910
use PHPUnit\Framework\TestCase;
10-
use Symfony\Component\Finder\SplFileInfo;
11+
use Symfony\Component\Form\FormBuilderInterface;
1112
use Symfony\Component\HttpFoundation\File\UploadedFile;
1213

1314
class EnhancedFileTest extends TestCase
1415
{
1516
/**
1617
* @var EnhancedFile
1718
*/
18-
protected $handler;
19+
protected $handler;
1920

2021
/**
2122
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -55,4 +56,12 @@ public function testConvertFieldValueFromFormWithFile()
5556
$this->assertEquals($file->getSize(), $result['fileSize']);
5657
$this->assertEquals($file->getClientMimeType(), $result['mimeType']);
5758
}
59+
60+
public function testBuildFieldCreateForm()
61+
{
62+
$formBuilder = $this->createMock(FormBuilderInterface::class);
63+
$fieldDefinition = new FieldDefinition();
64+
$lang = 'eng_US';
65+
$this->handler->buildFieldCreateForm($formBuilder, $fieldDefinition, $lang);
66+
}
5867
}

0 commit comments

Comments
 (0)