More comprehensive UploadField test cases

This commit is contained in:
Ingo Schommer 2013-05-29 17:26:11 +02:00
parent 2ddb78e6f4
commit 2bd2d5f844
5 changed files with 36 additions and 3 deletions

View File

@ -3,6 +3,7 @@
Member::add_extension('FrameworkTestRole');
Member::add_extension('FileUploadRole');
SiteTree::add_extension('FrameworkTestSiteTreeExtension');
File::add_extension('FrameworkTestFileExtension');
if(class_exists('SiteTreeCMSWorkflow')) {
SiteConfig::add_extension('CMSWorkflowSiteConfigDecorator');

View File

@ -155,9 +155,10 @@ class BasicFieldsTestPage extends TestPage {
$dateTimeShowCalendar->getTimeField()->setConfig('showdropdown', true);
$fields->addFieldsToTab('Root.File', array(
UploadField::create('File','FileUploadField')
$bla = UploadField::create('File','FileUploadField')
->setDescription($description)
->setConfig('allowedMaxFileNumber', 1),
->setConfig('allowedMaxFileNumber', 1)
->setConfig('canPreviewFolder', false),
UploadField::create('AttachedFile','UploadField with canUpload=false')
->setDescription($description)
->setConfig('canUpload', false),

View File

@ -19,7 +19,8 @@ class Company extends DataObject {
);
private static $has_many = array(
'Employees' => 'Employee'
'Employees' => 'Employee',
'GroupPhotos' => 'Image'
);
private static $many_many = array(
@ -54,6 +55,18 @@ class Company extends DataObject {
'CEO',
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main',
$uploadField = UploadField::create('GroupPhotos')
);
if(method_exists('UploadField', 'setAllowedFileCategories')) {
$uploadField->setAllowedFileCategories('image');
}
return $fields;
}
function validate() {
if(!$this->Title) {
return new ValidationResult(false, 'Title is required');

View File

@ -32,6 +32,12 @@ class Employee extends DataObject {
);
}
// 3.1 only
if(method_exists('UploadField', 'setAllowedFileCategories')) {
$fields->dataFieldByName('ProfileImage')->setAllowedFileCategories('image');
}
return $fields;
}
@ -50,6 +56,12 @@ class Employee extends DataObject {
DB::alteration_message("Added default records to Employee table","created");
}
public function validate() {
$result = parent::validate();
if(!$this->Name) $result->error('"Name" can\'t be blank');
return $result;
}
/**
* Contains test data
*

View File

@ -0,0 +1,6 @@
<?php
class FrameworkTestFileExtension extends DataExtension {
static $has_one = array(
'Company' => 'Company'
);
}