示例#1
0
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../bootstrap.php';
use Bundle\sfFormBundle\Widget\SchemaFormatter;
use Bundle\sfFormBundle\Widget\Schema;
use Bundle\sfFormBundle\Widget\FilterInput;
use Bundle\sfFormBundle\Tool\DomCssSelector;
class FormFormatterStub extends SchemaFormatter
{
    public function __construct()
    {
    }
    public function translate($subject, $parameters = array())
    {
        return sprintf('translation[%s]', $subject);
    }
}
$t = new lime_test(1);
$dom = new \DomDocument('1.0', 'utf-8');
$dom->validateOnParse = true;
// ->render()
$t->diag('->render()');
$ws = new Schema();
$ws->addFormFormatter('stub', new FormFormatterStub());
$ws->setFormFormatterName('stub');
$w = new FilterInput();
$w->setParent($ws);
$dom->loadHTML($w->render('foo'));
$css = new DomCssSelector($dom);
$t->is($css->matchSingle('label[for="foo_is_empty"]')->getValue(), 'translation[is empty]', '->render() translates the empty_label option');
示例#2
0
}
try {
    $parent['title'] = null;
    $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');
}
try {
    $parent['title1'];
    $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');
}
// implements \Countable
$t->diag('implements \\Countable');
$widgetSchema = new WidgetSchema(array('w1' => $w1 = new WidgetInputText(), 'w2' => $w2 = new WidgetInputText()));
$f = new FieldSchema($widgetSchema, null, 'article', array());
$t->is(count($f), 2, 'FormSchema implements the \\Countable interface');
// implements \Iterator
$t->diag('implements \\Iterator');
$f = new FieldSchema($widgetSchema, null, 'article', array());
$values = array();
foreach ($f as $name => $value) {
    $values[$name] = $value;
}
$t->is(isset($values['w1']), true, 'FormSchema implements the \\Iterator interface');
$t->is(isset($values['w2']), true, 'FormSchema implements the \\Iterator interface');
$t->is(count($values), 2, 'FormSchema implements the \\Iterator interface');
$t->diag('implements \\Iterator respecting the order of fields');
$widgetSchema->moveField('w2', 'first');
$f = new FieldSchema($widgetSchema, null, 'article', array());
示例#3
0
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/bootstrap.php';
use Bundle\sfFormBundle\Field;
use Bundle\sfFormBundle\FieldSchema;
use Bundle\sfFormBundle\Widget\Form as WidgetForm;
use Bundle\sfFormBundle\Widget\Schema as WidgetFormSchema;
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(31);
// widgets
$authorSchema = new WidgetFormSchema(array('id' => new WidgetInputHidden(), 'name' => $nameWidget = new WidgetInputText()));
$authorSchema->setNameFormat('article[author][%s]');
$schema = new WidgetFormSchema(array('title' => $titleWidget = new WidgetInputText(), 'author' => $authorSchema));
$schema->setNameFormat('article[%s]');
$titleWidget->setParent($schema);
// 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'];
// ->getValue() ->getWidget() ->getParent() ->getError() ->hasError()
$t->diag('->getValue() ->getName() ->getWidget() ->getParent() ->getError() ->hasError()');