Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (66 sloc) 2.82 kB
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Form
*/
namespace ZendTest\Form\Element;
use DateTime;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Form\Element\DateTimeSelect as DateTimeSelectElement;
use Zend\Form\Factory;
class DateTimeSelectTest extends TestCase
{
public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttributes()
{
$element = new DateTimeSelectElement();
$inputSpec = $element->getInputSpecification();
$this->assertArrayHasKey('validators', $inputSpec);
$this->assertInternalType('array', $inputSpec['validators']);
$expectedClasses = array(
'Zend\Validator\Date'
);
foreach ($inputSpec['validators'] as $validator) {
$class = get_class($validator);
$this->assertTrue(in_array($class, $expectedClasses), $class);
switch ($class) {
case 'Zend\Validator\Date':
$this->assertEquals('Y-m-d H:i:s', $validator->getFormat());
break;
default:
break;
}
}
}
public function testCanSetDateFromDateTime()
{
$element = new DateTimeSelectElement();
$element->setValue(new DateTime('2012-09-24 03:04:05'));
$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('05', $element->getSecondElement()->getValue());
}
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());
}
}
Jump to Line
Something went wrong with that request. Please try again.