mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
More comprehensive UploadField test cases
This commit is contained in:
parent
2ddb78e6f4
commit
2bd2d5f844
@ -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');
|
||||
|
@ -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),
|
||||
|
@ -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');
|
||||
|
@ -32,6 +32,12 @@ class Employee extends DataObject {
|
||||
);
|
||||
}
|
||||
|
||||
// 3.1 only
|
||||
if(method_exists('UploadField', 'setAllowedFileCategories')) {
|
||||
$fields->dataFieldByName('ProfileImage')->setAllowedFileCategories('image');
|
||||
}
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@ -49,6 +55,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
|
||||
|
6
code/FrameworkTestFileExtension.php
Normal file
6
code/FrameworkTestFileExtension.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class FrameworkTestFileExtension extends DataExtension {
|
||||
static $has_one = array(
|
||||
'Company' => 'Company'
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user