示例#1
0
 /**
  * @covers Xoops\Form\Text::render
  */
 public function testRender()
 {
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<input'));
     $this->assertTrue(false !== strpos($value, 'type="text"'));
     $this->assertTrue(false !== strpos($value, 'name="name"'));
     $this->assertTrue(false !== strpos($value, 'size="10"'));
     $this->assertTrue(false !== strpos($value, 'maxlength="20"'));
     $this->assertTrue(false !== strpos($value, 'placeholder="placeholder"'));
     $this->assertTrue(false !== strpos($value, 'title="Caption"'));
     $this->assertTrue(false !== strpos($value, 'id="name"'));
     $this->assertTrue(false !== strpos($value, 'value="value"'));
 }
示例#2
0
 public function render()
 {
     $this->setValue(null);
     // ensure the value is not displayed
     $this->set('type', 'password');
     return parent::render();
 }
示例#3
0
 public function testPlacementAppend()
 {
     $decorator = new Text('foo');
     $decorator->setOption('placement', 'append');
     $expected = 'barfoo';
     $actual = $decorator->render('bar');
     $this->assertSame($expected, $actual);
 }
示例#4
0
 public function render(array $attributes = [], array $viewData = [])
 {
     $this->options = array_merge($this->getOptions(), $attributes);
     $value = request($this->name, $this->getOption('value'));
     if ($this->isChecked($value)) {
         $this->options['checked'] = 'checked';
     }
     return parent::render($attributes, $viewData);
 }
示例#5
0
 public function render(array $attributes = [], array $viewData = [])
 {
     $this->options = array_merge($this->options, $attributes);
     // Since the hidden type does not have a label,
     // we can use its value to pass the value of the hidden
     if (strlen($this->getOption('value')) === 0) {
         $this->options['value'] = $this->getLabel();
         $this->value = $this->getLabel();
     }
     return parent::render($attributes, $viewData);
 }
示例#6
0
 /**
  * render
  *
  * @return string
  */
 public function render()
 {
     $xoops = \Xoops::getInstance();
     if ($xoops->theme()) {
         $xoops->theme()->addScript('include/color-picker.js');
     } else {
         echo '<script type="text/javascript" src="' . \XoopsBaseConfig::get('url') . '/include/color-picker.js"></script>';
     }
     $this->setExtra(' style="background-color:' . $this->getValue() . ';"');
     return parent::render() . "<button class='btn' type='button' onclick=\"return TCP.popup('" . \XoopsBaseConfig::get('url') . "/include/',document.getElementById('" . $this->getName() . "'));\"> ... </button>";
 }
示例#7
0
 /**
  * render
  *
  * @return string
  */
 public function render()
 {
     $xoops = \Xoops::getInstance();
     if ($xoops->theme()) {
         $xoops->theme()->addScript('include/color-picker.js');
     } else {
         echo '<script type="text/javascript" src="' . $xoops->url('/include/color-picker.js') . '"></script>';
     }
     $temp = $this->get('value', '');
     if (!empty($temp)) {
         $this->set('style', 'background-color:' . $temp . ';');
     }
     return parent::render() . "<button class='btn' type='button' onclick=\"return TCP.popup('" . $xoops->url('/include/') . "',document.getElementById('" . $this->getName() . "'));\"> ... </button>";
 }
示例#8
0
 public static function valid($rules, $data)
 {
     static::$errors = [];
     static::triggerOnce('init');
     self::$data = $data = (array) $data;
     foreach ((array) $rules as $field_name => $rule) {
         $current = isset($data[$field_name]) ? $data[$field_name] : null;
         if (is_callable($rule)) {
             static::$errors[$field_name] = call_user_func($rule, $current);
             continue;
         } elseif (is_string($rule)) {
             $current_rules = array_flip(preg_split('/\\s*\\|\\s*/', $rule));
         } else {
             $current_rules = (array) $rule;
         }
         static::$errors[$field_name] = true;
         foreach ($current_rules as $method => $message) {
             $meth_name = strtok($method, ':');
             $opts = strtok(':') ?: '';
             $opts = $opts ? json_decode("[{$opts}]") : [];
             $meth_opts = $opts ? array_merge([$current], $opts) : [$current];
             if (static::$errors[$field_name] !== true) {
                 continue 2;
             }
             if (empty(static::$methods[$meth_name])) {
                 static::$errors[$field_name] = true;
             } else {
                 if (call_user_func_array(static::$methods[$meth_name]->validate, $meth_opts)) {
                     static::$errors[$field_name] = true;
                 } else {
                     $arg = [];
                     foreach ($meth_opts as $key => $value) {
                         $arg["arg_{$key}"] = $value;
                     }
                     static::$errors[$field_name] = Text::render(static::$methods[$meth_name]->message, $arg);
                 }
             }
         }
     }
     self::$data = [];
     // Clean non-errors
     static::$errors = array_filter(static::$errors, function ($v) {
         return $v !== true;
     });
     return empty(static::$errors);
 }
 public function testInput()
 {
     $text = new Text(['value' => "Valor", 'id' => 'id']);
     $text->setPlaceholder("Placeholder");
     $this->assertEquals($text->render(), '<div><input value="Valor" id="id" type="text" placeholder="Placeholder" /></div>');
 }
示例#10
0
 /**
  * @dataProvider dataProviderTestWords
  */
 public function testWords($in, $out)
 {
     $this->assertSame($out, $this->me->render(new \Inml\Text($in)));
 }
示例#11
0
 public static function translate($text, $params = null)
 {
     $result = static::get(static::$current_lang . '.' . strtolower($text), $text);
     return $params ? Text::render($result) : $result;
 }