mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
Merge pull request #16 from open-sausages/pulls/namespace-model
Namespaced model to get more 4.x test coverage
This commit is contained in:
commit
f03b0ab6c9
6
.upgrade.yml
Normal file
6
.upgrade.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
mappings:
|
||||||
|
TestCategory: SilverStripe\FrameworkTest\Model\TestCategory
|
||||||
|
Company: SilverStripe\FrameworkTest\Model\Company
|
||||||
|
Employee: SilverStripe\FrameworkTest\Model\Employee
|
||||||
|
TestPage: SilverStripe\FrameworkTest\Model\TestPage
|
||||||
|
TestPage_Controller: SilverStripe\FrameworkTest\Model\TestPage_Controller
|
@ -1,5 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestCategory;
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestPage;
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestPage_Controller;
|
||||||
|
|
||||||
class BasicFieldsTestPage extends TestPage
|
class BasicFieldsTestPage extends TestPage
|
||||||
{
|
{
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
@ -39,8 +44,8 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
);
|
);
|
||||||
|
|
||||||
private static $has_one = array(
|
private static $has_one = array(
|
||||||
'Dropdown' => 'TestCategory',
|
'Dropdown' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
|
||||||
'GroupedDropdown' => 'TestCategory',
|
'GroupedDropdown' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
|
||||||
'File' => 'File',
|
'File' => 'File',
|
||||||
'AttachedFile' => 'File',
|
'AttachedFile' => 'File',
|
||||||
'Image' => 'Image',
|
'Image' => 'Image',
|
||||||
@ -52,7 +57,7 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
|
|
||||||
private static $many_many = array(
|
private static $many_many = array(
|
||||||
'ManyManyFiles' => 'File',
|
'ManyManyFiles' => 'File',
|
||||||
'MultipleListboxField' => 'TestCategory',
|
'MultipleListboxField' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $defaults = array(
|
private static $defaults = array(
|
||||||
|
@ -1,8 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\FrameworkTest\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use UploadField;
|
||||||
|
|
||||||
|
|
||||||
|
use SilverStripe\ORM\ValidationResult;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Company extends DataObject
|
class Company extends DataObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static $table_name = 'Company';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
@ -20,12 +34,12 @@ class Company extends DataObject
|
|||||||
);
|
);
|
||||||
|
|
||||||
private static $has_many = array(
|
private static $has_many = array(
|
||||||
'Employees' => 'Employee',
|
'Employees' => 'SilverStripe\\FrameworkTest\\Model\\Employee',
|
||||||
'GroupPhotos' => 'Image'
|
'GroupPhotos' => 'Image'
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $many_many = array(
|
private static $many_many = array(
|
||||||
'PastEmployees' => 'Employee'
|
'PastEmployees' => 'SilverStripe\\FrameworkTest\\Model\\Employee'
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $many_many_extraFields = array(
|
private static $many_many_extraFields = array(
|
||||||
@ -86,7 +100,7 @@ class Company extends DataObject
|
|||||||
public function requireDefaultRecords()
|
public function requireDefaultRecords()
|
||||||
{
|
{
|
||||||
parent::requireDefaultRecords();
|
parent::requireDefaultRecords();
|
||||||
$companySet = DataObject::get('Company');
|
$companySet = DataObject::get('SilverStripe\\FrameworkTest\\Model\\Company');
|
||||||
foreach ($companySet as $company) {
|
foreach ($companySet as $company) {
|
||||||
$company->delete();
|
$company->delete();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\FrameworkTest\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use NumericField;
|
||||||
|
use TextField;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of Employees
|
* Description of Employees
|
||||||
*
|
*
|
||||||
@ -13,19 +24,19 @@ class Employee extends DataObject
|
|||||||
);
|
);
|
||||||
|
|
||||||
private static $has_one = array(
|
private static $has_one = array(
|
||||||
'Company' => 'Company',
|
'Company' => 'SilverStripe\\FrameworkTest\\Model\\Company',
|
||||||
'ProfileImage' => 'Image'
|
'ProfileImage' => 'Image'
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $belongs_many_many = array(
|
private static $belongs_many_many = array(
|
||||||
'PastCompanies' => 'Company'
|
'PastCompanies' => 'SilverStripe\\FrameworkTest\\Model\\Company'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function getCMSFields()
|
public function getCMSFields()
|
||||||
{
|
{
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
if (method_exists('ManyManyList', 'getExtraFields')) {
|
if (method_exists('SilverStripe\\ORM\\ManyManyList', 'getExtraFields')) {
|
||||||
$fields->addFieldToTab('Root.Main',
|
$fields->addFieldToTab('Root.Main',
|
||||||
new NumericField('ManyMany[YearStart]', 'Year started (3.1, many-many only)')
|
new NumericField('ManyMany[YearStart]', 'Year started (3.1, many-many only)')
|
||||||
);
|
);
|
||||||
@ -36,7 +47,7 @@ class Employee extends DataObject
|
|||||||
|
|
||||||
// 3.1 only
|
// 3.1 only
|
||||||
if (method_exists('UploadField', 'setAllowedFileCategories')) {
|
if (method_exists('UploadField', 'setAllowedFileCategories')) {
|
||||||
$fields->dataFieldByName('ProfileImage')->setAllowedFileCategories('image');
|
$fields->dataFieldByName('ProfileImageID')->setAllowedFileCategories('image');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -46,7 +57,7 @@ class Employee extends DataObject
|
|||||||
public function requireDefaultRecords()
|
public function requireDefaultRecords()
|
||||||
{
|
{
|
||||||
parent::requireDefaultRecords();
|
parent::requireDefaultRecords();
|
||||||
$employeeSet = DataObject::get('Employee');
|
$employeeSet = DataObject::get('SilverStripe\\FrameworkTest\\Model\\Employee');
|
||||||
foreach ($employeeSet as $employee) {
|
foreach ($employeeSet as $employee) {
|
||||||
$employee->delete();
|
$employee->delete();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataExtension;
|
||||||
class FileUploadRole extends DataExtension
|
class FileUploadRole extends DataExtension
|
||||||
{
|
{
|
||||||
private static $has_one = array(
|
private static $has_one = array(
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataExtension;
|
||||||
class FrameworkTestFileExtension extends DataExtension
|
class FrameworkTestFileExtension extends DataExtension
|
||||||
{
|
{
|
||||||
private static $has_one = array(
|
private static $has_one = array(
|
||||||
'Company' => 'Company',
|
'Company' => 'SilverStripe\\FrameworkTest\\Model\\Company',
|
||||||
'BasicFieldsTestPage' => 'BasicFieldsTestPage'
|
'BasicFieldsTestPage' => 'BasicFieldsTestPage'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\ORM\DataExtension;
|
||||||
|
|
||||||
class FrameworkTestRole extends DataExtension
|
class FrameworkTestRole extends DataExtension
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataExtension;
|
||||||
class FrameworkTestSiteTreeExtension extends DataExtension
|
class FrameworkTestSiteTreeExtension extends DataExtension
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataList;
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestPage;
|
||||||
class GridFieldTestPage extends TestPage
|
class GridFieldTestPage extends TestPage
|
||||||
{
|
{
|
||||||
|
|
||||||
private static $has_one = array(
|
private static $has_one = array(
|
||||||
"HasOneCompany" => "Company",
|
"HasOneCompany" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $has_many = array(
|
private static $has_many = array(
|
||||||
"HasManyCompanies" => "Company",
|
"HasManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $many_many = array(
|
private static $many_many = array(
|
||||||
"ManyManyCompanies" => "Company",
|
"ManyManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
||||||
);
|
);
|
||||||
|
|
||||||
public function getCMSFields()
|
public function getCMSFields()
|
||||||
@ -21,7 +24,7 @@ class GridFieldTestPage extends TestPage
|
|||||||
$grids = array();
|
$grids = array();
|
||||||
|
|
||||||
$config = new GridFieldConfig_RecordEditor();
|
$config = new GridFieldConfig_RecordEditor();
|
||||||
$grid = new GridField('Companies', 'Companies', new DataList('Company'), $config);
|
$grid = new GridField('Companies', 'Companies', new DataList('SilverStripe\\FrameworkTest\\Model\\Company'), $config);
|
||||||
$fields->addFieldToTab('Root.NoRelation', $grid);
|
$fields->addFieldToTab('Root.NoRelation', $grid);
|
||||||
$grids[] = $grid;
|
$grids[] = $grid;
|
||||||
|
|
||||||
@ -72,7 +75,7 @@ class GridFieldTestPage_Controller extends Page_Controller
|
|||||||
{
|
{
|
||||||
$config = new GridFieldConfig_RecordEditor();
|
$config = new GridFieldConfig_RecordEditor();
|
||||||
|
|
||||||
$grid = new GridField('Companies', 'Companies', new DataList('Company'), $config);
|
$grid = new GridField('Companies', 'Companies', new DataList('SilverStripe\\FrameworkTest\\Model\\Company'), $config);
|
||||||
return new Form($this, 'Form', new FieldList($grid), new FieldList());
|
return new Form($this, 'Form', new FieldList($grid), new FieldList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace SilverStripe\FrameworkTest\Model;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
class Organisation extends DataObject
|
class Organisation extends DataObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static $table_name = 'Organisation';
|
||||||
|
|
||||||
// Used to test the Multiform module
|
// Used to test the Multiform module
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
'OrganisationName' => 'Text'
|
'OrganisationName' => 'Text'
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestCategory;
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestPage;
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestPage_Controller;
|
||||||
|
|
||||||
class RelationFieldsTestPage extends TestPage
|
class RelationFieldsTestPage extends TestPage
|
||||||
{
|
{
|
||||||
|
|
||||||
private static $has_one = array(
|
private static $has_one = array(
|
||||||
"HasOneCompany" => "Company",
|
"HasOneCompany" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
||||||
"HasOnePage" => "SiteTree",
|
"HasOnePage" => "SiteTree",
|
||||||
"HasOnePageWithSearch" => "SiteTree",
|
"HasOnePageWithSearch" => "SiteTree",
|
||||||
);
|
);
|
||||||
private static $has_many = array(
|
private static $has_many = array(
|
||||||
"HasManyCompanies" => "Company",
|
"HasManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
||||||
"HasManyPages" => "SiteTree",
|
"HasManyPages" => "SiteTree",
|
||||||
);
|
);
|
||||||
private static $many_many = array(
|
private static $many_many = array(
|
||||||
"ManyManyCompanies" => "Company",
|
"ManyManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
|
||||||
"ManyManyPages" => "SiteTree",
|
"ManyManyPages" => "SiteTree",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\FrameworkTest\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A data type that is related many-many to RelationFieldsTestPage, for testing purposes
|
* A data type that is related many-many to RelationFieldsTestPage, for testing purposes
|
||||||
*/
|
*/
|
||||||
class TestCategory extends DataObject
|
class TestCategory extends DataObject
|
||||||
{
|
{
|
||||||
|
private static $table_name = 'TestCategory';
|
||||||
|
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
"Title" => "Varchar",
|
"Title" => "Varchar",
|
||||||
);
|
);
|
||||||
@ -17,7 +26,7 @@ class TestCategory extends DataObject
|
|||||||
*/
|
*/
|
||||||
public static function map()
|
public static function map()
|
||||||
{
|
{
|
||||||
$categories = DataObject::get('TestCategory');
|
$categories = DataObject::get('SilverStripe\\FrameworkTest\\Model\\TestCategory');
|
||||||
if ($categories) {
|
if ($categories) {
|
||||||
return $categories->map('ID', 'Title')->toArray();
|
return $categories->map('ID', 'Title')->toArray();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestPage;
|
||||||
|
use SilverStripe\FrameworkTest\Model\TestPage_Controller;
|
||||||
|
|
||||||
class TestFileUploadPage extends TestPage
|
class TestFileUploadPage extends TestPage
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ class TestModelAdmin extends ModelAdmin
|
|||||||
private static $menu_title = 'Test ModelAdmin';
|
private static $menu_title = 'Test ModelAdmin';
|
||||||
|
|
||||||
private static $managed_models = array(
|
private static $managed_models = array(
|
||||||
"Company",
|
"SilverStripe\\FrameworkTest\\Model\\Company",
|
||||||
"Employee",
|
"SilverStripe\\FrameworkTest\\Model\\Employee",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\FrameworkTest\Model;
|
||||||
|
|
||||||
|
use Page;
|
||||||
|
|
||||||
|
use SiteTree;
|
||||||
|
use Page_Controller;
|
||||||
|
use FieldList;
|
||||||
|
use FormAction;
|
||||||
|
use Form;
|
||||||
|
use TextField;
|
||||||
|
use Email;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent class of all test pages
|
* Parent class of all test pages
|
||||||
*/
|
*/
|
||||||
@ -17,7 +32,7 @@ class TestPage extends Page
|
|||||||
|
|
||||||
public function requireDefaultRecords()
|
public function requireDefaultRecords()
|
||||||
{
|
{
|
||||||
if ($this->class == 'TestPage') {
|
if ($this->class == 'SilverStripe\\FrameworkTest\\Model\\TestPage') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +55,7 @@ class TestPage extends Page
|
|||||||
|
|
||||||
// Create actual page
|
// Create actual page
|
||||||
$page = new $class();
|
$page = new $class();
|
||||||
$page->Title = str_replace("TestPage", "", $class);
|
$page->Title = str_replace("SilverStripe\\FrameworkTest\\Model\\TestPage", "", $class);
|
||||||
$page->ShowInMenus = 0;
|
$page->ShowInMenus = 0;
|
||||||
if ($parent) {
|
if ($parent) {
|
||||||
$page->ParentID = $parent->ID;
|
$page->ParentID = $parent->ID;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
class Page2MultiForm extends MultiForm
|
class Page2MultiForm extends MultiForm
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
class Page3MultiForm extends MultiForm
|
class Page3MultiForm extends MultiForm
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user