示例#1
0
文件: Iframe.php 项目: JBZoo/Html
 /**
  * Create iframe.
  *
  * @param string $src
  * @param string $class
  * @param string $id
  * @param array $attrs
  * @return string
  */
 public function render($src, $class = '', $id = '', array $attrs = array())
 {
     $attrs = array_merge(array('frameborder' => 0, 'content' => null, 'tag' => 'iframe', 'src' => Str::trim($src)), $attrs);
     $attrs = $this->_cleanAttrs($attrs);
     $content = $attrs['content'];
     unset($attrs['content']);
     return Html::_('tag')->render($content, Str::trim($class), Str::trim($id), $attrs);
 }
示例#2
0
 /**
  * Test bool checkbox.
  *
  * @return void
  */
 public function testCheckbox()
 {
     $radio = Html::_('checkbool');
     $actual = $radio->render('show');
     $expected = array('label' => array('for' => 'preg:/checkbox-[0-9]+/', 'class' => 'jb-checkbox-lbl jb-label-1'), 'input' => array('id' => 'preg:/checkbox-[0-9]+/', 'name' => 'show', 'type' => 'checkbox', 'value' => 1, 'class' => 'jb-val-1'), ' Yes', '/label');
     isHtml($expected, $actual);
     $actual = $radio->render('show', 1, array('data-rel' => 'tooltip'), false);
     $expected = array('input' => array('id' => 'preg:/checkbox-[0-9]+/', 'name' => 'show', 'type' => 'checkbox', 'value' => 1, 'class' => 'jb-val-1', 'data-rel' => 'tooltip', 'checked' => 'checked'), 'label' => array('for' => 'preg:/checkbox-[0-9]+/', 'class' => 'jb-checkbox-lbl jb-label-1'), 'Yes', '/label');
     isHtml($expected, $actual);
 }
示例#3
0
 /**
  * Output content.
  *
  * @param string $name
  * @param array $attrs
  * @param int $checked
  * @param bool|true $isLblWrap
  * @return string
  */
 public function render($name, $checked = 0, array $attrs = array(), $isLblWrap = true)
 {
     $this->_type = Str::low($this->_type);
     if ($this->_type === 'radio') {
         $options = array(0 => $this->_translate('No'), 1 => $this->_translate('Yes'));
         return Html::_('radio')->render($options, $name, $checked, $attrs, $isLblWrap);
     } elseif ($this->_type === 'checkbox') {
         $options = array(1 => $this->_translate('Yes'));
         return Html::_('checkbox')->render($options, $name, $checked, $attrs, $isLblWrap);
     }
 }
示例#4
0
 /**
  * Performance render elements.
  *
  * @return void
  */
 public function testRenders()
 {
     $options = $this->_options;
     runBench(array('Select' => function () use($options) {
         return Html::_('select')->render($options, 'default', array('val-29'));
     }, 'Bool' => function () use($options) {
         return Html::_('checkbool')->render('bool');
     }, 'Checkbox' => function () use($options) {
         return Html::_('checkbox')->render($options, 'checkbox', 'val-20');
     }, 'Radio' => function () use($options) {
         return Html::_('radio')->render($options, 'radio', 'val-11');
     }, 'InputText' => function () use($options) {
         return Html::_('input')->render($options, 'input', 'val-11');
     }, 'Textarea' => function () {
         return Html::_('textarea')->render('textarea', 'Text area content');
     }, 'DataList' => function () use($options) {
         return Html::_('datalist')->render($options);
     }), array('count' => 500, 'name' => 'Renders performance'));
 }
示例#5
0
文件: HtmlTest.php 项目: JBZoo/Html
 /**
  * Test add custom render.
  *
  * @return void
  */
 public function testCustomAddRender()
 {
     $expected = 'Im test custom render';
     $result = $this->html->_('test', 'Custom\\Html')->render('name', 'value', 'class', 'id');
     isSame($expected, $result);
 }
