示例#1
0
 /**
  * __construct
  *
  * @param string  $caption  caption
  * @param string  $name     name
  * @param integer $size     size
  * @param integer $value    value unix timestamp
  * @param boolean $showtime true to show time, false for date only
  */
 public function __construct($caption, $name, $size = 2, $value = 0, $showtime = true)
 {
     parent::__construct($caption, '');
     $value = (int) $value;
     $value = $value > 0 ? $value : time();
     $datetime = getdate($value);
     $date = new DateSelect('', $name . '[date]', $size, $value);
     $date->setAttribute('id', $name . '-date');
     $this->addElement($date);
     if ($showtime) {
         $timearray = array();
         for ($i = 0; $i < 24; ++$i) {
             for ($j = 0; $j < 60; $j = $j + 10) {
                 $key = $i * 3600 + $j * 60;
                 $timearray[$key] = $j != 0 ? $i . ':' . $j : $i . ':0' . $j;
             }
         }
         ksort($timearray);
         $timeselect = new Select('', $name . '[time]', $datetime['hours'] * 3600 + 600 * ceil($datetime['minutes'] / 10));
         $timeselect->setAttribute('id', $name . '-time');
         $timeselect->addOptionArray($timearray);
         $timeselect->setClass('span2');
         $this->addElement($timeselect);
     } else {
         $this->addElement(new Hidden($name . '[time]', 0));
     }
 }
 public function testVerificaSeOsDadosForamInseridos()
 {
     $select = new Select();
     $select->setId("selectCat");
     $select->setName("categoria");
     $select->setClass("form-control");
     $select->setProtected("protected");
     $select->setLabel("Categoria");
     $select->setAlert("Erro no field.");
     $this->assertEquals("selectCat", $select->getId());
     $this->assertEquals("categoria", $select->getName());
     $this->assertEquals("form-control", $select->getClass());
     $this->assertEquals("protected", $select->getProtected());
     $this->assertEquals("Categoria", $select->getLabel());
     $this->assertEquals("Erro no field.", $select->getAlert());
 }
示例#3
0
 public function testGetHtmlJs()
 {
     $selectId = 'testId';
     $selectClass = 'testClass';
     $selectTitle = 'testTitle';
     $selectName = 'testName';
     $options = ['testValue' => 'testLabel', 'selectedValue' => 'selectedLabel'];
     $selectedValue = 'selectedValue';
     $this->select->setId($selectId);
     $this->select->setClass($selectClass);
     $this->select->setTitle($selectTitle);
     $this->select->setName($selectName);
     $this->select->setOptions($options);
     $this->select->setValue($selectedValue);
     $result = '<select name="testName" id="testId" class="testClass" title="testTitle" >' . '<option value="testValue" #{option_extra_attr_4016862802} >testLabel</option>' . '<option value="selectedValue" selected="selected" #{option_extra_attr_662265145} >selectedLabel</option>' . '</select>';
     $this->select->setIsRenderToJsTemplate(true);
     $this->assertEquals($result, $this->select->getHtml());
 }