/**
  * Tests the TextField Max Length Validation Success
  */
 public function testMaxLengthValidationSuccess()
 {
     $textField = new TextField('TestField');
     $textField->setMaxLength(5);
     $textField->setValue("John");
     // 4 characters, so should pass
     $result = $textField->validate(new RequiredFields());
     $this->assertTrue($result);
 }
 public function testLoadDataFromClearMissingFields()
 {
     $form = new Form(new Controller(), 'Form', new FieldList(new HeaderField('MyPlayerHeader', 'My Player'), new TextField('Name'), new TextareaField('Biography'), new DateField('Birthday'), new NumericField('BirthdayYear'), $unrelatedField = new TextField('UnrelatedFormField')), new FieldList());
     $unrelatedField->setValue("random value");
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
     $captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $form->loadDataFrom($captainWithDetails);
     $this->assertEquals($form->getData(), array('Name' => 'Captain Details', 'Biography' => 'Bio 1', 'Birthday' => '1982-01-01', 'BirthdayYear' => '1982', 'UnrelatedFormField' => 'random value'), 'LoadDataFrom() doesnt overwrite fields not found in the object');
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $team2 = $this->objFromFixture('FormTest_Team', 'team2');
     $form->loadDataFrom($captainWithDetails);
     $form->loadDataFrom($team2, Form::MERGE_CLEAR_MISSING);
     $this->assertEquals($form->getData(), array('Name' => 'Team 2', 'Biography' => '', 'Birthday' => '', 'BirthdayYear' => 0, 'UnrelatedFormField' => null), 'LoadDataFrom() overwrites fields not found in the object with $clearMissingFields=true');
 }