Changeset 7051
- Timestamp:
- 01/14/08 15:57:32 (10 months ago)
- Files:
-
- branches/1.1/lib/form/sfForm.class.php (modified) (1 diff)
- branches/1.1/lib/validator/sfValidatorSchema.class.php (modified) (1 diff)
- branches/1.1/lib/widget/sfWidgetFormSchema.class.php (modified) (1 diff)
- branches/1.1/test/unit/form/sfFormTest.php (modified) (4 diffs)
- branches/1.1/test/unit/validator/sfValidatorSchemaTest.php (modified) (2 diffs)
- branches/1.1/test/unit/widget/sfWidgetFormSchemaDecoratorTest.php (modified) (2 diffs)
- branches/1.1/test/unit/widget/sfWidgetFormSchemaTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/form/sfForm.class.php
r7047 r7051 735 735 return $str; 736 736 } 737 738 public function __clone() 739 { 740 $this->widgetSchema = clone $this->widgetSchema; 741 $this->validatorSchema = clone $this->validatorSchema; 742 743 // we rebind the cloned form because Exceptions are not clonable 744 $this->bind($this->taintedValues, $this->taintedFiles); 745 } 737 746 } branches/1.1/lib/validator/sfValidatorSchema.class.php
r6991 r7051 345 345 throw new Exception('Unable to convert a sfValidatorSchema to string.'); 346 346 } 347 348 public function __clone() 349 { 350 foreach ($this->fields as $name => $field) 351 { 352 $this->fields[$name] = clone $field; 353 } 354 } 347 355 } branches/1.1/lib/widget/sfWidgetFormSchema.class.php
r6220 r7051 591 591 } 592 592 } 593 594 public function __clone() 595 { 596 foreach ($this->fields as $name => $field) 597 { 598 $this->fields[$name] = clone $field; 599 } 600 } 593 601 } branches/1.1/test/unit/form/sfFormTest.php
r6969 r7051 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 76, new lime_output_color());13 $t = new lime_test(82, new lime_output_color()); 14 14 15 15 class FormTest extends sfForm … … 240 240 $d = $article->getDefaults(); 241 241 242 $t-> is($v['author']['first_name'],$author_validator_schema['first_name'], '->embedForm() embeds the validator schema');243 $t-> is($w['author']['first_name'],$author_widget_schema['first_name'], '->embedForm() embeds the widget schema');242 $t->ok($v['author']['first_name'] == $author_validator_schema['first_name'], '->embedForm() embeds the validator schema'); 243 $t->ok($w['author']['first_name'] == $author_widget_schema['first_name'], '->embedForm() embeds the widget schema'); 244 244 $t->is($d['author']['first_name'], 'Fabien', '->embedForm() merges default values from the embedded form'); 245 245 $t->is($v['author'][sfForm::getCSRFFieldName()], null, '->embedForm() removes the CSRF token for the embedded form'); … … 255 255 for ($i = 0; $i < 2; $i++) 256 256 { 257 $t-> is($v['authors'][$i]['first_name'],$author_validator_schema['first_name'], '->embedFormForEach() embeds the validator schema');258 $t-> is($w['authors'][$i]['first_name'],$author_widget_schema['first_name'], '->embedFormForEach() embeds the widget schema');257 $t->ok($v['authors'][$i]['first_name'] == $author_validator_schema['first_name'], '->embedFormForEach() embeds the validator schema'); 258 $t->ok($w['authors'][$i]['first_name'] == $author_widget_schema['first_name'], '->embedFormForEach() embeds the widget schema'); 259 259 $t->is($d['authors'][$i]['first_name'], 'Fabien', '->embedFormForEach() merges default values from the embedded forms'); 260 260 $t->is($v['authors'][$i][sfForm::getCSRFFieldName()], null, '->embedFormForEach() removes the CSRF token for the embedded forms'); … … 424 424 $t->is_deeply(sfForm::convertFileInformation($input), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention'); 425 425 $t->is_deeply(sfForm::convertFileInformation($expected), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention'); 426 427 // __clone() 428 $t->diag('__clone()'); 429 $a = new FormTest(); 430 $a->setValidatorSchema(new sfValidatorSchema(array( 431 'first_name' => new sfValidatorString(array('min_length' => 2)), 432 ))); 433 $a->bind(array('first_name' => 'F')); 434 $a1 = clone $a; 435 436 $t->ok($a1->getValidatorSchema() !== $a->getValidatorSchema(), '__clone() clones the validator schema'); 437 $t->ok($a1->getValidatorSchema() == $a->getValidatorSchema(), '__clone() clones the validator schema'); 438 439 $t->ok($a1->getWidgetSchema() !== $a->getWidgetSchema(), '__clone() clones the widget schema'); 440 $t->ok($a1->getWidgetSchema() == $a->getWidgetSchema(), '__clone() clones the widget schema'); 441 442 $t->ok($a1->getErrorSchema() !== $a->getErrorSchema(), '__clone() clones the error schema'); 443 $t->ok($a1->getErrorSchema()->getMessage() == $a->getErrorSchema()->getMessage(), '__clone() clones the error schema'); branches/1.1/test/unit/validator/sfValidatorSchemaTest.php
r6963 r7051 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(7 3, new lime_output_color());13 $t = new lime_test(78, new lime_output_color()); 14 14 15 15 class PreValidator extends sfValidator … … 368 368 $t->is($e->getCode(), 'invalid user [invalid password [invalid]] password [invalid]', '->clean() throws an exception with all error messages'); 369 369 } 370 371 // __clone() 372 $t->diag('__clone()'); 373 $v = new sfValidatorSchema(array('v1' => $v1, 'v2' => $v2)); 374 $v1 = clone $v; 375 $f1 = $v1->getFields(); 376 $f = $v->getFields(); 377 $t->is(array_keys($f1), array_keys($f), '__clone() clones embedded validators'); 378 foreach ($f1 as $name => $validator) 379 { 380 $t->ok($validator !== $f[$name], '__clone() clones embedded validators'); 381 $t->ok($validator == $f[$name], '__clone() clones embedded validators'); 382 } branches/1.1/test/unit/widget/sfWidgetFormSchemaDecoratorTest.php
r7049 r7051 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(1 6, new lime_output_color());13 $t = new lime_test(17, new lime_output_color()); 14 14 15 15 $w1 = new sfWidgetFormInput(); … … 72 72 $w1 = clone $w; 73 73 $t->ok($w1->getWidget() !== $w->getWidget(), '__clone() clones the embedded widget'); 74 $t->ok($w1->getWidget() == $w->getWidget(), '__clone() clones the embedded widget'); branches/1.1/test/unit/widget/sfWidgetFormSchemaTest.php
r6197 r7051 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(5 0, new lime_output_color());13 $t = new lime_test(55, new lime_output_color()); 14 14 15 15 $w1 = new sfWidgetFormInput(array(), array('class' => 'foo1')); … … 270 270 $rendered = $w->render(null, array('w1' => 'Fabien', 'w2' => 'Potencier'), array(), array('first_name' => 'Too short', 'Global error message', 'id' => 'Required')); 271 271 $t->is($rendered, $expected, '->render() renders a schema to HTML'); 272 273 // __clone() 274 $t->diag('__clone()'); 275 $w = new sfWidgetFormSchema(array('w1' => $w1, 'w2' => $w2)); 276 $w1 = clone $w; 277 $f1 = $w1->getFields(); 278 $f = $w->getFields(); 279 $t->is(array_keys($f1), array_keys($f), '__clone() clones embedded widgets'); 280 foreach ($f1 as $name => $widget) 281 { 282 $t->ok($widget !== $f[$name], '__clone() clones embedded widgets'); 283 $t->ok($widget == $f[$name], '__clone() clones embedded widgets'); 284 }