public function testCorrectFormatPassedToDateValidator() { $element = new DateElement('foo'); $element->setAttributes(array('min' => '2012-01-01', 'max' => '2012-12-31')); $element->setFormat('d-m-Y'); $inputSpec = $element->getInputSpecification(); foreach ($inputSpec['validators'] as $validator) { switch (get_class($validator)) { case 'Zend\\Validator\\DateStep': case 'Zend\\Validator\\Date': $this->assertEquals('d-m-Y', $validator->getFormat()); break; } } }
public function testErrorShowTwice() { $element = new Element\Date('birth'); $element->setFormat('Y-m-d'); $element->setValue('2010-13-13'); $validator = new \Zend\Validator\Date(); $validator->isValid($element->getValue()); $element->setMessages($validator->getMessages()); $markup = $this->helper->__invoke($element); $this->assertEquals(2, count(explode("<ul><li>The input does not appear to be a valid date</li></ul>", $markup))); }
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; }