Development

Changeset 11982

You must first sign up to be able to contribute.

Changeset 11982

Show
Ignore:
Timestamp:
10/06/08 17:09:28 (6 years ago)
Author:
fabien
Message:

[1.2] added the Countable interface for sfForm (refs #4520)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/lib/form/sfForm.class.php

    r11975 r11982  
    2121 * @version    SVN: $Id$ 
    2222 */ 
    23 class sfForm implements ArrayAccess 
     23class sfForm implements ArrayAccess, Countable 
    2424{ 
    2525  protected static 
     
    902902 
    903903  /** 
     904   * Returns the number of form fields (implements the Countable interface). 
     905   * 
     906   * @return integer The number of embedded form fields 
     907   */ 
     908  public function count() 
     909  { 
     910    return count($this->getFormFieldSchema()); 
     911  } 
     912 
     913  /** 
    904914   * Converts uploaded file array to a format following the $_GET and $POST naming convention. 
    905915   * 
  • branches/1.2/test/unit/form/sfFormTest.php

    r11972 r11982  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(119, new lime_output_color()); 
     13$t = new lime_test(120, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    175175  $t->pass('sfForm ArrayAccess implementation throws a LogicException if the form field does not exist'); 
    176176} 
     177 
     178// Countable interface 
     179$t->diag('Countable interface'); 
     180$f = new FormTest(); 
     181$f->setWidgetSchema(new sfWidgetFormSchema(array( 
     182  'first_name' => new sfWidgetFormInput(array('default' => 'Fabien')), 
     183  'last_name'  => new sfWidgetFormInput(), 
     184  'image'      => new sfWidgetFormInputFile(), 
     185))); 
     186$t->is(count($f), 3, 'sfForm implements the Countable interface'); 
    177187 
    178188// ->bind() ->isValid() ->hasErrors() ->getValues() ->getValue() ->isBound() ->getErrorSchema()