public function testGetCheckBoxes()
 {
     $div = new HtmlNode();
     $checkBoxes = HtmlCheckBox::getCheckBoxes(['name1' => 'value1', 'name2' => 'value2']);
     $div->append($checkBoxes);
     $this->assertEquals('<div><span><input name="name1" value="value1" type="checkbox"/></span><br/><span><input name="name2" value="value2" type="checkbox"/></span></div>', "{$div}");
 }
    public function testRenderRecursive()
    {
        $img = new HtmlLeaf(['kind' => 'img', 'attr' => ['id' => 'img1', 'class' => 'wide', 'href' => 'public/img/image1.jpg']]);
        $div = new HtmlNode(['child' => [$img], 'attr' => ['id' => 'div1']]);
        $expected = '
$' . $img->getID() . ' = new \\Simphotonics\\Dom\\HtmlLeaf([
  \'kind\' => \'img\',
  \'attr\'=> [
    \'id\' => \'img1\',
    \'class\' => \'wide\',
    \'href\' => \'public/img/image1.jpg\'
  ],
]); 

$' . $div->getID() . ' = new \\Simphotonics\\Dom\\HtmlNode([
  \'kind\' => \'div\',
  \'attr\'=> [
    \'id\' => \'div1\'
  ],
  \'child\'=> [
    $' . $img->getID() . '
  ]
]); 
';
        $this->assertEquals($expected, Renderer::renderRecursive($div));
    }
 /**
  * Initialises HtmlNavigator object.
  * @method  initNavigator
  * @return  void
  */
 private static function initNavigator()
 {
     // Templates
     $L = new HtmlLeaf(['kind' => 'a']);
     $B = new HtmlNode(['kind' => 'li', 'child' => [$L]]);
     // Home
     $B_home = clone $B;
     $B_home[0]->setAttr(['href' => '/'])->setCont('HOME');
     // Services
     $B_services = clone $B;
     $B_services[0]->setAttr(['href' => '/services'])->setCont('SERVICES');
     $Menu = new HtmlNode(['kind' => 'ul', 'attr' => ['id' => 'mainMenu']]);
     $Menu->append([$B_home, $B_services]);
     return new HtmlNavigator(['kind' => 'div', 'attr' => ['id' => 'nav', 'class' => 'has-shadow'], 'child' => [$Menu]]);
 }
Exemple #4
0
 /**
  * Constructs table object.
  * @method  __construct
  * @param   array        $inputData  User input data.
  * @param   integer      $nCols      Number of columns.
  * @param   integer      $headers    Flag enabling/disabling
  *                                   table headers.
  * @param   integer      $rowAlt     Add class alt to every
  *                                   $altRow row.
  * @param   integer      $rowOffset  Omit class alt for the first
  *                                   $rowOffset rows.
  */
 public function __construct($inputData = [], $nCols = 2, $headersOnOff = self::SET_TABLE_HEADERS, $rowAlt = 2, $rowOffset = 2)
 {
     parent::__construct(['kind' => 'table']);
     $this->nCols = $this->checkNcolsRange($nCols);
     $this->headersOnOff = $headersOnOff;
     $this->rowAlt = $this->checkRowAltRange($rowAlt);
     $this->rowOffset = $this->checkRowOffsetRange($rowOffset);
     // Store table data.
     $this->inputData = $inputData;
     // Append row nodes to table.
     $this->append($this->makeTableRows());
 }
Exemple #5
0
 /**
  * Constructs object.
  * @method __construct
  * @param  string      $name    Input element name.
  * @param  array       $options Array of the form: ['option1',...,'selected' => 'option10',...].
  */
 public function __construct($name = 'name', array $options = ['value1' => 'displayedValue1', 'value2' => 'displayedValue1'], $defaultOption = 'value2')
 {
     parent::__construct(['kind' => 'select', 'attr' => ['name' => $name, 'id' => $name]]);
     $this->initOptions($options, $defaultOption);
 }
Exemple #6
0
 /**
  * Constructs object.
  * @method __construct
  * @param  array       $input
  * @param  [type]      $framework
  */
 public function __construct(array $input = ['kind' => 'div'], callable $getURI = null)
 {
     parent::__construct($input);
     $this->getURI = func_num_args() > 1 ? $getURI : 'Simphotonics\\Utils\\WebUtils::getURI';
     $this->selfAnchor = $this->extendAttributes();
 }
Exemple #7
0
 /**
  * Constructs object.
  * @method __construct
  * @param  array       $input Array of the form:
  *                     [checkBoxName => checkBoxValue]
  */
 public function __construct($name = 'name', $value = 'value')
 {
     parent::__construct(['kind' => 'input', 'attr' => ['name' => $name, 'value' => $value, 'type' => 'checkbox']]);
 }
Exemple #8
0
 public function testRenderBlock()
 {
     self::$n->setCont('This is a block element!');
     $this->assertEquals('<div>This is a block element!<div class="main"></div><div class="main bold"></div></div>', '' . self::$n);
 }
Exemple #9
0
 /**
  * Constructs object.
  * @method  __construct
  * @param   array        $input     Objects specs.
  * @param   array        $hrefList  Array of the form:
  *                                  ['title' => 'href'].
  */
 public function __construct(array $anchors = ['Home' => 'http://simphotonics.com/'])
 {
     parent::__construct(['kind' => 'div']);
     $this->setAnchors($anchors);
 }
Exemple #10
0
 /**
  * Constructors an HtmlForm object.
  * @method  __construct
  * @param   array        $params  Array of the form:
  * ['action' => url, 'model' => model]
  */
 public function __construct($action = 'Warning: Form action not set!')
 {
     parent::__construct(['kind' => 'form', 'attr' => ['id' => $this->id, 'method' => 'post', 'action' => $action]]);
 }