MINOR Fixed UploadField->managesRelation() when no record is set

This commit is contained in:
Ingo Schommer 2012-02-08 11:27:10 +01:00
parent f75537b589
commit a0d583291c
2 changed files with 25 additions and 3 deletions

View File

@ -501,9 +501,8 @@ class UploadField extends FileField {
$record = $this->getRecord(); $record = $this->getRecord();
$fieldName = $this->getName(); $fieldName = $this->getName();
return ( return (
$record->has_one($fieldName) $record
|| $record->has_many($fieldName) && ($record->has_one($fieldName) || $record->has_many($fieldName) || $record->many_many($fieldName))
|| $record->many_many($fieldName)
); );
} }

View File

@ -375,6 +375,29 @@
} }
function testManagesRelation() {
$record = $this->objFromFixture('UploadFieldTest_Record', 'record1');
$field = new UploadField('ManyManyFiles');
$this->assertFalse($field->managesRelation(), 'False if no record is set');
$field = new UploadField('NoRelationField');
$field->setRecord($record);
$this->assertFalse($field->managesRelation(), 'False if no relation found by name');
$field = new UploadField('HasOneFile');
$field->setRecord($record);
$this->assertTrue($field->managesRelation(), 'True for has_one');
$field = new UploadField('HasManyFiles');
$field->setRecord($record);
$this->assertTrue($field->managesRelation(), 'True for has_many');
$field = new UploadField('ManyManyFiles');
$field->setRecord($record);
$this->assertTrue($field->managesRelation(), 'True for many_many');
}
protected function getMockForm() { protected function getMockForm() {
return new Form(new Controller(), 'Form', new FieldList(), new FieldList()); return new Form(new Controller(), 'Form', new FieldList(), new FieldList());
} }