Skip to content

Commit 6f730c0

Browse files
committed
added unit test for sfValidatorSchema::getBytes
1 parent da63591 commit 6f730c0

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/unit/validator/sfValidatorSchemaTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
require_once(__DIR__.'/../../bootstrap/unit.php');
1212

13-
$t = new lime_test(85);
13+
$t = new lime_test(103);
1414

1515
class PreValidator extends sfValidatorBase
1616
{
@@ -48,6 +48,14 @@ protected function doClean($values)
4848
}
4949
}
5050

51+
class BytesValidatorSchema extends sfValidatorSchema
52+
{
53+
public function getBytes($value)
54+
{
55+
return parent::getBytes($value);
56+
}
57+
}
58+
5159
$v1 = new sfValidatorString(array('max_length' => 3));
5260
$v2 = new sfValidatorString(array('min_length' => 3));
5361

@@ -401,3 +409,24 @@ protected function doClean($values)
401409
$t->ok($v1->getPreValidator() == $v->getPreValidator(), '__clone() clones the pre validator');
402410
$t->ok($v1->getPostValidator() !== $v->getPostValidator(), '__clone() clones the post validator');
403411
$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 short syntax');
421+
$t->is($v->getBytes('1 K'), 1024, 'kilobytes short syntax with space delimiter');
422+
$t->is($v->getBytes('1KB'), 1024, 'kilobytes long syntax');
423+
$t->is($v->getBytes('1 KB'), 1024, 'kilobytes long syntax with space delimiter');
424+
$t->is($v->getBytes('1M'), 1024 * 1024, 'megabytes short syntax');
425+
$t->is($v->getBytes('0.5M'), 1024 * 1024 / 2, 'fractional megabytes short syntax');
426+
$t->is($v->getBytes('0.5 M'), 1024 * 1024 / 2, 'fractional megabytes short syntax with space delimeter');
427+
$t->is($v->getBytes('1 G'), 1024 * 1024 * 1024, 'gigabytes');
428+
$t->is($v->getBytes('1 T'), 1024 * 1024 * 1024 * 1024, 'terabytes');
429+
$t->is($v->getBytes('1 P'), 1024 * 1024 * 1024 * 1024 * 1024, 'petabytes');
430+
$t->is($v->getBytes('1 E'), 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'exabytes');
431+
$t->is($v->getBytes('1 Z'), 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'zettabytes');
432+
$t->is($v->getBytes('1 Y'), 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'yottabytes');

0 commit comments

Comments
 (0)