示例#6
0
 /**
  * Setup test data.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->html = Html::getInstance();
     $this->checkbox = $this->html->_('checkbox');
 }
示例#7
0
<?php

/**
 * JBZoo Html
 *
 * This file is part of the JBZoo CCK package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package   Html
 * @license   MIT
 * @copyright Copyright (C) JBZoo.com,  All rights reserved.
 * @link      https://github.com/JBZoo/Html
 * @author    Sergey Kalistratov <*****@*****.**>
 */
namespace PHPSTORM_META;

/** @noinspection PhpUnusedLocalVariableInspection */
/** @noinspection PhpIllegalArrayKeyTypeInspection */
$STATIC_METHOD_TYPES = [\JBZoo\Html\Html::_('') => ['tag' instanceof \JBZoo\Html\Render\Tag, 'text' instanceof \JBZoo\Html\Render\Text, 'image' instanceof \JBZoo\Html\Render\Image, 'input' instanceof \JBZoo\Html\Render\Input, 'radio' instanceof \JBZoo\Html\Render\Radio, 'hidden' instanceof \JBZoo\Html\Render\Hidden, 'button' instanceof \JBZoo\Html\Render\Button, 'select' instanceof \JBZoo\Html\Render\Select, 'iframe' instanceof \JBZoo\Html\Render\Iframe, 'textarea' instanceof \JBZoo\Html\Render\TextArea, 'datalist' instanceof \JBZoo\Html\Render\Datalist, 'radiobool' instanceof \JBZoo\Html\Render\RadioBool, 'checkbool' instanceof \JBZoo\Html\Render\CheckBool, 'checkbox' instanceof \JBZoo\Html\Render\Checkbox]];
示例#8
0
文件: TextArea.php 项目: JBZoo/Html
 /**
  * Output content.
  *
  * @param string $name
  * @param string $content
  * @param array|string $class
  * @param string $id
  * @param array $attrs
  * @return string
  */
 public function render($name, $content = '', $class = '', $id = '', array $attrs = array())
 {
     $attrs['name'] = $name;
     $attrs['tag'] = 'textarea';
     return Html::_('tag')->render($content, $class, $id, $attrs);
 }
