public function testIsValidWithVariousConstraints() { $form = new Form(); $form->to = new EmailField(array('required' => true)); $form->cc = new EmailField(); $form->subject = new CharField(array('min_length' => 5)); $form->body = new TextField(); $form2 = clone $form; $this->assertFalse($form->isValid(array('cc' => '<xss></xss>john@', 'subject' => 'doh', 'body' => 'hello'))); $this->assertEquals(array('to' => null, 'cc' => 'xssxssjohn@', 'subject' => 'doh', 'body' => 'hello'), $form->getCleanedData()); $this->assertEquals('This field is required.', $form->errors['to']); $this->assertEquals('Enter a valid e-mail address.', $form->errors['cc']); $this->assertEquals('Ensure this value has at least 5 characters (it has 3).', $form->errors['subject']); $this->assertTrue($form2->isValid(array('to' => '*****@*****.**', 'cc' => '*****@*****.**', 'subject' => 'donuts', 'body' => 'hello'))); $this->assertEquals(array('to' => '*****@*****.**', 'cc' => '*****@*****.**', 'subject' => 'donuts', 'body' => 'hello'), $form2->getCleanedData()); }
public function __construct(array $data = null, array $files = null) { parent::__construct($data, $files); $this->lib = new \Stato\Webflow\Forms\CharField(); }