public function testCanRenderTextDelimiters()
 {
     $element = new DateTimeSelect('foo');
     $element->setShouldCreateEmptyOption(true);
     $element->setShouldRenderDelimiters(true);
     $element->setShouldShowSeconds(true);
     $markup = $this->helper->__invoke($element, \IntlDateFormatter::LONG, \IntlDateFormatter::LONG, 'pt_BR');
     // pattern === "d 'de' MMMM 'de' y HH'h'mm'min'ss's'"
     $this->assertStringMatchesFormat('%a de %a de %a %ah%amin%as', $markup);
 }
Exemplo n.º 2
0
 public function testUseDefaultValueForSecondsIfNotProvided()
 {
     $element = new DateTimeSelectElement();
     $element->setValue(array('year' => '2012', 'month' => '09', 'day' => '24', 'hour' => '03', 'minute' => '04'));
     $this->assertEquals('2012', $element->getYearElement()->getValue());
     $this->assertEquals('09', $element->getMonthElement()->getValue());
     $this->assertEquals('24', $element->getDayElement()->getValue());
     $this->assertEquals('03', $element->getHourElement()->getValue());
     $this->assertEquals('04', $element->getMinuteElement()->getValue());
     $this->assertEquals('00', $element->getSecondElement()->getValue());
 }
Exemplo n.º 3
0
 protected function generateFormElementByType($name, $type, $values = array(), $priority)
 {
     switch ($type) {
         case 'FILE':
             $elm = new Element\File();
             $elm->setLabel(strtoupper($name));
             break;
         case 'SELECT':
             $elm = new Element\Select($name);
             $elm->setLabel(strtoupper($name));
             $elm->setAttribute('id', $name . '_ID');
             if ($values instanceof \Traversable || is_array($values)) {
                 $elm->setValueOptions($values);
             }
             break;
         case 'DATE':
             if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') {
                 $elm = new \Zf2datatable\Form\Element\DateCalendar($name);
                 $elm->setAttribute('id', $name . '_ID');
                 $elm->setAttribute('class', 'form-control');
                 $elm->setLabel($name);
                 $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['date_js_properties']);
                 \Zf2datatable\Form\Element\DateCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['date_format_in']);
                 \Zf2datatable\Form\Element\DateCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['date_format_out']);
             } else {
                 $elm = new Element\Date($name);
                 $elm->setLabel(strtoupper($name));
                 $elm->setAttributes(array('type' => 'date'));
                 $elm->setFormat('Y-m-d');
             }
             break;
         case 'DATETIME':
             if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') {
                 $elm = new \Zf2datatable\Form\Element\DateTimeCalendar($name);
                 $elm->setAttribute('id', $name . '_ID');
                 $elm->setAttribute('class', 'form-control');
                 $elm->setLabel($name);
                 $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['datetime_js_properties']);
                 \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['datetime_format_in']);
                 \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['datetime_format_out']);
             } else {
                 $elm = new Element\DateTimeSelect($name);
                 $elm->setLabel(strtoupper($name));
             }
             break;
         default:
             $elm = new Element($name);
             $elm->setLabel(strtoupper($name));
             $elm->setAttributes(array('type' => 'text'));
             break;
     }
     $elm->setOption('priority', $priority);
     return $elm;
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function getInputSpecification()
 {
     $inputSpec = parent::getInputSpecification();
     $inputSpec['filters'][] = ['name' => 'DateTimeSelect', 'options' => ['null_on_empty' => true]];
     return $inputSpec;
 }
Exemplo n.º 5
0
 public function testNoMinutesDelimiterIfSecondsNotShown()
 {
     $element = new DateTimeSelect('foo');
     $element->setValue(array('year' => '2012', 'month' => '09', 'day' => '24', 'hour' => '03', 'minute' => '04', 'second' => '59'));
     $element->setShouldShowSeconds(false);
     $element->shouldRenderDelimiters(true);
     $markup = $this->helper->__invoke($element);
     // the last $markup char should be the '>' of the minutes  html select
     // closing tag and not the delimiter
     $this->assertEquals('>', substr($markup, -1));
 }
Exemplo n.º 6
0
 public function testPassingNullValueToSetValueWillUseCurrentDate()
 {
     $now = new DateTime();
     $element = new DateTimeSelectElement();
     $element->setValue(null);
     $yearElement = $element->getYearElement();
     $monthElement = $element->getMonthElement();
     $dayElement = $element->getDayElement();
     $this->assertEquals($now->format('Y'), $yearElement->getValue());
     $this->assertEquals($now->format('m'), $monthElement->getValue());
     $this->assertEquals($now->format('d'), $dayElement->getValue());
 }