示例#9
0
文件: SelectTest.php 项目: JBZoo/Html
 /**     * Setup test data.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->html = Html::getInstance();
     $this->select = $this->html->_('select');
 }
示例#10
0
文件: RadioTest.php 项目: JBZoo/Html
 /**
  * Test radio list output.
  *
  * return void
  */
 public function testRadio()
 {
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render(array('val-1', 'val-2', 'val-3'), 'test', array(), array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-0'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 0, 'class' => 'jb-val-0')), ' val-1', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-1'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 1, 'class' => 'jb-val-1')), ' val-2', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-2'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 2, 'class' => 'jb-val-2')), ' val-3', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test data and checked single option by array.
     $html = $this->radio->render(array('<p>tag</p>' => 'Tag', ' ' => 'Empty', '"Test label 3"' => 'Custom', 'значение' => 'Translate cyrillic value', 'common' => 'Common label'), 'test', array('common'), array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-lt-p-gt-tag-lt-p-gt'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => '&lt;p&gt;tag&lt;/p&gt;', 'class' => 'jb-val-lt-p-gt-tag-lt-p-gt')), ' Tag', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => ' ', 'class' => 'jb-val-')), ' Empty', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-quot-test-label-3-quot'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => '&quot;Test label 3&quot;', 'class' => 'jb-val-quot-test-label-3-quot')), ' Custom', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-znachenie'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'значение', 'class' => 'jb-val-znachenie')), ' Translate cyrillic value', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-common'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'common', 'class' => 'jb-val-common', 'checked' => 'checked')), ' Common label', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test checked single option by string.
     $html = $this->radio->render(array('"Test label 3"' => 'Custom', 'значение' => 'Translate cyrillic value', 'common' => 'Common label'), 'test', 'common', array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-quot-test-label-3-quot'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => '&quot;Test label 3&quot;', 'class' => 'jb-val-quot-test-label-3-quot')), ' Custom', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-znachenie'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'значение', 'class' => 'jb-val-znachenie')), ' Translate cyrillic value', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-common'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'common', 'class' => 'jb-val-common', 'checked' => 'checked')), ' Common label', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render(array('test-7' => 'Test label 7', 'test-8' => 'Test label 8'), 'test', array('common', 'test-8', 'test-2', 'test-4'));
     $expected = array(array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'no-exits', 'class' => 'jb-val-no-exits', 'checked' => 'checked')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-no-exits')), 'No exits', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-7', 'class' => 'jb-val-test-7')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-7')), 'Test label 7', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-8', 'class' => 'jb-val-test-8')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-8')), 'Test label 8', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render(array('test-7' => 'Test label 7', 'test-8' => 'Test label 8'), 'test', 'test');
     $expected = array(array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'no-exits', 'class' => 'jb-val-no-exits', 'checked' => 'checked')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-no-exits')), 'No exits', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-7', 'class' => 'jb-val-test-7')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-7')), 'Test label 7', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-8', 'class' => 'jb-val-test-8')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-8')), 'Test label 8', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test checked options by array.
     $html = $this->radio->render(array('test-1' => 'Test label 1', 'test-2' => 'Test label 2', 'test-3' => 'Test label 3', 'test-4' => 'Test label 4', 'test-6' => 'Test label 6', 'test-7' => 'Test label 7', 'test-8' => 'Test label 8', 'common' => 'Common label'), 'test', array('common', 'test-8', 'test-2', 'test-4'), array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-1'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-1', 'class' => 'jb-val-test-1')), ' Test label 1', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-2'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-2', 'class' => 'jb-val-test-2')), ' Test label 2', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-3'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-3', 'class' => 'jb-val-test-3')), ' Test label 3', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-4'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-4', 'class' => 'jb-val-test-4', 'checked' => 'checked')), ' Test label 4', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-6'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-6', 'class' => 'jb-val-test-6')), ' Test label 6', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-7'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-7', 'class' => 'jb-val-test-7')), ' Test label 7', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-8'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-8', 'class' => 'jb-val-test-8')), ' Test label 8', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-common'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'common', 'class' => 'jb-val-common')), ' Common label', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test setup callable template.
     $options = array('test-1' => 'Test label 1');
     $html = $this->radio->render($options, 'test', 0, array(), function ($list, $name, $value, $id, $text, $attrs) {
         $alias = Str::slug($value, true);
         $inpClass = 'jb-val-' . $alias;
         $input = $list->input($name, $value, $id, $inpClass, $attrs);
         $text = '<span class="label-title">' . $text . '</span>';
         $label = $list->label($id, $alias, $text);
         return implode(PHP_EOL, array($input, $label));
     });
     $expected = array(array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-1', 'class' => 'jb-val-test-1', 'checked' => 'checked')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-1')), 'span' => array('class' => 'label-title'), 'Test label 1', '/span', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render($options, 'test', 0, array(), 'no-exits');
     isEmpty($html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $inputReload = Html::_('checkbox', 'Custom\\Html');
     $html = $inputReload->render($options, 'test');
     $expected = array('div' => array('class' => 'jb-input jb-checkbox'), 'label' => array('for' => 'preg:/checkbox-[0-9]+/', 'class' => 'jb-checkbox-lbl jb-label-test-1'), array('input' => array('id' => 'preg:/checkbox-[0-9]+/', 'name' => 'test', 'type' => 'checkbox', 'value' => 'test-1', 'class' => 'jb-val-test-1')), 'span' => array('class' => 'label-title'), 'Test label 1', '/span', '/label', '/div');
     isHtml($expected, $html);
 }
示例#11
0
文件: HiddenTest.php 项目: JBZoo/Html
 /**
  * Setup test data.
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->html = Html::getInstance();
     $this->hidden = $this->html->_('hidden');
 }