public function register(Fol $app) { $app['builder'] = function ($app) { $builder = new FormBuilder(); $builder->add(new FormatFactory($builder)); return $builder; }; }
public function testBase() { $field = Builder::collectionMultiple(['section' => ['title' => Builder::text()->label('Title'), 'text' => Builder::textarea()->label('Text')], 'picture' => ['caption' => Builder::text()->label('Caption'), 'image' => Builder::file()->label('Image')], 'quote' => ['cite' => Builder::textarea()->label('Cite'), 'author' => Builder::text()->label('Author')]]); $this->assertInstanceOf('FormManager\\Containers\\CollectionMultiple', $field); $this->assertInstanceOf('FormManager\\Containers\\Group', $field->template['section']); return $field; }
public function testOne() { $input = Builder::text()->datalist(['Hello' => 'World'])->id('my-id'); $input->datalist->id('my-datalist-id'); $this->assertEquals('my-id', $input->attr('id')); $this->assertEquals(' <input type="text" id="my-id" list="my-datalist-id"><datalist id="my-datalist-id"><option value="Hello">World</option></datalist> ', (string) $input); }
public function testTwo() { $input = Builder::text()->id('my-id')->label('Hello'); $input->label->id('my-label-id'); $this->assertEquals('my-id', $input->attr('id')); $this->assertEquals('<label id="my-label-id" for="my-id">Hello</label> <input type="text" id="my-id" aria-labelledby="my-label-id"> ', (string) $input); }
public function testEmptyWithMinValue() { $number = Builder::number()->min(1)->val(''); $this->assertTrue($number->isValid()); $number->required(); $this->assertFalse($number->isValid()); }
public function testBase() { $field = Builder::group(['name' => Builder::text()->label('Name'), 'email' => Builder::email()->label('email'), 'age' => Builder::number()->label('Age'), 'image' => Builder::file()->label('Image')]); $this->assertInstanceOf('FormManager\\Containers\\Group', $field); $this->assertInstanceOf('FormManager\\Fields\\Text', $field['name']); return $field; }
public function testBasic() { $this->_testElement(Builder::radio()); $this->_testField(Builder::radio()); $this->_testRequired(Builder::radio()); $this->_testCheckUncheck(Builder::radio()); }
public function testBase() { $field = Builder::choose(['value1' => Builder::radio()->label('Value 1'), 'value2' => Builder::radio()->label('Value 2'), 'value3' => Builder::radio()->label('Value 3'), 'value4' => Builder::radio()->label('Value 4')]); $this->assertInstanceOf('FormManager\\Containers\\Choose', $field); $this->assertInstanceOf('FormManager\\Fields\\Radio', $field['value1']); return $field; }
public function testLocales() { $input = Builder::text()->required(); $message = 'custom error message'; FormManager\Validators\Required::$error_message = $message; $this->assertFalse($input->isValid()); $this->assertEquals($message, $input->error()); }
/** * Generate a bootstrap standard form * * @param null|array $fields * * @return Form */ public static function form(array $fields = null) { $form = Builder::Form(); if ($fields) { $form->add($fields); } return $form->rule('form'); }
public function testBasic() { $this->_testElement(Builder::range()); $this->_testField(Builder::range()); $this->_testRequired(Builder::range()); $this->_testNumber(Builder::range()); $this->_testMinMax(Builder::range()); }
public function testOptgroups() { $select = Builder::select()->optgroups(['Numbers' => [0 => 'Zero', 1 => 'One', 2 => 'Two'], 'Letters' => ['a' => 'A', 'b' => 'B', 'c' => 'C']]); $this->assertCount(6, $select); $select->options([3 => 'Three']); $this->assertCount(7, $select); $select->clear()->options([4 => 'Four']); $this->assertCount(1, $select); }
/** * Helper to build the entity form. * * @param Admin $app * @param string $entityName * @param mixed|null $id * * return \Folk\Formats\Form */ protected static function createForm(Admin $app, $entityName, $id = null) { $entity = $app->getEntity($entityName); $form = F::form()->method('post')->enctype('multipart/form-data')->add(['entity' => F::hidden()->val($entityName)->class('field-data-entity'), 'data' => $entity->getScheme($app['builder'])]); if ($id !== null) { $form['id'] = F::hidden()->val($id)->class('field-data-id'); } return $form; }
public function testValues() { $input = Builder::email(); $input->val('invalid-email'); $this->assertFalse($input->isValid()); $input->val('*****@*****.**'); $this->assertTrue($input->isValid()); $this->assertEquals('*****@*****.**', $input->val()); }
public function testFieldsets() { $form = Builder::form(['submit' => Builder::submit()])->fieldsets(['personal' => ['name' => Builder::text(), 'surname' => Builder::text(), 'age' => Builder::number()]]); $this->assertCount(4, $form); $this->assertCount(1, $form->fieldsets()); $this->assertCount(3, $form->fieldsets()['personal']); $form->clear()->add(['other' => Builder::text()]); $this->assertCount(1, $form); }
public function testBasic() { $this->_testElement(Builder::text()); $this->_testField(Builder::text()); $this->_testRequired(Builder::text()); $this->_testMaxlength(Builder::text()); $this->_testPattern(Builder::text()); $this->_testValidator(Builder::text()); }
/** * @depends testValue */ public function testTemplate(Collection $field) { $form = Builder::form(); $form['key'] = $field; $template = $field->getTemplate(); $template['name']->id('my-id'); $template['name']->label->id('my-label-id'); $this->assertEquals('<label id="my-label-id" for="my-id">Name</label> <input type="text" id="my-id" name="key[::n::][name]" aria-labelledby="my-label-id"> ', (string) $template['name']); }
public function testValues() { $input = Builder::url(); $input->val('invalid-url'); $this->assertFalse($input->isValid()); $input->val('http://valid-url.com'); $this->assertTrue($input->isValid()); $this->assertEquals('http://valid-url.com', $input->val()); }
public function testMimeTypePsr() { $file = dirname(__DIR__) . '/image.jpg'; $val = new UploadedFile($file, filesize($file), 0, 'image.jpg', 'image/jpeg'); $input = Builder::file()->accept('image/png')->val($val); $this->assertFalse($input->isValid()); $input->accept('image/jpeg'); $this->assertTrue($input->isValid(), $input->error()); }
/** * Returns the template used to create all values. * * @param mixed $template The new template * * @return self */ public function setTemplate($template) { if (is_array($template)) { $template = F::group($template); } elseif (!$template instanceof Group) { throw new \InvalidArgumentException('Invalid type of the template. Only arrays and FormManager\\Containers\\Group are allowed'); } $this->template = $template; return $this; }
public function testValues() { $input = Builder::search(); $input->val('hello'); $this->assertSame('hello', $input->val()); $input->val('0'); $this->assertSame('0', $input->val()); $input->load('0'); $this->assertSame('0', $input->val()); }
public function testMinMaxDatetime() { $input = Builder::datetime(); $input->min('2004-08-14T15:52:01+00:00'); $input->max('2005-08-14T15:52:01+00:00'); $input->val('Mon, 15 Aug 2005 15:52:01 +0000'); $this->assertFalse($input->isValid()); $input->val('Mon, 15 Aug 2004 15:52:01 +0000'); $this->assertTrue($input->isValid()); }
public function testsValues() { $input = Builder::color(); $input->val('red'); $this->assertFalse($input->isValid()); $input->val('11234f'); $this->assertFalse($input->isValid()); $input->val('#11234f'); $this->assertTrue($input->isValid()); $this->assertEquals('#11234f', $input->val()); }
/** * {@inheritdoc} */ public function add(array $children) { foreach ($children as $type => $child) { $child = F::group($child); if (!isset($child[$this->keyField])) { $child[$this->keyField] = F::hidden()->val($type); } $this->template[$type] = $child; } return $this; }
/** * @dataProvider booleanProvider */ public function testBoolean($value, $checked) { $input = Builder::checkbox(); $input->val($value); if ($checked) { $this->assertTrue($input->attr('checked')); } else { $this->assertNotTrue($input->attr('checked')); } $input->load($value); if ($checked) { $this->assertTrue($input->attr('checked')); } else { $this->assertNotTrue($input->attr('checked')); } }
public function testsValues() { $input = Builder::month(); $input->val('2014-33'); $this->assertFalse($input->isValid()); $input->val('2014-09'); $this->assertTrue($input->isValid()); $this->assertEquals('2014-09', $input->val()); $input->max('2014-08'); $this->assertFalse($input->isValid()); $input->max('2014-09'); $this->assertTrue($input->isValid()); $input->max('2014-10'); $this->assertTrue($input->isValid()); $input->min('2014-10'); $this->assertFalse($input->isValid()); }
public function testsValues() { $input = Builder::date(); $input->val('2005-33-14'); $this->assertFalse($input->isValid()); $input->val('Mon, 15 Aug 2005'); $this->assertTrue($input->isValid()); $this->assertEquals('Mon, 15 Aug 2005', $input->val()); $input->max('2005-08-14'); $this->assertFalse($input->isValid()); $input->max('2005-08-15'); $this->assertTrue($input->isValid()); $input->max('2005-08-16'); $this->assertTrue($input->isValid()); $input->min('2005-08-16'); $this->assertFalse($input->isValid()); }
public function testsValues() { $input = Builder::week(); $input->val('2014-W55'); $this->assertFalse($input->isValid()); $input->val('2014-W16'); $this->assertTrue($input->isValid()); $this->assertEquals('2014-W16', $input->val()); $input->max('2014-W15'); $this->assertFalse($input->isValid()); $input->max('2014-W16'); $this->assertTrue($input->isValid()); $input->max('2014-W17'); $this->assertTrue($input->isValid()); $input->min('2014-W17'); $this->assertFalse($input->isValid()); }
public function testsValues() { $input = Builder::time(); $input->val('38:34:32'); $this->assertFalse($input->isValid()); $input->val('18:34:32'); $this->assertTrue($input->isValid()); $this->assertEquals('18:34:32', $input->val()); $input->max('18:34:31'); $this->assertFalse($input->isValid()); $input->max('18:34:32'); $this->assertTrue($input->isValid()); $input->max('18:34:33'); $this->assertTrue($input->isValid()); $input->min('18:34:33'); $this->assertFalse($input->isValid()); }
public function testValidation() { $form = Builder::form(['name' => Builder::text()->maxlength(200)->label('Name'), 'email' => Builder::email()->label('Email'), 'password' => Builder::password()->label('Password'), 'repeat_password' => Builder::password()->label('Repeat password')])->addValidator(function ($form) { $password1 = $form['password']->val(); $password2 = $form['repeat_password']->val(); if ($password1 != $password2) { throw new InvalidValueException('The passwords does not match'); } }); $form->val(['name' => 'Oscar', 'email' => '*****@*****.**', 'password' => '1234', 'repeat_password' => '12345']); $this->assertFalse($form->isValid()); $this->assertEquals('The passwords does not match', $form->error()); $this->assertCount(1, $form->getElementsWithErrors()); $form['repeat_password']->val('1234'); $this->assertTrue($form->isValid()); $this->assertNull($form->error()); $this->assertCount(0, $form->getElementsWithErrors()); }