silverstripe-frameworktest/code/TestRegistryPage.php
Guy Sartorelli 7b9778253f
MNT Don't require silverstripe/registry (#123)
Just because registry needs frameworktest doesn't mean frameworktest
should need registry
2022-09-15 17:02:03 +12:00

33 lines
1.0 KiB
PHP

<?php
use SilverStripe\FrameworkTest\Model\TestPage;
use SilverStripe\ORM\DataObject;
use SilverStripe\Registry\RegistryPage;
use SilverStripe\Security\DefaultAdminService;
use SilverStripe\Security\Member;
if (!class_exists(RegistryPage::class)) {
return;
}
class TestRegistryPage extends RegistryPage
{
public function requireDefaultRecords()
{
if (!DataObject::get_one(static::class)) {
// Try to create common parent
$defaultAdminService = DefaultAdminService::singleton();
Member::actAs($defaultAdminService->findOrCreateDefaultAdmin(), function () {
$page = new static;
$page->Title = 'Registry Test Page';
$page->ShowInMenus = 0;
$parent = TestPage::getOrCreateParentPage();
$page->ParentID = $parent->ID;
$page->DataClass = TestRegistryDataObject::class;
$page->write();
$page->copyVersionToStage('Stage', 'Live');
});
}
}
}