Exemplo n.º 1
0
 public function testRenderWithSingleData()
 {
     $form = new \TestForm1();
     $obj = new TestModel2($this->adapter);
     $obj->field1 = 'value1';
     $obj->field2 = 'value2';
     $form->setData('t2', $obj);
     $ret = $form->render();
     echo json_encode($ret);
 }
Exemplo n.º 2
0
$t->is($widgetSchema->getLabels(), array('a' => '1_a', 'b' => '1_b', 'c' => '2_c', 'd' => '2_d'), 'mergeForm() merges labels correctly');
$t->is($widgetSchema->getHelps(), array('a' => '1_a', 'b' => '1_b', 'c' => '2_c', 'd' => '2_d'), 'mergeForm() merges helps correctly');
$t->isa_ok($widgetSchema['c'], 'sfWidgetFormTextarea', 'mergeForm() overrides original form widget');
$t->isa_ok($validatorSchema['c'], 'sfValidatorPass', 'mergeForm() overrides original form validator');
$t->isa_ok($validatorSchema->getPreValidator(), 'sfValidatorPass', 'mergeForm() merges pre validator');
$t->isa_ok($validatorSchema->getPostValidator(), 'sfValidatorPass', 'mergeForm() merges post validator');
try {
    $f1->bind(array('a' => 'foo', 'b' => 'bar', 'd' => 'far_too_long_value'));
    $f1->mergeForm($f2);
    $t->fail('mergeForm() disallows merging already bound forms');
} catch (LogicException $e) {
    $t->pass('mergeForm() disallows merging already bound forms');
}
$errorSchema = $f1->getErrorSchema();
$t->ok(array_key_exists('d', $errorSchema->getErrors()), 'mergeForm() merges errors after having been bound');
$f1 = new TestForm1();
$f1->getWidgetSchema()->moveField('a', 'last');
// is moved field well positioned when accessed with iterator interface? (#5551)
foreach ($f1 as $f1name => $f1field) {
    $t->is($f1name, 'b', 'iterating on form takes in account ->moveField() operations.');
    break;
}
$f2 = new TestForm2();
$f2->mergeForm($f1);
$t->is_deeply(array_keys($f2->getWidgetSchema()->getFields()), array('c', 'd', 'b', 'a'), 'mergeForm() merges fields in the correct order');
$f1 = new NumericFieldsForm(array('5' => 'default1'), array('salt' => '1'));
$f2 = new NumericFieldsForm(array('5' => 'default2'), array('salt' => '2'));
$f1->mergeForm($f2);
$t->is_deeply($f1->getDefaults(), array('5' => 'default2'), '->mergeForm() merges numeric defaults');
$t->is_deeply($f1->getWidgetSchema()->getLabels(), array('5' => 'label2'), '->mergeForm() merges numeric labels');
$t->is_deeply($f1->getWidgetSchema()->getHelps(), array('5' => 'help2'), '->mergeForm() merges numeric helps');
Exemplo n.º 3
0
        return array('/path/to/a/' . $this->getOption('name') . '.css' => 'all');
    }
}
$f = new FormTest();
$f->setWidgets(array('foo' => new MyWidget(array('name' => 'foo')), 'bar' => new MyWidget(array('name' => 'bar'))));
$t->is($f->getJavaScripts(), array('/path/to/a/foo.js', '/path/to/a/bar.js'), '->getJavaScripts() returns the stylesheets of all widgets');
$t->is($f->getStylesheets(), array('/path/to/a/foo.css' => 'all', '/path/to/a/bar.css' => 'all'), '->getStylesheets() returns the JavaScripts of all widgets');
// ->getFormFieldSchema()
$t->diag('->getFormFieldSchema()');
$f = new NumericFieldsForm(array('5' => 'default'));
$t->is_deeply($f->getFormFieldSchema()->getValue(), array('5' => 'default'), '->getFormFieldSchema() includes default numeric fields');
$f->bind(array('5' => 'bound'));
$t->is_deeply($f->getFormFieldSchema()->getValue(), array('5' => 'bound'), '->getFormFieldSchema() includes bound numeric fields');
// ->getErrors()
$t->diag('->getErrors()');
$f1 = new TestForm1();
$f21 = new TestForm1();
$f2 = new TestForm2();
$f2->embedForm('F21', $f21);
$f1->embedForm('F2', $f2);
$f1->bind(array());
$expected = array('1_a' => 'Required.', '1_b' => 'Required.', '1_c' => 'Required.', 'F2' => array('2_d' => 'Required.', 'F21' => array('1_a' => 'Required.', '1_b' => 'Required.', '1_c' => 'Required.')));
$t->is($f1->getErrors(), $expected, '->getErrors() return array of errors');
// bind with a simulated file upload in the POST array
$f = new FormTest();
try {
    $f->bind(array('file' => array('name' => 'foo.txt', 'type' => 'text/plain', 'tmp_name' => 'somefile', 'error' => 0, 'size' => 10)));
    $t->fail('Cannot fake a file upload with a POST');
} catch (InvalidArgumentException $e) {
    $t->pass('Cannot fake a file upload with a POST');
}
Exemplo n.º 4
0
        $this->getWidgetSchema()->setLabels(array('a' => '1_a', 'b' => '1_b', 'c' => '1_c'));
    }
}
class TestForm2 extends FormTest
{
    public function configure()
    {
        $this->disableCSRFProtection();
        $this->setWidgets(array('c' => new sfWidgetFormTextarea(), 'd' => new sfWidgetFormTextarea()));
        $this->setValidators(array('c' => new sfValidatorPass(), 'd' => new sfValidatorString(array('max_length' => 5))));
        $this->getWidgetSchema()->setLabels(array('c' => '2_c', 'd' => '2_d'));
        $this->validatorSchema->setPreValidator(new sfValidatorPass());
        $this->validatorSchema->setPostValidator(new sfValidatorPass());
    }
}
$f1 = new TestForm1();
$f2 = new TestForm2();
$f1->mergeForm($f2);
$widgetSchema = $f1->getWidgetSchema();
$validatorSchema = $f1->getValidatorSchema();
$t->is(count($widgetSchema->getFields()), 4, 'mergeForm() merges a widget form schema');
$t->is(count($validatorSchema->getFields()), 4, 'mergeForm() merges a validator schema');
$t->is(array_keys($widgetSchema->getFields()), array('a', 'b', 'c', 'd'), 'mergeForms() merges the correct widgets');
$t->is(array_keys($validatorSchema->getFields()), array('a', 'b', 'c', 'd'), 'mergeForms() merges the correct validators');
$t->is($widgetSchema->getLabels(), array('a' => '1_a', 'b' => '1_b', 'c' => '2_c', 'd' => '2_d'), 'mergeForm() merges labels correctly');
$t->isa_ok($widgetSchema['c'], 'sfWidgetFormTextarea', 'mergeForm() overrides original form widget');
$t->isa_ok($validatorSchema['c'], 'sfValidatorPass', 'mergeForm() overrides original form validator');
$t->isa_ok($validatorSchema->getPreValidator(), 'sfValidatorPass', 'mergeForm() merges pre validator');
$t->isa_ok($validatorSchema->getPostValidator(), 'sfValidatorPass', 'mergeForm() merges post validator');
try {
    $f1->bind(array('a' => 'foo', 'b' => 'bar', 'd' => 'far_too_long_value'));
Exemplo n.º 5
0
 public function testIsValidWithCleanHook()
 {
     require_once __DIR__ . '/../files/forms/test_form_1.php';
     $form = new \TestForm1();
     $this->assertFalse($form->isValid(array('lib' => 'bar')));
     $this->assertEquals('Lib should be "foo"', $form->errors['_all_']);
     $form = new \TestForm1();
     $this->assertTrue($form->isValid(array('lib' => 'foo')));
 }