Skip to content

Commit 6fe802e

Browse files
author
Vincent Chabot
committed
Add validator sfValidatorFileMulti
1 parent 6f3b10f commit 6fe802e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

lib/autoload/sfCoreAutoload.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ static public function make()
480480
'sfvalidatorerror' => 'validator/sfValidatorError.class.php',
481481
'sfvalidatorerrorschema' => 'validator/sfValidatorErrorSchema.class.php',
482482
'sfvalidatorfile' => 'validator/sfValidatorFile.class.php',
483+
'sfvalidatorfilemulti' => 'validator/sfValidatorFileMulti.class.php',
483484
'sfvalidatorfromdescription' => 'validator/sfValidatorFromDescription.class.php',
484485
'sfvalidatorinteger' => 'validator/sfValidatorInteger.class.php',
485486
'sfvalidatorip' => 'validator/sfValidatorIp.class.php',
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class sfValidatorFileMulti extends sfValidatorFile
4+
{
5+
6+
/**
7+
* @see sfValidatorBase
8+
*/
9+
protected function doClean($value)
10+
{
11+
$clean = array();
12+
13+
foreach ($value as $file)
14+
{
15+
$clean[] = parent::doClean($file);
16+
}
17+
18+
return $clean;
19+
}
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the symfony package.
5+
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
require_once(__DIR__.'/../../bootstrap/unit.php');
12+
13+
$t = new lime_test(9);
14+
15+
$tmpDir = sys_get_temp_dir();
16+
$content = 'This is an ASCII file.';
17+
$content2 = 'This is an ASCII file. And another one.';
18+
file_put_contents($tmpDir.'/test.txt', $content);
19+
file_put_contents($tmpDir.'/test2.txt', $content2);
20+
21+
// ->clean()
22+
$t->diag('->clean()');
23+
$v = new sfValidatorFileMulti();
24+
25+
$f = $v->clean(array(
26+
array('tmp_name' => $tmpDir.'/test.txt'),
27+
array('tmp_name' => $tmpDir.'/test2.txt'),
28+
));
29+
30+
$t->ok(is_array($f), '->clean() returns an array of sfValidatedFile instances');
31+
32+
$t->ok($f[0] instanceof sfValidatedFile, '->clean() returns an array of sfValidatedFile');
33+
$t->is($f[0]->getOriginalName(), '', '->clean() returns an array of sfValidatedFile with an empty original name if the name is not passed in the initial value');
34+
$t->is($f[0]->getSize(), strlen($content), '->clean() returns an array of sfValidatedFile with a computed file size if the size is not passed in the initial value');
35+
$t->is($f[0]->getType(), 'text/plain', '->clean() returns an array of sfValidatedFile with a guessed content type');
36+
37+
$t->ok($f[1] instanceof sfValidatedFile, '->clean() returns an array of sfValidatedFile');
38+
$t->is($f[1]->getOriginalName(), '', '->clean() returns an array of sfValidatedFile with an empty original name if the name is not passed in the initial value');
39+
$t->is($f[1]->getSize(), strlen($content2), '->clean() returns an array of sfValidatedFile with a computed file size if the size is not passed in the initial value');
40+
$t->is($f[1]->getType(), 'text/plain', '->clean() returns an array of sfValidatedFile with a guessed content type');
41+
42+
unlink($tmpDir.'/test.txt');
43+
unlink($tmpDir.'/test2.txt');
44+
sfToolkit::clearDirectory($tmpDir.'/foo');

0 commit comments

Comments
 (0)