ENHANCEMENT Added renameField() to FieldSet

MINOR Added test for FieldSet->renameField() to test method behaviour

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@69244 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2008-12-16 21:11:45 +00:00 committed by Sam Minnee
parent e24c5801d3
commit c5ab033cdd
2 changed files with 34 additions and 0 deletions

View File

@ -201,6 +201,22 @@ class FieldSet extends DataObjectSet {
return false;
}
/**
* Rename the title of a particular field name in this set.
*
* @param string $fieldName Name of field to rename title of
* @param string $newFieldTitle New title of field
* @return boolean
*/
function renameField($fieldName, $newFieldTitle) {
$field = $this->dataFieldByName($fieldName);
if(!$field) return false;
$field->setTitle($newFieldTitle);
return $field->Title() == $newFieldTitle;
}
/**
* @return boolean
*/

View File

@ -166,6 +166,24 @@ class FieldSetTest extends SapphireTest {
/* We have 1 field inside our tab */
$this->assertEquals(1, $tab->Fields()->Count());
}
function testRenameField() {
$fields = new FieldSet();
$nameField = new TextField('Name', 'Before title');
$fields->push($nameField);
/* The title of the field object is the same as what we put in */
$this->assertSame('Before title', $nameField->Title());
/* The field gets renamed to a different title */
$fields->renameField('Name', 'After title');
/* The title of the field object is the title we renamed to, this
includes the original object we created ($nameField), and getting
the field back out of the set */
$this->assertSame('After title', $nameField->Title());
$this->assertSame('After title', $fields->dataFieldByName('Name')->Title());
}
function testReplaceAFieldInADifferentTab() {
/* A FieldSet gets created with a TabSet and some field objects */