示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#4
0
 public static function tearDownAfterClass()
 {
     \Former\Former::close();
 }
示例#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));
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#12
0
 public function testActions()
 {
     $actions = Former::actions('foo', 'bar');
     $matcher = '<div class="form-actions">foo bar</div>';
     $this->assertEquals($matcher, $actions);
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#19
0
 public function testChangeViaFormer()
 {
     Former::framework('zurb');
     $this->assertEquals(Framework::current(), 'zurb');
 }
示例#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);
 }
示例#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);
 }
示例#22
0
文件: Field.php 项目: raftalks/former
 /**
  * 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;
         }
     }
 }
示例#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);
 }
示例#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);
 }
示例#25
0
 public function testSecureInlineFilesOpen()
 {
     $open = Former::inline_secure_open_for_files('#');
     $matcher = $this->createMatcher('inline', true);
     $this->assertEquals($matcher, $open);
 }
示例#26
0
 public function testCanInlineASingleField()
 {
     $input = Former::text('foo')->raw()->__toString();
     $matcher = '<input type="text" name="foo">';
     $this->assertEquals($matcher, $input);
 }
示例#27
0
文件: start.php 项目: iyoworks/former
 public function tearDown()
 {
     \Former\Former::close();
 }