|
10 | 10 |
|
11 | 11 | require_once(__DIR__.'/../../bootstrap/unit.php'); |
12 | 12 |
|
13 | | -$t = new lime_test(85); |
| 13 | +$t = new lime_test(94); |
14 | 14 |
|
15 | 15 | class PreValidator extends sfValidatorBase |
16 | 16 | { |
@@ -48,6 +48,14 @@ protected function doClean($values) |
48 | 48 | } |
49 | 49 | } |
50 | 50 |
|
| 51 | +class BytesValidatorSchema extends sfValidatorSchema |
| 52 | +{ |
| 53 | + public function getBytes($value) |
| 54 | + { |
| 55 | + return parent::getBytes($value); |
| 56 | + } |
| 57 | +} |
| 58 | + |
51 | 59 | $v1 = new sfValidatorString(array('max_length' => 3)); |
52 | 60 | $v2 = new sfValidatorString(array('min_length' => 3)); |
53 | 61 |
|
@@ -401,3 +409,15 @@ protected function doClean($values) |
401 | 409 | $t->ok($v1->getPreValidator() == $v->getPreValidator(), '__clone() clones the pre validator'); |
402 | 410 | $t->ok($v1->getPostValidator() !== $v->getPostValidator(), '__clone() clones the post validator'); |
403 | 411 | $t->ok($v1->getPostValidator() == $v->getPostValidator(), '__clone() clones the post validator'); |
| 412 | + |
| 413 | +$t->diag('convert post_max_size to bytes'); |
| 414 | +$v = new BytesValidatorSchema(); |
| 415 | +$t->is($v->getBytes(null), 0, 'empty string considered as 0 bytes'); |
| 416 | +$t->is($v->getBytes(''), 0, 'empty string considered as 0 bytes'); |
| 417 | +$t->is($v->getBytes('0'), 0, 'simple bytes'); |
| 418 | +$t->is($v->getBytes('1'), 1, 'simple bytes'); |
| 419 | +$t->is($v->getBytes('1B'), 1, 'simple bytes'); |
| 420 | +$t->is($v->getBytes('1K'), 1024, 'kilobytes'); |
| 421 | +$t->is($v->getBytes('1M'), 1024 * 1024, 'megabytes short syntax'); |
| 422 | +$t->is($v->getBytes('0.5M'), 1024 * 1024 / 2, 'fractional megabytes'); |
| 423 | +$t->is($v->getBytes('1G'), 1024 * 1024 * 1024, 'gigabytes'); |
0 commit comments