Exemplo n.º 1
0
 public function testMultipleInstances()
 {
     $multiple = array(Former::submit('submit'), Former::reset('reset'));
     $multiple = implode(' ', $multiple);
     $matcher = '<input class="btn" type="submit" value="Submit"> <input class="btn" type="reset" value="Reset">';
     $this->assertEquals($matcher, $multiple);
 }
Exemplo n.º 2
0
 public function testHelp()
 {
     $text1 = Former::text('foo')->inlineHelp('bar')->__toString();
     $text2 = Former::text('foo')->blockHelp('bar')->__toString();
     $matcher = '<div><label for="foo">Foo</label><input type="text" name="foo" id="foo"><small>Bar</small></div>';
     $this->assertEquals($matcher, $text1);
     $this->assertEquals($matcher, $text2);
 }
Exemplo n.º 3
0
 public function testMultipleCustom()
 {
     $checkboxes = Former::checkboxes('foo')->checkboxes(array('foo' => 'Foo', 'bar' => 'Bar'))->__toString();
     $matcher = $this->cg($this->cb('foo', 'Foo') . $this->cx('bar', 'Bar'));
     $this->assertEquals($matcher, $checkboxes);
 }
Exemplo n.º 4
0
 public static function tearDownAfterClass()
 {
     \Former\Former::close();
 }
Exemplo n.º 5
0
 /**
  * Prints out the current help
  *
  * @return string A .help-block or .help-inline
  */
 private function getHelp()
 {
     $inline = array_get($this->help, 'inline');
     $block = array_get($this->help, 'block');
     $errors = Former::getErrors();
     if ($errors) {
         $inline = Framework::inlineHelp($errors);
     }
     return join(null, array($inline, $block));
 }
Exemplo n.º 6
0
 public function testDatalistCustomList()
 {
     $datalist = Former::text('foo')->list('bar')->useDatalist(array('foo' => 'bar', 'kel' => 'tar'))->__toString();
     $matcher = '<div class="control-group">' . '<label for="foo" class="control-label">Foo</label>' . '<div class="controls">' . '<input list="bar" type="text" name="foo" id="foo">' . '<datalist id="bar">' . '<option value="bar">foo</option>' . '<option value="tar">kel</option>' . '</datalist>' . '</div>' . '</div>';
     $this->assertEquals($matcher, $datalist);
 }
Exemplo n.º 7
0
 public function testSelectOptionsValueMethod()
 {
     $select = Former::select('foo')->data_foo('bar')->options($this->options)->select('kal')->__toString();
     $matcher = $this->cg('<select data-foo="bar" id="foo" name="foo">' . '<option value="foo">bar</option>' . '<option value="kal" selected="selected">ter</option>' . '</select>');
     $this->assertEquals($select, $matcher);
 }
Exemplo n.º 8
0
 public function testUneditable()
 {
     $textarea = Former::textarea('foo')->setAttributes($this->testAttributes)->value('bar')->__toString();
     $matcher = $this->cg('<textarea class="foo" data-foo="bar" name="foo" id="foo" rows="10" cols="50">bar</textarea>');
     $this->assertEquals($matcher, $textarea);
 }
Exemplo n.º 9
0
 public function testDisablingValidation()
 {
     Former::config('live_validation', false);
     Former::withRules(array('foo' => 'required'));
     $input = Former::text('foo')->__toString();
     $matcher = $this->cg($this->field(), '<label for="foo" class="control-label">Foo</label>');
     $this->assertEquals($matcher, $input);
 }
Exemplo n.º 10
0
 public function testMultipleCustom()
 {
     $radios = Former::radios('foo')->radios(array('foo' => 'Foo', 'bar' => 'Bar'))->__toString();
     $matcher = $this->cg($this->r('foo', 'Foo', 0) . $this->rx('bar', 'Bar'));
     $this->assertEquals($matcher, $radios);
 }
Exemplo n.º 11
0
 public function testLegend()
 {
     $legend = Former::legend('test', array('class' => 'foo', 'data-foo' => 'bar'));
     $matcher = '<legend class="foo" data-foo="bar">Test</legend>';
     $this->assertEquals($matcher, $legend);
 }
