Development

Changeset 7081

You must first sign up to be able to contribute.

Changeset 7081

Show
Ignore:
Timestamp:
01/17/08 11:54:54 (8 months ago)
Author:
fabien
Message:

fixed sfValidatorDate for empty arrays

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/validator/sfValidatorDate.class.php

    r6875 r7081  
    159159    return $clean; 
    160160  } 
     161 
     162  /** 
     163   * @see sfValidator 
     164   */ 
     165  protected function isEmpty($value) 
     166  { 
     167    if (is_array($value)) 
     168    { 
     169      $filtered = array_filter($value); 
     170 
     171      return empty($filtered); 
     172    } 
     173 
     174    return parent::isEmpty($value); 
     175  } 
    161176} 
  • branches/1.1/test/unit/validator/sfValidatorDateTest.php

    r6945 r7081  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(29, new lime_output_color()); 
     13$t = new lime_test(33, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorDate(); 
     
    133133$v->setOption('with_time', true); 
    134134$t->is($v->clean(time()), time(), '->clean() output format can be change with the date_output option'); 
     135 
     136// required 
     137$v = new sfValidatorDate(); 
     138foreach (array( 
     139  array('year' => '', 'month' => '', 'day' => ''), 
     140  array('year' => null, 'month' => null, 'day' => null), 
     141  '', 
     142  null, 
     143) as $input) 
     144{ 
     145  try 
     146  { 
     147    $v->clean($input); 
     148    $t->fail('->clean() throws an exception if the date is empty and required is true'); 
     149  } 
     150  catch (sfValidatorError $e) 
     151  { 
     152    $t->pass('->clean() throws an exception if the date is empty and required is true'); 
     153  } 
     154}