Example #1
0
 public function testFilterWithForm()
 {
     $form = new Form();
     $form->setName('test_form');
     $form->input('text')->addFilter(new RegexReplace('!\\s{2,}!', ' '))->addFilter(new CallbackFilter('trim'));
     $form->handle(new FormData('post', ['test_form' => 1, 'text' => 'hello    world         ']));
     $this->assertTrue($form->isValid());
     $this->assertEquals('hello world', $form->getElements()['text']->getValue());
 }
Example #2
0
 public function testReSetData()
 {
     $form = new Form();
     $form->input('name');
     $form->input('email');
     $form->input('age');
     $form->handle(new FormData('post', [$form->getUid() => '1', 'name' => 'petro', 'email' => '*****@*****.**']));
     $this->assertEquals('*****@*****.**', $form->getElements()['email']->getValue());
     $this->assertEquals(['name' => 'petro', 'email' => '*****@*****.**', 'age' => ''], $form->getData());
     $form->handle(new FormData('post', [$form->getUid() => '1', 'name' => 'stepan']));
     $this->assertEquals(null, $form->getElement('email')->getValue());
     $this->assertEquals('stepan', $form->getElement('name')->getValue());
 }