Exemplo n.º 12
0
 public function testActions()
 {
     $actions = Former::actions('foo', 'bar');
     $matcher = '<div class="form-actions">foo bar</div>';
     $this->assertEquals($matcher, $actions);
 }
Exemplo n.º 13
0
 public function testCustomUncheckedValue()
 {
     Former::config('push_checkboxes', true);
     Former::config('unchecked_value', 'unchecked');
     $checkbox = Former::checkbox('foo')->text('foo')->__toString();
     $matcher = $this->cg('<label for="foo" class="checkbox">' . '<input type="hidden" name="foo" value="unchecked" id="foo">' . $this->cb('foo') . 'Foo' . '</label>');
     $this->assertEquals($matcher, $checkbox);
     Former::config('push_checkboxes', false);
 }
Exemplo n.º 14
0
 public function testMaxSizeOctets()
 {
     $file = Former::file('foo')->max(2, 'Mo')->__toString();
     $matcher = $this->cg('<input type="file" name="foo" id="foo"><input type="hidden" name="MAX_FILE_SIZE" value="2097152">');
     $this->assertEquals($matcher, $file);
 }
Exemplo n.º 15
0
 public function testAllTheThings()
 {
     $control = Former::text('foo')->state('error')->inlineHelp('foo')->blockHelp('bar')->prepend('@', '$', Button::normal('foo'))->append('@', '$', Button::normal('foo'))->__toString();
     $matcher = '<div class="control-group error">' . '<label for="foo" class="control-label">Foo</label>' . '<div class="controls">' . '<div class="input-prepend input-append">' . '<span class="add-on">@</span>' . '<span class="add-on">$</span>' . '<button type="button" class="btn">foo</button>' . '<input type="text" name="foo" id="foo">' . '<span class="add-on">@</span>' . '<span class="add-on">$</span>' . '<button type="button" class="btn">foo</button>' . '</div>' . '<span class="help-inline">Foo</span>' . '<p  class="help-block">Bar</p>' . '</div>' . '</div>';
     $this->assertEquals($matcher, $control);
 }
Exemplo n.º 16
0
 public function testUneditable()
 {
     $input = Former::uneditable('foo')->value('bar')->__toString();
     $matcher = $this->cg('<span class="uneditable-input">bar</span>');
     $this->assertEquals($matcher, $input);
 }
Exemplo n.º 17
0
 public function testDoesntUseTranslationsArraysAsLabels()
 {
     $input = Former::text('pagination')->__toString();
     $matcher = $this->cg('<input type="text" name="pagination" id="pagination">', '<label for="pagination" class="control-label">Pagination</label>');
     $this->assertEquals($matcher, $input);
 }
Exemplo n.º 18
0
 public function testAddClass()
 {
     $static = Former::text('foo')->class('foo')->addClass('bar')->__toString();
     $input = Former::text('foo', null, null, array('class' => 'foo'))->addClass('bar')->__toString();
     $matcher = $this->cg('<input class="foo bar" type="text" name="foo" id="foo">');
     $this->assertEquals($matcher, $input);
     $this->assertEquals($matcher, $static);
 }
Exemplo n.º 19
0
 public function testChangeViaFormer()
 {
     Former::framework('zurb');
     $this->assertEquals(Framework::current(), 'zurb');
 }
Exemplo n.º 20
0
 public function testMultipleObjectActions()
 {
     $actions = Former::actions(Former::submit('submit'), Former::reset('reset'));
     $matcher = '<div class="form-actions">' . '<input class="btn" type="submit" value="Submit"> ' . '<input class="btn" type="reset" value="Reset">' . '</div>';
     $this->assertEquals($matcher, $actions);
 }
Exemplo n.º 21
0
 public function testRepopulateFromModel()
 {
     Former::populate((object) array('foo' => 0));
     $radios = Former::radios('foo')->radios('foo', 'bar')->__toString();
     $matcher = $this->cgm($this->rc('foo', 'Foo', 0) . $this->r('foo2', 'Bar', 1));
     $this->assertEquals($matcher, $radios);
 }
