Added tests

This commit is contained in:
spiliot 2013-04-22 03:42:19 +03:00
parent 50e3307f00
commit 2d7f6fc707
2 changed files with 14 additions and 5 deletions

View file

@ -1958,29 +1958,38 @@ class ValidationTest extends CakeTestCase {
* @return void
*/
public function testMoney() {
$this->assertTrue(Validation::money('100'));
$this->assertTrue(Validation::money('100.11'));
$this->assertTrue(Validation::money('100.112'));
$this->assertTrue(Validation::money('100.1'));
$this->assertTrue(Validation::money('100.111,1'));
$this->assertTrue(Validation::money('100.111,11'));
$this->assertFalse(Validation::money('100.111,111'));
$this->assertFalse(Validation::money('text'));
$this->assertTrue(Validation::money('$100'));
$this->assertTrue(Validation::money('$100.11'));
$this->assertTrue(Validation::money('$100.112'));
$this->assertFalse(Validation::money('$100.1'));
$this->assertTrue(Validation::money('$100.1'));
$this->assertFalse(Validation::money('$100.1111'));
$this->assertFalse(Validation::money('text'));
$this->assertTrue(Validation::money('100', 'right'));
$this->assertTrue(Validation::money('100.11$', 'right'));
$this->assertTrue(Validation::money('100.112$', 'right'));
$this->assertFalse(Validation::money('100.1$', 'right'));
$this->assertTrue(Validation::money('100.1$', 'right'));
$this->assertFalse(Validation::money('100.1111$', 'right'));
$this->assertTrue(Validation::money('€100'));
$this->assertTrue(Validation::money('€100.11'));
$this->assertTrue(Validation::money('€100.112'));
$this->assertFalse(Validation::money('€100.1'));
$this->assertTrue(Validation::money('€100.1'));
$this->assertFalse(Validation::money('€100.1111'));
$this->assertTrue(Validation::money('100', 'right'));
$this->assertTrue(Validation::money('100.11€', 'right'));
$this->assertTrue(Validation::money('100.112€', 'right'));
$this->assertFalse(Validation::money('100.1€', 'right'));
$this->assertTrue(Validation::money('100.1€', 'right'));
$this->assertFalse(Validation::money('100.1111€', 'right'));
}

View file

@ -528,7 +528,7 @@ class Validation {
* @return boolean Success
*/
public static function money($check, $symbolPosition = 'left') {
$money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1})?';
$money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1,2})?';
if ($symbolPosition === 'right') {
$regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u';
} else {