示例#1
0
 public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttributes()
 {
     $element = new DateTimeElement('foo');
     $element->setAttributes(array('inclusive' => true, 'min' => '2000-01-01T00:00Z', 'max' => '2001-01-01T00:00Z', 'step' => '1'));
     $inputSpec = $element->getInputSpecification();
     $this->assertArrayHasKey('validators', $inputSpec);
     $this->assertInternalType('array', $inputSpec['validators']);
     $expectedClasses = array('Zend\\Validator\\Date', 'Zend\\Validator\\GreaterThan', 'Zend\\Validator\\LessThan', 'Zend\\Validator\\DateStep');
     foreach ($inputSpec['validators'] as $validator) {
         $class = get_class($validator);
         $this->assertTrue(in_array($class, $expectedClasses), $class);
         switch ($class) {
             case 'Zend\\Validator\\GreaterThan':
                 $this->assertTrue($validator->getInclusive());
                 $this->assertEquals('2000-01-01T00:00Z', $validator->getMin());
                 break;
             case 'Zend\\Validator\\LessThan':
                 $this->assertTrue($validator->getInclusive());
                 $this->assertEquals('2001-01-01T00:00Z', $validator->getMax());
                 break;
             case 'Zend\\Validator\\DateStep':
                 $dateInterval = new \DateInterval('PT1M');
                 $this->assertEquals($dateInterval, $validator->getStep());
                 break;
             default:
                 break;
         }
     }
 }
示例#2
0
 public function testProvidesInputSpecificationThatIncludesDateTimeFormatterBasedOnAttributes()
 {
     $element = new DateTimeElement('foo');
     $element->setFormat(DateTime::W3C);
     $inputSpec = $element->getInputSpecification();
     $this->assertArrayHasKey('filters', $inputSpec);
     $this->assertInternalType('array', $inputSpec['filters']);
     foreach ($inputSpec['filters'] as $filter) {
         switch ($filter['name']) {
             case 'Zend\\Filter\\DateTimeFormatter':
                 $this->assertEquals($filter['options']['format'], DateTime::W3C);
                 $this->assertEquals($filter['options']['format'], $element->getFormat());
                 break;
             default:
                 break;
         }
     }
 }