mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
Merge pull request #55 from open-sausages/pulls/4/tweak-framework-test
Update Frameworktest to be a vendormodule and tweaks
This commit is contained in:
commit
cace7979aa
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\FrameworkTest\Model;
|
namespace SilverStripe\FrameworkTest\Model;
|
||||||
|
|
||||||
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\ORM\ValidationResult;
|
use SilverStripe\ORM\ValidationResult;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
@ -338,4 +339,9 @@ class Company extends DataObject
|
|||||||
215 => array("Cisco", "Information technology", "40.04", "John T. Chambers"),
|
215 => array("Cisco", "Information technology", "40.04", "John T. Chambers"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldSearchField()
|
||||||
|
{
|
||||||
|
return DropdownField::create('CompanyID', 'Company', self::get()->map())->setEmptyString('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,19 @@ namespace SilverStripe\FrameworkTest\Model;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use SilverStripe\Assets\Image;
|
||||||
|
use SilverStripe\Forms\CompositeField;
|
||||||
|
use SilverStripe\Forms\FieldGroup;
|
||||||
|
use SilverStripe\ORM\Connect\MySQLSchemaManager;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\Forms\NumericField;
|
use SilverStripe\Forms\NumericField;
|
||||||
use SilverStripe\Forms\TextField;
|
use SilverStripe\Forms\TextField;
|
||||||
|
use SilverStripe\Forms\DropdownField;
|
||||||
|
use SilverStripe\ORM\Filters\ExactMatchFilter;
|
||||||
|
use SilverStripe\ORM\Filters\FulltextFilter;
|
||||||
|
use SilverStripe\ORM\Filters\GreaterThanOrEqualFilter;
|
||||||
|
use SilverStripe\ORM\Filters\LessThanOrEqualFilter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,17 +30,62 @@ class Employee extends DataObject
|
|||||||
|
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
'Name' => 'Varchar',
|
'Name' => 'Varchar',
|
||||||
'Biography' => 'HTMLText'
|
'Biography' => 'HTMLText',
|
||||||
|
'DateOfBirth' => 'Date',
|
||||||
|
'Category' => 'Enum("marketing,management,rnd,hr")'
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $has_one = array(
|
private static $has_one = [
|
||||||
'Company' => 'SilverStripe\\FrameworkTest\\Model\\Company',
|
'Company' => Company::class,
|
||||||
'ProfileImage' => 'SilverStripe\\Assets\\Image'
|
'ProfileImage' => Image::class
|
||||||
);
|
];
|
||||||
|
|
||||||
private static $belongs_many_many = array(
|
private static $belongs_many_many = [
|
||||||
'PastCompanies' => 'SilverStripe\\FrameworkTest\\Model\\Company'
|
'PastCompanies' => Company::class
|
||||||
);
|
];
|
||||||
|
|
||||||
|
private static $indexes = [
|
||||||
|
'SearchFields' => [
|
||||||
|
'type' => 'fulltext',
|
||||||
|
'columns' => ['Name', 'Biography'],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $create_table_options = [
|
||||||
|
MySQLSchemaManager::ID => 'ENGINE=MyISAM'
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $summary_fields = [
|
||||||
|
'ID',
|
||||||
|
'Name',
|
||||||
|
'Biography',
|
||||||
|
'CompanyID',
|
||||||
|
'Company.Name' => 'Company',
|
||||||
|
'ColleagueNames' => 'Colleague Names',
|
||||||
|
'DateOfBirth',
|
||||||
|
'Category'
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $searchable_fields = [
|
||||||
|
'Name',
|
||||||
|
'Company' => [
|
||||||
|
'title' => 'Company exact match filter',
|
||||||
|
'filter' => ExactMatchFilter::class,
|
||||||
|
],
|
||||||
|
'Company.Name' => array(
|
||||||
|
'title' => 'Company Name starting with',
|
||||||
|
'field' => TextField::class,
|
||||||
|
'filter' => 'StartsWithFilter'
|
||||||
|
),
|
||||||
|
'CompanyID' => [
|
||||||
|
'title' => 'Company ID less than',
|
||||||
|
'field' => NumericField::class,
|
||||||
|
'filter' => 'LessThanFilter'
|
||||||
|
],
|
||||||
|
'Company.Employees.Name' => array('title' => 'Colleague'),
|
||||||
|
'DateOfBirth',
|
||||||
|
'Category'
|
||||||
|
];
|
||||||
|
|
||||||
private static $table_name = 'Employee';
|
private static $table_name = 'Employee';
|
||||||
|
|
||||||
@ -49,17 +101,40 @@ class Employee extends DataObject
|
|||||||
public function requireDefaultRecords()
|
public function requireDefaultRecords()
|
||||||
{
|
{
|
||||||
parent::requireDefaultRecords();
|
parent::requireDefaultRecords();
|
||||||
$employeeSet = DataObject::get('SilverStripe\\FrameworkTest\\Model\\Employee');
|
$employeeSet = DataObject::get(Employee::class);
|
||||||
foreach ($employeeSet as $employee) {
|
foreach ($employeeSet as $employee) {
|
||||||
$employee->delete();
|
$employee->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// By explicitly seeding our random generator, we'll always get the same sequence
|
||||||
|
srand(5);
|
||||||
|
|
||||||
|
$companyIDs = Company::get()->column();
|
||||||
|
$companyCount = sizeof($companyIDs);
|
||||||
|
|
||||||
|
$words = $this->words();
|
||||||
|
$wordCount = sizeof($words);
|
||||||
|
$categories = ['marketing', 'management', 'rnd', 'hr'];
|
||||||
|
|
||||||
foreach ($this->data() as $employeeName) {
|
foreach ($this->data() as $employeeName) {
|
||||||
$employee = new Employee();
|
$employee = Employee::create([
|
||||||
$employee->Name = $employeeName;
|
'Name' => $employeeName,
|
||||||
|
'CompanyID' => $companyIDs[rand(0, $companyCount-1)],
|
||||||
|
'Biography' => implode([
|
||||||
|
$words[rand(0, $wordCount-1)],
|
||||||
|
$words[rand(0, $wordCount-1)],
|
||||||
|
$words[rand(0, $wordCount-1)],
|
||||||
|
$words[rand(0, $wordCount-1)],
|
||||||
|
], " "),
|
||||||
|
'DateOfBirth' => date("Y-m-d", rand(0, 500) * 24 * 60 * 60),
|
||||||
|
'Category' => $categories[rand(0, 3)]
|
||||||
|
]);
|
||||||
$employee->write();
|
$employee->write();
|
||||||
}
|
}
|
||||||
DB::alteration_message("Added default records to Employee table", "created");
|
DB::alteration_message("Added default records to Employee table", "created");
|
||||||
|
|
||||||
|
// Let's rescrambled our random generator
|
||||||
|
srand();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validate()
|
public function validate()
|
||||||
@ -91,4 +166,37 @@ class Employee extends DataObject
|
|||||||
'Elvis','Illana','Lee','Ariana','Hilel','Juliet','Gage','Larissa','Richard','Allen'
|
'Elvis','Illana','Lee','Ariana','Hilel','Juliet','Gage','Larissa','Richard','Allen'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Random words used to build the BIO
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function words()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"aquarist", "macedonian", "kalian", "knew", "cloisterless", "separation", "husker",
|
||||||
|
"subhall", "relatable", "gyrofrequency", "mandating", "presentability", "catt", "folioing",
|
||||||
|
"theodore", "yavar", "mutular", "umbrage", "reinstated", "sert", "nonemulous", "nutwood",
|
||||||
|
"perikeiromene", "moi", "wordless", "downstage", "rsj", "nonanesthetized", "dunker",
|
||||||
|
"preloan", "lev", "marlow", "unpaneled", "overliberally", "monasticism", "philoctetes",
|
||||||
|
"amba", "fluffier", "volley", "unwasteful", "helpless", "gallico", "superexpectation",
|
||||||
|
"quartermaster", "extenuative", "marriage", "tiberius", "horn", "yankeedom", "chabazite",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaultSearchContext()
|
||||||
|
{
|
||||||
|
$context = parent::getDefaultSearchContext();
|
||||||
|
|
||||||
|
$context->addField(TextField::create('SearchFields', 'Full Text search'));
|
||||||
|
$context->addFilter(FulltextFilter::create('SearchFields'));
|
||||||
|
|
||||||
|
return $context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColleagueNames()
|
||||||
|
{
|
||||||
|
return implode($this->Company()->Employees()->column('Name'), ' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ namespace SilverStripe\FrameworkTest\Model;
|
|||||||
|
|
||||||
use Page;
|
use Page;
|
||||||
use PageController;
|
use PageController;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleResource;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Forms\FormAction;
|
use SilverStripe\Forms\FormAction;
|
||||||
@ -87,7 +89,10 @@ class TestPage_Controller extends PageController
|
|||||||
new FormAction("save", "Save"),
|
new FormAction("save", "Save"),
|
||||||
$gohome = new FormAction("gohome", "Go home")
|
$gohome = new FormAction("gohome", "Go home")
|
||||||
);
|
);
|
||||||
$gohome->setAttribute('src', 'frameworktest/images/test-button.png');
|
$gohome->setAttribute(
|
||||||
|
'src',
|
||||||
|
ModuleResourceLoader::resourceURL('silverstripe/frameworktest: images/test-button.png')
|
||||||
|
);
|
||||||
$form = new Form($this, "Form", $fields, $actions);
|
$form = new Form($this, "Form", $fields, $actions);
|
||||||
$form->loadDataFrom($this->dataRecord);
|
$form->loadDataFrom($this->dataRecord);
|
||||||
return $form;
|
return $form;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "silverstripe/frameworktest",
|
"name": "silverstripe/frameworktest",
|
||||||
"description": "Aids core and module developers in testing their code against a set of sample data and behaviour.",
|
"description": "Aids core and module developers in testing their code against a set of sample data and behaviour.",
|
||||||
"type": "silverstripe-module",
|
"type": "silverstripe-vendormodule",
|
||||||
"keywords": ["silverstripe", "frameworktest", "testing"],
|
"keywords": ["silverstripe", "frameworktest", "testing"],
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"authors": [
|
"authors": [
|
||||||
@ -15,6 +15,19 @@
|
|||||||
"silverstripe/framework": "~4.0",
|
"silverstripe/framework": "~4.0",
|
||||||
"silverstripe/cms": "~4.0",
|
"silverstripe/cms": "~4.0",
|
||||||
"guzzlehttp/guzzle": "~6.0",
|
"guzzlehttp/guzzle": "~6.0",
|
||||||
"fzaninotto/faker": "^1.7"
|
"fzaninotto/faker": "^1.7",
|
||||||
|
"silverstripe/vendor-plugin": "^1.0"
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"expose": [
|
||||||
|
"client/dist",
|
||||||
|
"css",
|
||||||
|
"images"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"SSilverStripe\\FrameworkTest\\": "code/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user