silverstripe-frameworktest/code/FrameworkTestRole.php

54 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2008-11-13 22:32:37 +01:00
<?php
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
2024-08-20 06:14:03 +02:00
use SilverStripe\Core\Extension;
2016-07-20 00:34:52 +02:00
use SilverStripe\Security\Member;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TreeDropdownField;
2024-08-20 06:14:03 +02:00
class FrameworkTestRole extends Extension
2015-12-17 21:20:49 +01:00
{
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
private static $has_one = array(
2016-08-16 06:38:31 +02:00
'FavouritePage' => 'SilverStripe\\CMS\\Model\\SiteTree',
2015-12-17 21:20:49 +01:00
);
2016-07-20 00:34:52 +02:00
protected function updateCMSFields(FieldList $fields)
2015-12-17 21:20:49 +01:00
{
$fields->addFieldToTab(
'Root.Main',
2016-08-16 06:38:31 +02:00
new TreeDropdownField("FavouritePageID", "Favourite page", "SilverStripe\\CMS\\Model\\SiteTree")
2015-12-17 21:20:49 +01:00
);
}
2016-07-20 00:34:52 +02:00
2024-08-27 05:39:21 +02:00
protected function onRequireDefaultRecords()
2015-12-17 21:20:49 +01:00
{
2016-07-20 00:34:52 +02:00
$hasTestMembers = Member::get()->find('Email', 'hayley@test.com');
2015-12-17 21:20:49 +01:00
if (!$hasTestMembers) {
foreach ($this->data() as $name) {
$member = new Member(array(
'FirstName' => $name,
'FirstName' => 'Smith',
'Email' => "{$name}@test.com",
));
$member->write();
}
2008-11-13 22:32:37 +01:00
2015-12-17 21:20:49 +01:00
DB::alteration_message("Added default records to Member table", "created");
}
}
2015-12-17 21:20:49 +01:00
/**
* Contains test data
*
* @return array
*/
public function data()
{
return array(
'Hayley', 'Octavius', 'Walker', 'Gary', 'Elton', 'Janna', 'Ursa', 'Lars', 'Moses', 'Lareina', 'Elmo', 'Shea', 'Duncan', 'Velma', 'Acton', 'Galena', 'Heidi', 'Troy', 'Elliott', 'Whitney', 'Summer', 'Olga', 'Tatum', 'Zeph', 'Jared', 'Hilda', 'Quinlan', 'Chaim', 'Xenos', 'Cara', 'Tatiana', 'Tyrone', 'Juliet', 'Chester', 'Hannah', 'Imani', 'Quinn', 'Ariel', 'Aretha', 'Courtney ', 'Shellie', 'Garrett', 'Camilla', 'Simon', 'Mohammad', 'Kirby', 'Rae', 'Xena', 'Noel', 'Omar', 'Shannon', 'Iola', 'Maia', 'Serina', 'Taylor', 'Alice', 'Lucy', 'Austin', 'Abel', 'Yetta', 'Ulysses', 'Donovan', 'Castor', 'Emmanuel', 'Nero', 'Virginia', 'Gregory', 'Neville', 'Len', 'Knox', 'Gavin', 'Pascale', 'Hyatt', 'Alden', 'Emerald', 'Cherokee', 'Adam', 'Uma', 'Serena', 'Isabelle', 'Kieran', 'Gay', 'Lavinia', 'Elvis', 'Illana', 'Lee', 'Ariana', 'Hilel', 'Gage', 'Larissa', 'Richard', 'Allen'
);
}
2012-04-12 05:04:39 +02:00
}