From c69fa9ffbabc6385d1e2f769d511d9b729df7a0c Mon Sep 17 00:00:00 2001 From: "Timofey A. Anisimov" Date: Tue, 11 Dec 2012 18:43:19 +0400 Subject: [PATCH] fix non existing enumeration import --- .../Primitives/PrimitiveEnumeration.class.php | 1 + test/core/PrimitiveEnumerationTest.class.php | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/core/Form/Primitives/PrimitiveEnumeration.class.php b/core/Form/Primitives/PrimitiveEnumeration.class.php index 59e6d0d256..b07f15fa20 100644 --- a/core/Form/Primitives/PrimitiveEnumeration.class.php +++ b/core/Form/Primitives/PrimitiveEnumeration.class.php @@ -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; } diff --git a/test/core/PrimitiveEnumerationTest.class.php b/test/core/PrimitiveEnumerationTest.class.php index 42ad1d8bf5..8f5a63e94d 100644 --- a/test/core/PrimitiveEnumerationTest.class.php +++ b/test/core/PrimitiveEnumerationTest.class.php @@ -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')); @@ -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') + ); + } } ?> \ No newline at end of file