예제 #1
0
파일: Builder.php 프로젝트: oscarotero/folk
 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;
 }
예제 #3
0
 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);
 }
예제 #4
0
 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);
 }
예제 #5
0
 public function testEmptyWithMinValue()
 {
     $number = Builder::number()->min(1)->val('');
     $this->assertTrue($number->isValid());
     $number->required();
     $this->assertFalse($number->isValid());
 }
예제 #6
0
 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;
 }
예제 #7
0
 public function testBasic()
 {
     $this->_testElement(Builder::radio());
     $this->_testField(Builder::radio());
     $this->_testRequired(Builder::radio());
     $this->_testCheckUncheck(Builder::radio());
 }
예제 #8
0
 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;
 }
예제 #9
0
 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');
 }
예제 #11
0
 public function testBasic()
 {
     $this->_testElement(Builder::range());
     $this->_testField(Builder::range());
     $this->_testRequired(Builder::range());
     $this->_testNumber(Builder::range());
     $this->_testMinMax(Builder::range());
 }
예제 #12
0
 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);
 }
예제 #13
0
파일: Entity.php 프로젝트: oscarotero/folk
 /**
  * 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;
 }
예제 #14
0
 public function testValues()
 {
     $input = Builder::email();
     $input->val('invalid-email');
     $this->assertFalse($input->isValid());
     $input->val('*****@*****.**');
     $this->assertTrue($input->isValid());
     $this->assertEquals('*****@*****.**', $input->val());
 }
예제 #15
0
 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);
 }
예제 #16
0
 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());
 }
예제 #17
0
 /**
  * @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']);
 }
예제 #18
0
 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());
 }
예제 #19
0
 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());
 }
예제 #20
0
 /**
  * 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;
 }
예제 #21
0
 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());
 }
예제 #22
0
 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());
 }
예제 #23
0
 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());
 }
예제 #24
0
 /**
  * {@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;
 }
예제 #25
0
 /**
  * @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'));
     }
 }
예제 #26
0
 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());
 }
예제 #27
0
 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());
 }
예제 #28
0
 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());
 }
예제 #29
0
 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());
 }
예제 #30
0
 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());
 }