Development

Changeset 19780

You must first sign up to be able to contribute.

Changeset 19780

Show
Ignore:
Timestamp:
07/01/09 12:49:37 (9 months ago)
Author:
nicolas
Message:

[1.2, 1.3] added test to ensure embedded form fields id integrity (closes #4741)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/test/unit/form/sfFormTest.php

    r17587 r19780  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(140, new lime_output_color()); 
     13$t = new lime_test(144, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    1818  { 
    1919    return "*$secret*"; 
     20  } 
     21} 
     22 
     23class TestForm1 extends FormTest 
     24{ 
     25  public function configure() 
     26  { 
     27    $this->disableCSRFProtection(); 
     28    $this->setWidgets(array( 
     29      'a' => new sfWidgetFormInput(), 
     30      'b' => new sfWidgetFormInput(), 
     31      'c' => new sfWidgetFormInput(), 
     32    )); 
     33    $this->setValidators(array( 
     34      'a' => new sfValidatorString(array('min_length' => 2)), 
     35      'b' => new sfValidatorString(array('max_length' => 3)), 
     36      'c' => new sfValidatorString(array('max_length' => 1000)), 
     37    )); 
     38    $this->getWidgetSchema()->setLabels(array( 
     39      'a' => '1_a', 
     40      'b' => '1_b', 
     41      'c' => '1_c', 
     42    )); 
     43    $this->getWidgetSchema()->setHelps(array( 
     44      'a' => '1_a', 
     45      'b' => '1_b', 
     46      'c' => '1_c', 
     47    )); 
     48  } 
     49} 
     50 
     51class TestForm2 extends FormTest 
     52{ 
     53  public function configure() 
     54  { 
     55    $this->disableCSRFProtection(); 
     56    $this->setWidgets(array( 
     57      'c' => new sfWidgetFormTextarea(), 
     58      'd' => new sfWidgetFormTextarea(), 
     59    )); 
     60    $this->setValidators(array( 
     61      'c' => new sfValidatorPass(), 
     62      'd' => new sfValidatorString(array('max_length' => 5)), 
     63    )); 
     64    $this->getWidgetSchema()->setLabels(array( 
     65      'c' => '2_c', 
     66      'd' => '2_d', 
     67    )); 
     68    $this->getWidgetSchema()->setHelps(array( 
     69      'c' => '2_c', 
     70      'd' => '2_d', 
     71    )); 
     72    $this->validatorSchema->setPreValidator(new sfValidatorPass()); 
     73    $this->validatorSchema->setPostValidator(new sfValidatorPass()); 
    2074  } 
    2175} 
     
    486540$t->is($w['author']->generateName('first_name'), 'article[author][first_name]', '->embedForm() changes the name format to reflect the embedding'); 
    487541$t->is($w['author']['company']->generateName('name'), 'article[author][company][name]', '->embedForm() changes the name format to reflect the embedding'); 
     542 
     543// tests for ticket #4754 
     544$f1 = new TestForm1(); 
     545$f2 = new TestForm2(); 
     546$f1->embedForm('f2', $f2); 
     547$t->is($f1['f2']['c']->render(), '<textarea rows="4" cols="30" name="f2[c]" id="f2_c"></textarea>', '->embedForm() generates a correct id in embedded form fields'); 
     548$t->is($f1['f2']['c']->renderLabel(), '<label for="f2_c">2_c</label>', '->embedForm() generates a correct label id correctly in embedded form fields'); 
     549 
     550// tests for ticket #4754 
     551$f1 = new TestForm1(); 
     552$f2 = new TestForm2(); 
     553$f1->embedForm('f2', $f2); 
     554$t->is($f1['f2']['c']->render(), '<textarea rows="4" cols="30" name="f2[c]" id="f2_c"></textarea>', '->embedForm() generates a correct id in embedded form fields'); 
     555$t->is($f1['f2']['c']->renderLabel(), '<label for="f2_c">2_c</label>', '->embedForm() generates a correct label id correctly in embedded form fields'); 
    488556 
    489557// ->embedFormForEach() 
     
    705773$t->diag('mergeForm()'); 
    706774 
    707 class TestForm1 extends FormTest 
    708 { 
    709   public function configure() 
    710   { 
    711     $this->disableCSRFProtection(); 
    712     $this->setWidgets(array( 
    713       'a' => new sfWidgetFormInput(), 
    714       'b' => new sfWidgetFormInput(), 
    715       'c' => new sfWidgetFormInput(), 
    716     )); 
    717     $this->setValidators(array( 
    718       'a' => new sfValidatorString(array('min_length' => 2)), 
    719       'b' => new sfValidatorString(array('max_length' => 3)), 
    720       'c' => new sfValidatorString(array('max_length' => 1000)), 
    721     )); 
    722     $this->getWidgetSchema()->setLabels(array( 
    723       'a' => '1_a', 
    724       'b' => '1_b', 
    725       'c' => '1_c', 
    726     )); 
    727     $this->getWidgetSchema()->setHelps(array( 
    728       'a' => '1_a', 
    729       'b' => '1_b', 
    730       'c' => '1_c', 
    731     )); 
    732   } 
    733 } 
    734  
    735 class TestForm2 extends FormTest 
    736 { 
    737   public function configure() 
    738   { 
    739     $this->disableCSRFProtection(); 
    740     $this->setWidgets(array( 
    741       'c' => new sfWidgetFormTextarea(), 
    742       'd' => new sfWidgetFormTextarea(), 
    743     )); 
    744     $this->setValidators(array( 
    745       'c' => new sfValidatorPass(), 
    746       'd' => new sfValidatorString(array('max_length' => 5)), 
    747     )); 
    748     $this->getWidgetSchema()->setLabels(array( 
    749       'c' => '2_c', 
    750       'd' => '2_d', 
    751     )); 
    752     $this->getWidgetSchema()->setHelps(array( 
    753       'c' => '2_c', 
    754       'd' => '2_d', 
    755     )); 
    756     $this->validatorSchema->setPreValidator(new sfValidatorPass()); 
    757     $this->validatorSchema->setPostValidator(new sfValidatorPass()); 
    758   } 
    759 } 
    760  
    761775$f1 = new TestForm1(); 
    762776$f2 = new TestForm2(); 
  • branches/1.3/test/unit/form/sfFormTest.php

    r19531 r19780  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(144); 
     13$t = new lime_test(146); 
    1414 
    1515class FormTest extends sfForm 
     
    1818  { 
    1919    return "*$secret*"; 
     20  } 
     21} 
     22 
     23class TestForm1 extends FormTest 
     24{ 
     25  public function configure() 
     26  { 
     27    $this->disableCSRFProtection(); 
     28    $this->setWidgets(array( 
     29      'a' => new sfWidgetFormInput(), 
     30      'b' => new sfWidgetFormInput(), 
     31      'c' => new sfWidgetFormInput(), 
     32    )); 
     33    $this->setValidators(array( 
     34      'a' => new sfValidatorString(array('min_length' => 2)), 
     35      'b' => new sfValidatorString(array('max_length' => 3)), 
     36      'c' => new sfValidatorString(array('max_length' => 1000)), 
     37    )); 
     38    $this->getWidgetSchema()->setLabels(array( 
     39      'a' => '1_a', 
     40      'b' => '1_b', 
     41      'c' => '1_c', 
     42    )); 
     43    $this->getWidgetSchema()->setHelps(array( 
     44      'a' => '1_a', 
     45      'b' => '1_b', 
     46      'c' => '1_c', 
     47    )); 
     48  } 
     49} 
     50 
     51class TestForm2 extends FormTest 
     52{ 
     53  public function configure() 
     54  { 
     55    $this->disableCSRFProtection(); 
     56    $this->setWidgets(array( 
     57      'c' => new sfWidgetFormTextarea(), 
     58      'd' => new sfWidgetFormTextarea(), 
     59    )); 
     60    $this->setValidators(array( 
     61      'c' => new sfValidatorPass(), 
     62      'd' => new sfValidatorString(array('max_length' => 5)), 
     63    )); 
     64    $this->getWidgetSchema()->setLabels(array( 
     65      'c' => '2_c', 
     66      'd' => '2_d', 
     67    )); 
     68    $this->getWidgetSchema()->setHelps(array( 
     69      'c' => '2_c', 
     70      'd' => '2_d', 
     71    )); 
     72    $this->validatorSchema->setPreValidator(new sfValidatorPass()); 
     73    $this->validatorSchema->setPostValidator(new sfValidatorPass()); 
    2074  } 
    2175} 
     
    519573$t->is($w['author']->generateName('first_name'), 'article[author][first_name]', '->embedForm() changes the name format to reflect the embedding'); 
    520574$t->is($w['author']['company']->generateName('name'), 'article[author][company][name]', '->embedForm() changes the name format to reflect the embedding'); 
     575 
     576// tests for ticket #4754 
     577$f1 = new TestForm1(); 
     578$f2 = new TestForm2(); 
     579$f1->embedForm('f2', $f2); 
     580$t->is($f1['f2']['c']->render(), '<textarea rows="4" cols="30" name="f2[c]" id="f2_c"></textarea>', '->embedForm() generates a correct id in embedded form fields'); 
     581$t->is($f1['f2']['c']->renderLabel(), '<label for="f2_c">2_c</label>', '->embedForm() generates a correct label id correctly in embedded form fields'); 
    521582 
    522583// ->embedFormForEach() 
     
    738799$t->diag('mergeForm()'); 
    739800 
    740 class TestForm1 extends FormTest 
    741 { 
    742   public function configure() 
    743   { 
    744     $this->disableCSRFProtection(); 
    745     $this->setWidgets(array( 
    746       'a' => new sfWidgetFormInput(), 
    747       'b' => new sfWidgetFormInput(), 
    748       'c' => new sfWidgetFormInput(), 
    749     )); 
    750     $this->setValidators(array( 
    751       'a' => new sfValidatorString(array('min_length' => 2)), 
    752       'b' => new sfValidatorString(array('max_length' => 3)), 
    753       'c' => new sfValidatorString(array('max_length' => 1000)), 
    754     )); 
    755     $this->getWidgetSchema()->setLabels(array( 
    756       'a' => '1_a', 
    757       'b' => '1_b', 
    758       'c' => '1_c', 
    759     )); 
    760     $this->getWidgetSchema()->setHelps(array( 
    761       'a' => '1_a', 
    762       'b' => '1_b', 
    763       'c' => '1_c', 
    764     )); 
    765   } 
    766 } 
    767  
    768 class TestForm2 extends FormTest 
    769 { 
    770   public function configure() 
    771   { 
    772     $this->disableCSRFProtection(); 
    773     $this->setWidgets(array( 
    774       'c' => new sfWidgetFormTextarea(), 
    775       'd' => new sfWidgetFormTextarea(), 
    776     )); 
    777     $this->setValidators(array( 
    778       'c' => new sfValidatorPass(), 
    779       'd' => new sfValidatorString(array('max_length' => 5)), 
    780     )); 
    781     $this->getWidgetSchema()->setLabels(array( 
    782       'c' => '2_c', 
    783       'd' => '2_d', 
    784     )); 
    785     $this->getWidgetSchema()->setHelps(array( 
    786       'c' => '2_c', 
    787       'd' => '2_d', 
    788     )); 
    789     $this->validatorSchema->setPreValidator(new sfValidatorPass()); 
    790     $this->validatorSchema->setPostValidator(new sfValidatorPass()); 
    791   } 
    792 } 
    793  
    794801$f1 = new TestForm1(); 
    795802$f2 = new TestForm2(); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.