Namespaced model to get more 4.x test coverage

This commit is contained in:
Ingo Schommer 2016-07-01 14:37:50 +12:00
parent d66b64d1fa
commit 8f315e7962
17 changed files with 123 additions and 34 deletions

6
.upgrade.yml Normal file
View 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

View File

@ -1,5 +1,10 @@
<?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
{
private static $db = array(
@ -39,8 +44,8 @@ class BasicFieldsTestPage extends TestPage
);
private static $has_one = array(
'Dropdown' => 'TestCategory',
'GroupedDropdown' => 'TestCategory',
'Dropdown' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
'GroupedDropdown' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
'File' => 'File',
'AttachedFile' => 'File',
'Image' => 'Image',
@ -52,7 +57,7 @@ class BasicFieldsTestPage extends TestPage
private static $many_many = array(
'ManyManyFiles' => 'File',
'MultipleListboxField' => 'TestCategory',
'MultipleListboxField' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
);
private static $defaults = array(

View File

@ -1,8 +1,22 @@
<?php
namespace SilverStripe\FrameworkTest\Model;
use UploadField;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
class Company extends DataObject
{
private static $table_name = 'Company';
/**
*
* @var array
@ -20,12 +34,12 @@ class Company extends DataObject
);
private static $has_many = array(
'Employees' => 'Employee',
'Employees' => 'SilverStripe\\FrameworkTest\\Model\\Employee',
'GroupPhotos' => 'Image'
);
private static $many_many = array(
'PastEmployees' => 'Employee'
'PastEmployees' => 'SilverStripe\\FrameworkTest\\Model\\Employee'
);
private static $many_many_extraFields = array(
@ -86,7 +100,7 @@ class Company extends DataObject
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
$companySet = DataObject::get('Company');
$companySet = DataObject::get('SilverStripe\\FrameworkTest\\Model\\Company');
foreach ($companySet as $company) {
$company->delete();
}

View File

@ -1,31 +1,42 @@
<?php
namespace SilverStripe\FrameworkTest\Model;
use NumericField;
use TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
/**
* Description of Employees
*
*/
class Employee extends DataObject
{
private static $db = array(
'Name' => 'Varchar',
'Biography' => 'HTMLText'
);
private static $has_one = array(
'Company' => 'Company',
'Company' => 'SilverStripe\\FrameworkTest\\Model\\Company',
'ProfileImage' => 'Image'
);
private static $belongs_many_many = array(
'PastCompanies' => 'Company'
'PastCompanies' => 'SilverStripe\\FrameworkTest\\Model\\Company'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
if (method_exists('ManyManyList', 'getExtraFields')) {
if (method_exists('SilverStripe\\ORM\\ManyManyList', 'getExtraFields')) {
$fields->addFieldToTab('Root.Main',
new NumericField('ManyMany[YearStart]', 'Year started (3.1, many-many only)')
);
@ -36,21 +47,21 @@ class Employee extends DataObject
// 3.1 only
if (method_exists('UploadField', 'setAllowedFileCategories')) {
$fields->dataFieldByName('ProfileImage')->setAllowedFileCategories('image');
$fields->dataFieldByName('ProfileImageID')->setAllowedFileCategories('image');
}
return $fields;
}
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
$employeeSet = DataObject::get('Employee');
$employeeSet = DataObject::get('SilverStripe\\FrameworkTest\\Model\\Employee');
foreach ($employeeSet as $employee) {
$employee->delete();
}
foreach ($this->data() as $employeeName) {
$employee = new Employee();
$employee->Name = $employeeName;
@ -67,7 +78,7 @@ class Employee extends DataObject
}
return $result;
}
/**
* Contains test data
*

View File

@ -1,4 +1,6 @@
<?php
use SilverStripe\ORM\DataExtension;
class FileUploadRole extends DataExtension
{
private static $has_one = array(

View File

@ -1,8 +1,10 @@
<?php
use SilverStripe\ORM\DataExtension;
class FrameworkTestFileExtension extends DataExtension
{
private static $has_one = array(
'Company' => 'Company',
'Company' => 'SilverStripe\\FrameworkTest\\Model\\Company',
'BasicFieldsTestPage' => 'BasicFieldsTestPage'
);
}

View File

@ -1,5 +1,9 @@
<?php
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataExtension;
class FrameworkTestRole extends DataExtension
{

View File

@ -1,4 +1,6 @@
<?php
use SilverStripe\ORM\DataExtension;
class FrameworkTestSiteTreeExtension extends DataExtension
{

View File

@ -1,17 +1,20 @@
<?php
use SilverStripe\ORM\DataList;
use SilverStripe\FrameworkTest\Model\TestPage;
class GridFieldTestPage extends TestPage
{
private static $has_one = array(
"HasOneCompany" => "Company",
"HasOneCompany" => "SilverStripe\\FrameworkTest\\Model\\Company",
);
private static $has_many = array(
"HasManyCompanies" => "Company",
"HasManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
);
private static $many_many = array(
"ManyManyCompanies" => "Company",
"ManyManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
);
public function getCMSFields()
@ -21,7 +24,7 @@ class GridFieldTestPage extends TestPage
$grids = array();
$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);
$grids[] = $grid;
@ -72,7 +75,7 @@ class GridFieldTestPage_Controller extends Page_Controller
{
$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());
}
}

View File

@ -1,8 +1,13 @@
<?php
namespace SilverStripe\FrameworkTest\Model;
use SilverStripe\ORM\DataObject;
class Organisation extends DataObject
{
private static $table_name = 'Organisation';
// Used to test the Multiform module
private static $db = array(
'OrganisationName' => 'Text'

View File

@ -1,19 +1,23 @@
<?php
use SilverStripe\FrameworkTest\Model\TestCategory;
use SilverStripe\FrameworkTest\Model\TestPage;
use SilverStripe\FrameworkTest\Model\TestPage_Controller;
class RelationFieldsTestPage extends TestPage
{
private static $has_one = array(
"HasOneCompany" => "Company",
"HasOneCompany" => "SilverStripe\\FrameworkTest\\Model\\Company",
"HasOnePage" => "SiteTree",
"HasOnePageWithSearch" => "SiteTree",
);
private static $has_many = array(
"HasManyCompanies" => "Company",
"HasManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
"HasManyPages" => "SiteTree",
);
private static $many_many = array(
"ManyManyCompanies" => "Company",
"ManyManyCompanies" => "SilverStripe\\FrameworkTest\\Model\\Company",
"ManyManyPages" => "SiteTree",
);

View File

@ -1,23 +1,32 @@
<?php
namespace SilverStripe\FrameworkTest\Model;
use SilverStripe\ORM\DataObject;
/**
* A data type that is related many-many to RelationFieldsTestPage, for testing purposes
*/
class TestCategory extends DataObject
{
private static $table_name = 'TestCategory';
private static $db = array(
"Title" => "Varchar",
);
private static $belongs_many_many = array(
"RelationPages" => "RelationFieldsTestPage",
);
/**
* Returns a dropdown map of all objects of this class
*/
public static function map()
{
$categories = DataObject::get('TestCategory');
$categories = DataObject::get('SilverStripe\\FrameworkTest\\Model\\TestCategory');
if ($categories) {
return $categories->map('ID', 'Title')->toArray();
} else {

View File

@ -1,5 +1,8 @@
<?php
use SilverStripe\FrameworkTest\Model\TestPage;
use SilverStripe\FrameworkTest\Model\TestPage_Controller;
class TestFileUploadPage extends TestPage
{
}

View File

@ -6,7 +6,7 @@ class TestModelAdmin extends ModelAdmin
private static $menu_title = 'Test ModelAdmin';
private static $managed_models = array(
"Company",
"Employee",
"SilverStripe\\FrameworkTest\\Model\\Company",
"SilverStripe\\FrameworkTest\\Model\\Employee",
);
}

View File

@ -1,5 +1,20 @@
<?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
*/
@ -17,7 +32,7 @@ class TestPage extends Page
public function requireDefaultRecords()
{
if ($this->class == 'TestPage') {
if ($this->class == 'SilverStripe\\FrameworkTest\\Model\\TestPage') {
return;
}
@ -40,7 +55,7 @@ class TestPage extends Page
// Create actual page
$page = new $class();
$page->Title = str_replace("TestPage", "", $class);
$page->Title = str_replace("SilverStripe\\FrameworkTest\\Model\\TestPage", "", $class);
$page->ShowInMenus = 0;
if ($parent) {
$page->ParentID = $parent->ID;

View File

@ -1,5 +1,7 @@
<?php
use SilverStripe\ORM\DataObject;
class Page2MultiForm extends MultiForm
{

View File

@ -1,5 +1,7 @@
<?php
use SilverStripe\ORM\DataObject;
class Page3MultiForm extends MultiForm
{