Skip to content
Merged
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
8 changes: 8 additions & 0 deletions core/Form/Primitives/PrimitiveString.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions test/core/PrimitiveStringTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]', '[email protected]', '[email protected]');

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));



}
}
?>