diff --git a/code/SubsiteAdmin.php b/code/SubsiteAdmin.php index 89d9284..66da3c9 100644 --- a/code/SubsiteAdmin.php +++ b/code/SubsiteAdmin.php @@ -46,14 +46,18 @@ class SubsiteAdmin extends GenericDataAdmin { return $html; } + /** + * Returns the form for adding subsites. + * @returns Form A nerw form object + */ function AddSubsiteForm() { $templates = $this->getIntranetTemplates(); if($templates) { - $templateArray = $templates->map('ID', 'Domain'); + $templateArray = $templates->map('ID', 'Title'); } - return new Form($this, 'AddIntranetForm', new FieldSet( + return new Form($this, 'AddSubsiteForm', new FieldSet( new TextField('Name', 'Name:'), new TextField('Subdomain', 'Subdomain:'), new DropdownField('TemplateID', 'Use template:', $templateArray), @@ -66,11 +70,10 @@ class SubsiteAdmin extends GenericDataAdmin { } public function getIntranetTemplates() { - return DataObject::get('Subsite_Template', '', 'Domain DESC'); + return DataObject::get('Subsite_Template', '', 'Title'); } function addintranet($data, $form) { - $SQL_email = Convert::raw2sql($data['AdminEmail']); $member = DataObject::get_one('Member', "`Email`='$SQL_email'"); @@ -85,7 +88,8 @@ class SubsiteAdmin extends GenericDataAdmin { // Create intranet from existing template // TODO Change template based on the domain selected. - $intranet = Intranet::createFromTemplate($data['Name'], $data['Subdomain'], $data['TemplateID']); + $template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']); + $intranet = $template->createInstance($data['Name'], $data['Subdomain']); $groupObjects = array(); diff --git a/tests/SubsiteAdminTest.php b/tests/SubsiteAdminTest.php index 3efe664..0d715a2 100644 --- a/tests/SubsiteAdminTest.php +++ b/tests/SubsiteAdminTest.php @@ -3,37 +3,31 @@ class SubsiteAdminTest extends SapphireTest { static $fixture_file = 'subsites/tests/SubsiteTest.yml'; - /** - * Test generation of the view - */ - function testBasicView() { - // Open the admin area logged in as admin - $response1 = Director::test('admin/subsites/'); - - - // Confirm that this URL gets you the entire page, with the edit form loaded - $response2 = Director::test('admin/subsites/show/1'); - $this->assertTrue(strpos($response2->getBody(), 'id="Root_Configuration"') !== false); - $this->assertTrue(strpos($response2->getBody(), '
$this->idFromFixture('Member', 'admin') + )); + } - // Confirm that this URL gets you just the form content, with the edit form loaded - $response3 = Director::test('admin/subsites/show/1', array('ajax' => 1)); + /** + * Test generation of the view + */ + function testBasicView() { + // Open the admin area logged in as admin + $response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession()); + + // Confirm that this URL gets you the entire page, with the edit form loaded + $response2 = Director::test('admin/subsites/show/1', null, $this->adminLoggedInSession()); + $this->assertTrue(strpos($response2->getBody(), 'id="Root_Configuration"') !== false); + $this->assertTrue(strpos($response2->getBody(), 'assertTrue(strpos($response3->getBody(), 'id="Root_Configuration"') !== false); - $this->assertTrue(strpos($response3->getBody(), '