Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/Form/Primitives/PrimitiveEnumeration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function import($scope)
$this->value = new $this->className($this->value);
} catch (MissingElementException $e) {
$this->value = null;
$this->imported = false;

return false;
}
Expand Down
32 changes: 27 additions & 5 deletions test/core/PrimitiveEnumerationTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ final class PrimitiveEnumerationTest extends TestCase
{
public function testIntegerValues()
{
$form =
Form::create()->
add(
Primitive::enumeration('enum')->of('DataType')
);
$form = $this->getForm();

$form->import(array('enum' => '4097'));

Expand All @@ -30,5 +26,31 @@ public function testGetList()
$primitive->import(array('enum' => DataType::getAnyId()));
$this->assertEquals($primitive->getList(), $enum->getObjectList());
}

public function testNonExsitingValue()
{
$form = $this->getForm();

$form->get('enum')->
setDefault(DataType::create(DataType::getAnyId()));

$form->import(array('enum' => -10000));

$this->assertFalse($form->get('enum')->isImported());
$this->assertNull($form->getValue('enum'));
$this->assertEquals(
DataType::getAnyId(),
$form->getActualValue('enum')->getId()
);
}

private function getForm()
{
return
Form::create()->
add(
Primitive::enumeration('enum')->of('DataType')
);
}
}
?>