Beispiel #1
0
use Bundle\sfFormBundle\Widget\InputText as WidgetInputText;
use Bundle\sfFormBundle\Widget\InputHidden as WidgetInputHidden;
use Bundle\sfFormBundle\Validator\Error as ValidatorError;
use Bundle\sfFormBundle\Validator\String as ValidatorString;
use Bundle\sfFormBundle\Validator\ErrorSchema as ValidatorErrorSchema;
$t = new lime_test(11);
// widgets
$authorSchema = new WidgetSchema(array('name' => $nameWidget = new WidgetInputText()));
$authorSchema->setNameFormat('article[author][%s]');
$schema = new WidgetSchema(array('title' => $titleWidget = new WidgetInputText(), 'author' => $authorSchema));
$schema->setNameFormat('article[%s]');
// errors
$authorErrorSchema = new ValidatorErrorSchema(new ValidatorString());
$authorErrorSchema->addError(new ValidatorError(new ValidatorString(), 'name error'), 'name');
$articleErrorSchema = new ValidatorErrorSchema(new ValidatorString());
$articleErrorSchema->addError($titleError = new ValidatorError(new ValidatorString(), 'title error'), 'title');
$articleErrorSchema->addError($authorErrorSchema, 'author');
$parent = new FieldSchema($schema, null, 'article', array('title' => 'symfony', 'author' => array('name' => 'Fabien')), $articleErrorSchema);
$f = $parent['title'];
$child = $parent['author'];
// \ArrayAccess interface
$t->diag('ArrayAccess interface');
$t->is(isset($parent['title']), true, 'sfFormField implements the \\ArrayAccess interface');
$t->is(isset($parent['title1']), false, 'sfFormField implements the \\ArrayAccess interface');
$t->is($parent['title'], $f, 'sfFormField implements the \\ArrayAccess interface');
try {
    unset($parent['title']);
    $t->fail('Field implements the \\ArrayAccess interface but in read-only mode');
} catch (\LogicException $e) {
    $t->pass('Field implements the \\ArrayAccess interface but in read-only mode');
}
Beispiel #2
0
$t->diag('implements \\Countable');
$e = new ErrorSchema($v1, array('e1' => $e1, 'e2' => $e2));
$t->is(count($e), 2, '"Error" implements \\Countable');
// implements \Iterator
$t->diag('implements \\Iterator');
$e = new ErrorSchema($v1, array('e1' => $e1, $e2));
$e->addError($e2, '2');
$errors = array();
foreach ($e as $name => $error) {
    $errors[$name] = $error;
}
$t->is($errors, array('e1' => $e1, 0 => $e2, '2' => $e2), 'ErrorSchema implements the \\Iterator interface');
// implements \ArrayAccess
$t->diag('implements \\ArrayAccess');
$e = new ErrorSchema($v1, array('e1' => $e1, $e2));
$e->addError($e2, '2');
$t->is($e['e1'], $e1, 'ErrorSchema implements the \\ArrayAccess interface');
$t->is($e[0], $e2, 'ErrorSchema implements the \\ArrayAccess interface');
$t->is($e['2'], $e2, 'ErrorSchema implements the \\ArrayAccess interface');
$t->is(isset($e['e1']), true, 'ErrorSchema implements the \\ArrayAccess interface');
$t->is(isset($e['e2']), false, 'ErrorSchema implements the \\ArrayAccess interface');
try {
    $e['e1'] = $e2;
    $t->fail('ErrorSchema implements the \\ArrayAccess interface');
} catch (\LogicException $e) {
    $t->pass('ErrorSchema implements the \\ArrayAccess interface');
}
// implements \Serializable
$t->diag('implements \\Serializable');
class NotSerializable implements \Serializable
{