mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
Added more fields. Needs to be tidied.
This commit is contained in:
commit
236711fe4d
0
_config.php
Normal file
0
_config.php
Normal file
117
code/BasicFieldsTestPage.php
Normal file
117
code/BasicFieldsTestPage.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
class BasicFieldsTestPage extends TestPage {
|
||||
static $db = array(
|
||||
'Checkbox' => 'Boolean',
|
||||
'Readonly' => 'Varchar',
|
||||
'Textarea' => 'Text',
|
||||
'Text' => 'Varchar',
|
||||
'CalendarDate' => 'Date',
|
||||
'CompositeDate' => 'Date',
|
||||
'Date' => 'Date',
|
||||
'DMYCalendarDate' => 'Date',
|
||||
'DMYDate' => 'Date',
|
||||
'DropdownTime' => 'Time',
|
||||
'PopupDateTime' => 'Datetime',
|
||||
'Time' => 'Time',
|
||||
'Number' => 'Int',
|
||||
'Price' => 'Double',
|
||||
'Email' => 'Varchar',
|
||||
'Password' => 'Varchar',
|
||||
'ConfirmedPassword' => 'Varchar',
|
||||
'HTMLField' => 'HTMLText',
|
||||
'HTMLOneLine' => 'HTMLVarchar',
|
||||
'UniqueText' => 'Varchar',
|
||||
'AjaxUniqueText' => 'Varchar',
|
||||
'UniqueRestrictedText' => 'Varchar',
|
||||
'BankNumber' => 'Varchar',
|
||||
'PhoneNumber' => 'Varchar',
|
||||
'Autocomplete' => 'Varchar',
|
||||
'CreditCard' => 'Varchar',
|
||||
'GSTNumber' => 'Varchar',
|
||||
);
|
||||
|
||||
static $has_one = array(
|
||||
'Dropdown' => 'TestCategory',
|
||||
'OptionSet' => 'TestCategory',
|
||||
'GroupedDropdown' => 'TestCategory',
|
||||
'ListboxField' => 'TestCategory',
|
||||
'Image' => 'Image',
|
||||
'Image2' => 'Image',
|
||||
'Image3' => 'Image',
|
||||
'File' => 'File',
|
||||
'File2' => 'File',
|
||||
'File3' => 'File',
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
'Readonly' => 'Default value for \'readonly\'',
|
||||
);
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
// TODO: Tidy these up
|
||||
$fields->addFieldsToTab('Root.Content.BasicTests', array(
|
||||
new CheckboxField('Checkbox', 'CheckboxField'),
|
||||
new DropdownField('DropdownID', 'DropdownField', TestCategory::map()),
|
||||
new GroupedDropdownField('GroupedDropdownID', 'GroupedDropdown', array('Test Categorys' => TestCategory::map())),
|
||||
new ListboxField('ListboxFieldID', 'ListboxField', TestCategory::map(), array(), 3),
|
||||
new OptionsetField('OptionSetID', 'OptionSetField', TestCategory::map()),
|
||||
new ReadonlyField('Readonly', 'ReadonlyField'),
|
||||
new TextareaField('Textarea', 'TextareaField - 8 rows', 8),
|
||||
new TextField('Text', 'TextField'),
|
||||
new NumericField('Number', 'NumericField'),
|
||||
new CurrencyField('Price', 'CurrencyField'),
|
||||
new EmailField('Email', 'EmailField'),
|
||||
new PasswordField('Password', 'PasswordField'),
|
||||
new ConfirmedPasswordField('ConfirmedPassword', 'ConfirmedPasswordField'),
|
||||
new HtmlEditorField('HTMLField', 'HtmlEditorField'),
|
||||
new HtmlOneLineField('HTMLOneLine', 'HTMLOneLineField'),
|
||||
new UniqueTextField('UniqueText', 'UniqueText', 'BasicFieldsTestPage', 'This field must be unique.', 'UniqueTextField'),
|
||||
new UniqueRestrictedTextField('UniqueRestrictedText', 'UniqueRestrictedText', 'BasicFieldsTestPage', 'This field must be unique for each page',
|
||||
'[^A-Za-z0-9-]+', '-', 'This field can only be made up of letters, digits and hyphens.',
|
||||
'UniqueRestrictedTextField'),
|
||||
new BankAccountField('BankNumber', 'BankAccountField'),
|
||||
new PhoneNumberField('PhoneNumber', 'PhoneNumberField'),
|
||||
new AjaxUniqueTextField('AjaxUniqueText', 'AjaxUniqueTextField', 'AjaxjUniqueText', 'BasicFieldsTestPage'),
|
||||
// new AutocompleteTextField('Autocomplete', 'AutocompleteTextField', Director::absoluteURL('BasicFieldsTestPage_Controller/AutoCompleteItems')), // Um, how does this work?
|
||||
new CreditCardField('CreditCard', 'CreditCardField'),
|
||||
new GSTNumberField('GSTNumber', 'GSTNumberField'),
|
||||
));
|
||||
|
||||
$fields->addFieldsToTab('Root.Content.DateTimeTests', array(
|
||||
new CalendarDateField('CalendarDate','CalendarDateField'),
|
||||
new CompositeDateField('CompositeDate','CompsiteDateField'),
|
||||
new DateField('Date','DateField'),
|
||||
new DMYCalendarDateField('DMYCalendarDate','DMYCalendarDateField'),
|
||||
new DMYDateField('DMYDate','DMYDateField'),
|
||||
new DropdownTimeField('DropdownTime','DropdownTimeField'),
|
||||
new PopupDateTimeField('PopupDateTime','PopupDateTimeField'),
|
||||
new TimeField('Time','TimeField')
|
||||
));
|
||||
|
||||
$fields->addFieldsToTab('Root.Content.FileTests', array(
|
||||
new ImageField('Image','ImageField'),
|
||||
new SimpleImageField('Image2','SimpleImageField'),
|
||||
new ImageField('Image3','ImageField'),
|
||||
new FileIFrameField('File','FileIFrameField'),
|
||||
new FileField('File2','FileField'),
|
||||
new FileIFrameField('File3','FileIFrameField'),
|
||||
));
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
|
||||
class BasicFieldsTestPage_Controller extends TestPage_Controller {
|
||||
function AutoCompleteItems() {
|
||||
$items = array(
|
||||
'TestItem1',
|
||||
'TestItem2',
|
||||
'TestItem3',
|
||||
'TestItem4',
|
||||
);
|
||||
return implode(',', $items);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
34
code/RelationFieldsTestPage.php
Normal file
34
code/RelationFieldsTestPage.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class RelationFieldsTestPage extends TestPage {
|
||||
static $many_many = array(
|
||||
"CheckboxSet" => "TestCategory",
|
||||
);
|
||||
static $has_may = array(
|
||||
"Items" => "TestCTFItem",
|
||||
);
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->addFieldToTab("Root.Content.CheckboxSet",
|
||||
new CheckboxSetField("CheckboxSet", "CheckboxSetField", TestCategory::map()));
|
||||
|
||||
$fields->addFieldToTab("Root.Content.ComplexTableField",
|
||||
new ComplexTableField($this, "Items", "TestCTFItem", array(
|
||||
"Title" => "Item Title",
|
||||
"Author" => "Item Author")));
|
||||
|
||||
// $fields->addFieldToTab("Root.Tests.ComplexTableField",
|
||||
// new CheckboxSetField("CheckboxSet", "CheckboxSetField", TestCategory::map()));
|
||||
// $fields->addFieldToTab("Root.Tests.CheckboxSet", new CheckboxSetField("CheckboxSet", "CheckboxSetField", TestCategory::map()));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
|
||||
class RelationFieldsTestPage_Controller extends TestPage_Controller {
|
||||
|
||||
}
|
||||
|
||||
?>
|
25
code/TestCTFItem.php
Normal file
25
code/TestCTFItem.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A data type that is related 1-many to RelationFieldsTestPage, for testing purposes
|
||||
*/
|
||||
class TestCTFItem extends DataObject {
|
||||
static $db = array(
|
||||
"Title" => "Varchar",
|
||||
"Author" => "Varchar",
|
||||
"Description" => "Text",
|
||||
);
|
||||
static $has_one = array(
|
||||
"Parent" => "RelationFieldsTestPage",
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns a dropdown map of all objects of this class
|
||||
*/
|
||||
static function map() {
|
||||
return DataObject::get('TestCategory')->toDropdownMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
34
code/TestCategory.php
Normal file
34
code/TestCategory.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A data type that is related many-many to RelationFieldsTestPage, for testing purposes
|
||||
*/
|
||||
class TestCategory extends DataObject {
|
||||
static $db = array(
|
||||
"Title" => "Varchar",
|
||||
);
|
||||
static $belongs_many_many = array(
|
||||
"RelationPages" => "RelationFieldsTestPage",
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns a dropdown map of all objects of this class
|
||||
*/
|
||||
static function map() {
|
||||
return DataObject::get('TestCategory')->toDropdownMap();
|
||||
}
|
||||
|
||||
function requireDefaultRecords(){
|
||||
$class = $this->class;
|
||||
if(!DataObject::get_one($class)) {
|
||||
foreach(array("A","B","C","D") as $item) {
|
||||
$page = new $class();
|
||||
$page->Title = "Test Category $item";
|
||||
$page->write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
36
code/TestPage.php
Normal file
36
code/TestPage.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Parent class of all test pages
|
||||
*/
|
||||
class TestPage extends Page {
|
||||
|
||||
/**
|
||||
* We can only create subclasses of TestPage
|
||||
*/
|
||||
function canCreate() {
|
||||
return $this->class != 'TestPage' && parent::canCreate();
|
||||
}
|
||||
|
||||
function requireDefaultRecords(){
|
||||
if($this->class == 'TestPage') return;
|
||||
|
||||
$class = $this->class;
|
||||
if(!DataObject::get_one($class)) {
|
||||
$page = new $class();
|
||||
$page->Title = str_replace("TestPage","",$class) . " Test";
|
||||
$page->write();
|
||||
Debug::show($page);
|
||||
$page->doPublish();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parent class of all test page controllers
|
||||
*/
|
||||
class TestPage_Controller extends Page_Controller {
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user