Skip to content

Commit 405e45e

Browse files
committed
Merge pull request #92 from soloweb/featurePrimitiveString
PrimitiveString::getAllowedPattern
2 parents 792b27e + aa9007a commit 405e45e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

core/Form/Primitives/PrimitiveString.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class PrimitiveString extends FiltrablePrimitive
2121
const MD5_PATTERN = '/^[0-9a-f]{32}$/';
2222

2323
protected $pattern = null;
24+
25+
/**
26+
* @return null|string
27+
*/
28+
public function getAllowedPattern()
29+
{
30+
return $this->pattern;
31+
}
2432

2533
/**
2634
* @return PrimitiveString

test/core/PrimitiveStringTest.class.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,38 @@ public function testImport()
1010

1111
foreach ($nullValues as $value)
1212
$this->assertNull($prm->importValue($value));
13-
13+
14+
$prm->clean();
1415
$falseValues = array(array(), true, false, $prm);
1516

1617
foreach ($falseValues as $value)
1718
$this->assertFalse($prm->importValue($value));
18-
19+
20+
$prm->clean();
1921
$trueValues = array('some string', -100500, 2011.09);
2022

2123
foreach ($trueValues as $value)
2224
$this->assertTrue($prm->importValue($value));
25+
26+
27+
$prm->setAllowedPattern(
28+
PrimitiveString::MAIL_PATTERN
29+
);
30+
31+
$prm->clean();
32+
33+
34+
foreach ($trueValues as $value)
35+
$this->assertTrue($prm->importValue($value));
36+
37+
$prm->clean();
38+
$falseValues = array('example.com', 100500, 2012.04);
39+
40+
foreach ($falseValues as $value)
41+
$this->assertFalse($prm->importValue($value));
42+
43+
44+
2345
}
2446
}
2547
?>

0 commit comments

Comments
 (0)