コード例 #1
0
ファイル: sfFormTest.php プロジェクト: WIZARDISHUNGRY/symfony
$t->diag('->renderHiddenFields()');
$f = new sfForm();
$f->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInput(), 'is_admin' => new sfWidgetFormInputHidden()));
$output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="is_admin" id="is_admin" />';
$t->is($f->renderHiddenFields(), $output, 'renderHiddenFields() renders all hidden fields, no visible fields');
$t->is(count($f->getFormFieldSchema()), 3, 'renderHiddenFields() does not modify the form fields');
// ->embedForm()
$t->diag('->embedForm()');
$author = new FormTest(array('first_name' => 'Fabien'));
$author->setWidgetSchema($author_widget_schema = new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInput())));
$author->setValidatorSchema($author_validator_schema = new sfValidatorSchema(array('first_name' => new sfValidatorString(array('min_length' => 2)))));
$company = new FormTest();
$company->setWidgetSchema($company_widget_schema = new sfWidgetFormSchema(array('name' => new sfWidgetFormInput())));
$company->setValidatorSchema($company_validator_schema = new sfValidatorSchema(array('name' => new sfValidatorString(array('min_length' => 2)))));
$article = new FormTest();
$article->setWidgetSchema($article_widget_schema = new sfWidgetFormSchema(array('title' => new sfWidgetFormInput())));
$article->setValidatorSchema($article_validator_schema = new sfValidatorSchema(array('title' => new sfValidatorString(array('min_length' => 2)))));
$author->embedForm('company', $company);
$article->embedForm('author', $author);
$v = $article->getValidatorSchema();
$w = $article->getWidgetSchema();
$d = $article->getDefaults();
$w->setNameFormat('article[%s]');
$t->ok($v['author']['first_name'] == $author_validator_schema['first_name'], '->embedForm() embeds the validator schema');
$t->ok($w['author']['first_name'] == $author_widget_schema['first_name'], '->embedForm() embeds the widget schema');
$t->is($d['author']['first_name'], 'Fabien', '->embedForm() merges default values from the embedded form');
$t->is($v['author'][sfForm::getCSRFFieldName()], null, '->embedForm() removes the CSRF token for the embedded form');
$t->is($w['author'][sfForm::getCSRFFieldName()], null, '->embedForm() removes the CSRF token for the embedded form');
$t->is($w['author']->generateName('first_name'), 'article[author][first_name]', '->embedForm() changes the name format to reflect the embedding');
$t->is($w['author']['company']->generateName('name'), 'article[author][company][name]', '->embedForm() changes the name format to reflect the embedding');
// ->embedFormForEach()
コード例 #2
0
ファイル: sfFormTest.php プロジェクト: Tony-M/GrannySymfony
$input = array('file' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'file1' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 200));
$t->is_deeply(sfForm::convertFileInformation($input), $input, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
$input = array('article' => array('name' => array('file1' => 'test1.txt', 'file2' => 'test2.txt'), 'type' => array('file1' => 'text/plain', 'file2' => 'text/plain'), 'tmp_name' => array('file1' => '/tmp/test1.txt', 'file2' => '/tmp/test2.txt'), 'error' => array('file1' => 0, 'file2' => 0), 'size' => array('file1' => 100, 'file2' => 200)));
$expected = array('article' => array('file1' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'file2' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test2.txt', 'error' => 0, 'size' => 200)));
$t->is_deeply(sfForm::convertFileInformation($input), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
$t->is_deeply(sfForm::convertFileInformation($expected), $expected, '::convertFileInformation() only changes the input array if needed');
$input = array('file' => array('name' => 'test.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test.txt', 'error' => 0, 'size' => 100), 'article' => array('name' => array('name' => array('name' => 'test1.txt', 'another' => array('file2' => 'test2.txt'))), 'type' => array('name' => array('name' => 'text/plain', 'another' => array('file2' => 'text/plain'))), 'tmp_name' => array('name' => array('name' => '/tmp/test1.txt', 'another' => array('file2' => '/tmp/test2.txt'))), 'error' => array('name' => array('name' => 0, 'another' => array('file2' => 0))), 'size' => array('name' => array('name' => 100, 'another' => array('file2' => 200)))));
$expected = array('file' => array('name' => 'test.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test.txt', 'error' => 0, 'size' => 100), 'article' => array('name' => array('name' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'another' => array('file2' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test2.txt', 'error' => 0, 'size' => 200)))));
$t->is_deeply(sfForm::convertFileInformation($input), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
$t->is_deeply(sfForm::convertFileInformation($expected), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
// ->renderFormTag()
$t->diag('->renderFormTag()');
$f = new FormTest();
$t->is($f->renderFormTag('/url'), '<form action="/url" method="post">', '->renderFormTag() renders the form tag');
$t->is($f->renderFormTag('/url', array('method' => 'put')), '<form method="post" action="/url"><input type="hidden" name="sf_method" value="put" />', '->renderFormTag() adds a hidden input tag if the method is not GET or POST');
$f->setWidgetSchema(new sfWidgetFormSchema(array('image' => new sfWidgetFormInputFile())));
$t->is($f->renderFormTag('/url'), '<form action="/url" method="post" enctype="multipart/form-data">', '->renderFormTag() adds the enctype attribute if the form is multipart');
// __clone()
$t->diag('__clone()');
$a = new FormTest();
$a->setValidatorSchema(new sfValidatorSchema(array('first_name' => new sfValidatorString(array('min_length' => 2)))));
$a->bind(array('first_name' => 'F'));
$a1 = clone $a;
$t->ok($a1->getValidatorSchema() !== $a->getValidatorSchema(), '__clone() clones the validator schema');
$t->ok($a1->getValidatorSchema() == $a->getValidatorSchema(), '__clone() clones the validator schema');
$t->ok($a1->getWidgetSchema() !== $a->getWidgetSchema(), '__clone() clones the widget schema');
$t->ok($a1->getWidgetSchema() == $a->getWidgetSchema(), '__clone() clones the widget schema');
$t->ok($a1->getErrorSchema() !== $a->getErrorSchema(), '__clone() clones the error schema');
$t->ok($a1->getErrorSchema()->getMessage() == $a->getErrorSchema()->getMessage(), '__clone() clones the error schema');
// mergeForm()
$t->diag('mergeForm()');
コード例 #3
0
ファイル: FormTest.php プロジェクト: rande/sfFormBundle
$input = array('file' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'file1' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 200));
$t->is_deeply(Form::convertFileInformation($input), $input, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
$input = array('article' => array('name' => array('file1' => 'test1.txt', 'file2' => 'test2.txt'), 'type' => array('file1' => 'text/plain', 'file2' => 'text/plain'), 'tmp_name' => array('file1' => '/tmp/test1.txt', 'file2' => '/tmp/test2.txt'), 'error' => array('file1' => 0, 'file2' => 0), 'size' => array('file1' => 100, 'file2' => 200)));
$expected = array('article' => array('file1' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'file2' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test2.txt', 'error' => 0, 'size' => 200)));
$t->is_deeply(Form::convertFileInformation($input), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
$t->is_deeply(Form::convertFileInformation($expected), $expected, '::convertFileInformation() only changes the input array if needed');
$input = array('file' => array('name' => 'test.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test.txt', 'error' => 0, 'size' => 100), 'article' => array('name' => array('name' => array('name' => 'test1.txt', 'another' => array('file2' => 'test2.txt'))), 'type' => array('name' => array('name' => 'text/plain', 'another' => array('file2' => 'text/plain'))), 'tmp_name' => array('name' => array('name' => '/tmp/test1.txt', 'another' => array('file2' => '/tmp/test2.txt'))), 'error' => array('name' => array('name' => 0, 'another' => array('file2' => 0))), 'size' => array('name' => array('name' => 100, 'another' => array('file2' => 200)))));
$expected = array('file' => array('name' => 'test.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test.txt', 'error' => 0, 'size' => 100), 'article' => array('name' => array('name' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'another' => array('file2' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test2.txt', 'error' => 0, 'size' => 200)))));
$t->is_deeply(Form::convertFileInformation($input), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
$t->is_deeply(Form::convertFileInformation($expected), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
// ->renderFormTag()
$t->diag('->renderFormTag()');
$f = new FormTest();
$t->is($f->renderFormTag('/url'), '<form action="/url" method="post">', '->renderFormTag() renders the form tag');
$t->is($f->renderFormTag('/url', array('method' => 'put')), '<form method="post" action="/url"><input type="hidden" name="sf_method" value="put" />', '->renderFormTag() adds a hidden input tag if the method is not GET or POST');
$f->setWidgetSchema(new WidgetSchema(array('image' => new WidgetInputFile())));
$t->is($f->renderFormTag('/url'), '<form action="/url" method="post" enctype="multipart/form-data">', '->renderFormTag() adds the enctype attribute if the form is multipart');
// __clone()
$t->diag('__clone()');
$a = new FormTest();
$a->setValidatorSchema(new ValidatorSchema(array('first_name' => new ValidatorString(array('min_length' => 2)))));
$a->bind(array('first_name' => 'F'));
$a1 = clone $a;
$t->ok($a1->getValidatorSchema() !== $a->getValidatorSchema(), '__clone() clones the validator schema');
$t->ok($a1->getValidatorSchema() == $a->getValidatorSchema(), '__clone() clones the validator schema');
$t->ok($a1->getWidgetSchema() !== $a->getWidgetSchema(), '__clone() clones the widget schema');
$t->ok($a1->getWidgetSchema() == $a->getWidgetSchema(), '__clone() clones the widget schema');
$t->ok($a1->getErrorSchema() !== $a->getErrorSchema(), '__clone() clones the error schema');
$t->ok($a1->getErrorSchema()->getMessage() == $a->getErrorSchema()->getMessage(), '__clone() clones the error schema');
// mergeForm()
$t->diag('mergeForm()');