diff --git a/core/Form/Primitives/PrimitiveString.class.php b/core/Form/Primitives/PrimitiveString.class.php index 192feb7a98..6e5d31b66d 100644 --- a/core/Form/Primitives/PrimitiveString.class.php +++ b/core/Form/Primitives/PrimitiveString.class.php @@ -21,6 +21,14 @@ class PrimitiveString extends FiltrablePrimitive const MD5_PATTERN = '/^[0-9a-f]{32}$/'; protected $pattern = null; + + /** + * @return null|string + */ + public function getAllowedPattern() + { + return $this->pattern; + } /** * @return PrimitiveString diff --git a/test/core/PrimitiveStringTest.class.php b/test/core/PrimitiveStringTest.class.php index 386e1933d2..6a3ce95fc3 100644 --- a/test/core/PrimitiveStringTest.class.php +++ b/test/core/PrimitiveStringTest.class.php @@ -10,16 +10,38 @@ public function testImport() foreach ($nullValues as $value) $this->assertNull($prm->importValue($value)); - + + $prm->clean(); $falseValues = array(array(), true, false, $prm); foreach ($falseValues as $value) $this->assertFalse($prm->importValue($value)); - + + $prm->clean(); $trueValues = array('some string', -100500, 2011.09); foreach ($trueValues as $value) $this->assertTrue($prm->importValue($value)); + + + $prm->setAllowedPattern( + PrimitiveString::MAIL_PATTERN + ); + + $prm->clean(); + $trueValues = array('me@example.com', 'example@example.com', 'i.ivanov@example.com'); + + foreach ($trueValues as $value) + $this->assertTrue($prm->importValue($value)); + + $prm->clean(); + $falseValues = array('example.com', 100500, 2012.04); + + foreach ($falseValues as $value) + $this->assertFalse($prm->importValue($value)); + + + } } ?> \ No newline at end of file