Exemplo n.º 22
0
 /**
  * Add the corresponding rules to the field's attributes
  */
 private function addRules()
 {
     // Get the different rules assigned to this field
     $rules = Former::getRules($this->name);
     if (!$rules) {
         return false;
     }
     // Iterate through them and add the attributes
     foreach ($rules as $rule => $parameters) {
         switch ($rule) {
             case 'email':
                 $this->type = 'email';
                 break;
             case 'url':
                 $this->type = 'url';
                 break;
             case 'required':
                 $this->required();
                 break;
             case 'after':
             case 'before':
                 $format = 'Y-m-d';
                 if ($this->type == 'datetime' or $this->type == 'datetime-local') {
                     $format .= '\\TH:i:s';
                 }
                 $date = strtotime(array_get($parameters, 0));
                 $attribute = $rule == 'before' ? 'max' : 'min';
                 $this->attributes[$attribute] = date($format, $date);
                 break;
             case 'max':
                 $this->setMax(array_get($parameters, 0));
                 break;
             case 'min':
                 $this->setMin(array_get($parameters, 0));
                 break;
             case 'integer':
                 $this->attributes['pattern'] = '\\d+';
                 break;
             case 'mimes':
             case 'image':
                 if ($this->type == 'file') {
                     $ext = $rule == 'image' ? array('jpg', 'png', 'gif', 'bmp') : $parameters;
                     $mimes = array_map('File::mime', $ext);
                     $this->attributes['accept'] = implode(',', $mimes);
                 }
                 break;
             case 'numeric':
                 if ($this->type == 'number') {
                     $this->attributes['step'] = 'any';
                 } else {
                     $this->attributes['pattern'] = '[+-]?\\d*\\.?\\d+';
                 }
                 break;
             case 'not_numeric':
                 $this->attributes['pattern'] = '\\D+';
                 break;
             case 'alpha':
                 $this->attributes['pattern'] = '[a-zA-Z]+';
                 break;
             case 'alpha_num':
                 $this->attributes['pattern'] = '[a-zA-Z0-9]+';
                 break;
             case 'alpha_dash':
                 $this->attributes['pattern'] = '[a-zA-Z0-9_\\-]+';
                 break;
             case 'between':
                 list($min, $max) = $parameters;
                 $this->setMin($min);
                 $this->setMax($max);
                 break;
             case 'in':
                 $possible = sizeof($parameters) == 1 ? $parameters[0] : '(' . join('|', $parameters) . ')';
                 $this->attributes['pattern'] = '^' . $possible . '$';
                 break;
             case 'not_in':
                 $this->attributes['pattern'] = '(?:(?!^' . join('$|^', $parameters) . '$).)*';
                 break;
             case 'match':
                 $this->attributes['pattern'] = substr($parameters[0], 1, -1);
                 break;
             default:
                 continue;
                 break;
         }
     }
 }
Exemplo n.º 23
0
 public function testCanGroupCheckboxes()
 {
     Former::framework(null);
     $auto = Former::checkboxes('value[]', '')->checkboxes('Value 01', 'Value 02')->__toString();
     $chain = Former::checkboxes('value', '')->grouped()->checkboxes('Value 01', 'Value 02')->__toString();
     $this->assertEquals($chain, $auto);
     $this->assertEquals('<label for="value_0" class="checkbox">' . '<input id="value_0" type="checkbox" name="value[]" value="1">Value 01' . '</label>' . '<label for="value_1" class="checkbox">' . '<input id="value_1" type="checkbox" name="value[]" value="1">Value 02' . '</label>', $auto);
 }
Exemplo n.º 24
0
 /**
  * Get a rule from the Rules array
  *
  * @param string $name The field to fetch
  * @return array An array of rules
  * @static 
  */
 public static function getRules($name)
 {
     return \Former\Former::getRules($name);
 }
Exemplo n.º 25
0
 public function testSecureInlineFilesOpen()
 {
     $open = Former::inline_secure_open_for_files('#');
     $matcher = $this->createMatcher('inline', true);
     $this->assertEquals($matcher, $open);
 }
Exemplo n.º 26
0
 public function testCanInlineASingleField()
 {
     $input = Former::text('foo')->raw()->__toString();
     $matcher = '<input type="text" name="foo">';
     $this->assertEquals($matcher, $input);
 }
Exemplo n.º 27
0
 public function tearDown()
 {
     \Former\Former::close();
 }