mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Added tests
This commit is contained in:
parent
50e3307f00
commit
2d7f6fc707
2 changed files with 14 additions and 5 deletions
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue