mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Adjusted FormTest->testLoadDataFromObject() to new assumptions about changed behaviour on loadDataFrom() from $loadBlanks to $clearMissingFields - which means that form fields are cleared regardless if they have blank values in the passed object or not
ENHANCEMENT Added FormTest->loadDataFromClearMissingFields() ENHANCEMENT Made FormTest fixtures more expressive git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64001 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
5f50fee5e9
commit
2fbed5b2e1
@ -82,17 +82,16 @@ class FormTest extends FunctionalTest {
|
|||||||
new TextareaField('Biography'),
|
new TextareaField('Biography'),
|
||||||
new DateField('Birthday'),
|
new DateField('Birthday'),
|
||||||
new NumericField('BirthdayYear') // dynamic property
|
new NumericField('BirthdayYear') // dynamic property
|
||||||
//new CheckboxSetField('Teams') // relation editing
|
|
||||||
),
|
),
|
||||||
new FieldSet()
|
new FieldSet()
|
||||||
);
|
);
|
||||||
|
|
||||||
$captain1 = $this->objFromFixture('FormTest_Player', 'captain1');
|
$captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
|
||||||
$form->loadDataFrom($captain1);
|
$form->loadDataFrom($captainWithDetails);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$form->getData(),
|
$form->getData(),
|
||||||
array(
|
array(
|
||||||
'Name' => 'Captain 1',
|
'Name' => 'Captain Details',
|
||||||
'Biography' => 'Bio 1',
|
'Biography' => 'Bio 1',
|
||||||
'Birthday' => '1982-01-01',
|
'Birthday' => '1982-01-01',
|
||||||
'BirthdayYear' => '1982',
|
'BirthdayYear' => '1982',
|
||||||
@ -100,30 +99,66 @@ class FormTest extends FunctionalTest {
|
|||||||
'LoadDataFrom() loads simple fields and dynamic getters'
|
'LoadDataFrom() loads simple fields and dynamic getters'
|
||||||
);
|
);
|
||||||
|
|
||||||
$captain2 = $this->objFromFixture('FormTest_Player', 'captain2');
|
$captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
|
||||||
$form->loadDataFrom($captain2);
|
$form->loadDataFrom($captainNoDetails);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$form->getData(),
|
$form->getData(),
|
||||||
array(
|
array(
|
||||||
'Name' => 'Captain 2',
|
'Name' => 'Captain No Details',
|
||||||
'Biography' => 'Bio 1',
|
'Biography' => null,
|
||||||
'Birthday' => '1982-01-01',
|
'Birthday' => null,
|
||||||
'BirthdayYear' => '1982',
|
'BirthdayYear' => 0,
|
||||||
),
|
),
|
||||||
'LoadNonBlankDataFrom() loads only fields with values, and doesnt overwrite existing values'
|
'LoadNonBlankDataFrom() loads only fields with values, and doesnt overwrite existing values'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadDataFromClearMissingFields() {
|
||||||
|
$form = new Form(
|
||||||
|
new Controller(),
|
||||||
|
'Form',
|
||||||
|
new FieldSet(
|
||||||
|
new HeaderField('My Player'),
|
||||||
|
new TextField('Name'), // appears in both Player and Team
|
||||||
|
new TextareaField('Biography'),
|
||||||
|
new DateField('Birthday'),
|
||||||
|
new NumericField('BirthdayYear'), // dynamic property
|
||||||
|
$unrelatedField = new TextField('UnrelatedFormField')
|
||||||
|
//new CheckboxSetField('Teams') // relation editing
|
||||||
|
),
|
||||||
|
new FieldSet()
|
||||||
|
);
|
||||||
|
$unrelatedField->setValue("random value");
|
||||||
|
|
||||||
$captain2 = $this->objFromFixture('FormTest_Player', 'captain2');
|
$captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
|
||||||
$form->loadDataFrom($captain2, true);
|
$captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
|
||||||
|
$form->loadDataFrom($captainWithDetails);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$form->getData(),
|
$form->getData(),
|
||||||
array(
|
array(
|
||||||
'Name' => 'Captain 2',
|
'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, true);
|
||||||
|
$this->assertEquals(
|
||||||
|
$form->getData(),
|
||||||
|
array(
|
||||||
|
'Name' => 'Team 2',
|
||||||
'Biography' => '',
|
'Biography' => '',
|
||||||
'Birthday' => '',
|
'Birthday' => '',
|
||||||
'BirthdayYear' => 0,
|
'BirthdayYear' => 0,
|
||||||
|
'UnrelatedFormField' => null,
|
||||||
),
|
),
|
||||||
'LoadDataFrom() overwrites existing with blank values on subsequent calls'
|
'LoadDataFrom() overwrites fields not found in the object with $clearMissingFields=true'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,14 +4,14 @@ FormTest_Team:
|
|||||||
team2:
|
team2:
|
||||||
Name: Team 2
|
Name: Team 2
|
||||||
FormTest_Player:
|
FormTest_Player:
|
||||||
captain1:
|
captainWithDetails:
|
||||||
Name: Captain 1
|
Name: Captain Details
|
||||||
Birthday: 1982-01-01
|
Birthday: 1982-01-01
|
||||||
Biography: Bio 1
|
Biography: Bio 1
|
||||||
FavouriteTeam: =>FormTest_Team.team1
|
FavouriteTeam: =>FormTest_Team.team1
|
||||||
Teams: =>FormTest_Team.team1
|
Teams: =>FormTest_Team.team1
|
||||||
captain2:
|
captainNoDetails:
|
||||||
Name: Captain 2
|
Name: Captain No Details
|
||||||
Teams: =>FormTest_Team.team2
|
Teams: =>FormTest_Team.team2
|
||||||
player1:
|
player1:
|
||||||
Name: Player 1
|
Name: Player 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user