Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit a0d583291cce28a472f9f0dcd98d03fc085e3944 1 parent f75537b
Ingo Schommer chillu authored
5 forms/UploadField.php
View
@@ -501,9 +501,8 @@ public function managesRelation() {
$record = $this->getRecord();
$fieldName = $this->getName();
return (
- $record->has_one($fieldName)
- || $record->has_many($fieldName)
- || $record->many_many($fieldName)
+ $record
+ && ($record->has_one($fieldName) || $record->has_many($fieldName) || $record->many_many($fieldName))
);
}
23 tests/forms/uploadfield/UploadFieldTest.php
View
@@ -375,6 +375,29 @@ function testDisabled() {
}
+ 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() {
return new Form(new Controller(), 'Form', new FieldList(), new FieldList());
}
Please sign in to comment.
Something went wrong with that request. Please try again.