mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
More testing and debugging
This commit is contained in:
parent
dd4045b2bb
commit
5aff60efb5
@ -46,14 +46,18 @@ class SubsiteAdmin extends GenericDataAdmin {
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the form for adding subsites.
|
||||||
|
* @returns Form A nerw form object
|
||||||
|
*/
|
||||||
function AddSubsiteForm() {
|
function AddSubsiteForm() {
|
||||||
$templates = $this->getIntranetTemplates();
|
$templates = $this->getIntranetTemplates();
|
||||||
|
|
||||||
if($templates) {
|
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('Name', 'Name:'),
|
||||||
new TextField('Subdomain', 'Subdomain:'),
|
new TextField('Subdomain', 'Subdomain:'),
|
||||||
new DropdownField('TemplateID', 'Use template:', $templateArray),
|
new DropdownField('TemplateID', 'Use template:', $templateArray),
|
||||||
@ -66,11 +70,10 @@ class SubsiteAdmin extends GenericDataAdmin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getIntranetTemplates() {
|
public function getIntranetTemplates() {
|
||||||
return DataObject::get('Subsite_Template', '', 'Domain DESC');
|
return DataObject::get('Subsite_Template', '', 'Title');
|
||||||
}
|
}
|
||||||
|
|
||||||
function addintranet($data, $form) {
|
function addintranet($data, $form) {
|
||||||
|
|
||||||
$SQL_email = Convert::raw2sql($data['AdminEmail']);
|
$SQL_email = Convert::raw2sql($data['AdminEmail']);
|
||||||
$member = DataObject::get_one('Member', "`Email`='$SQL_email'");
|
$member = DataObject::get_one('Member', "`Email`='$SQL_email'");
|
||||||
|
|
||||||
@ -85,7 +88,8 @@ class SubsiteAdmin extends GenericDataAdmin {
|
|||||||
|
|
||||||
// Create intranet from existing template
|
// Create intranet from existing template
|
||||||
// TODO Change template based on the domain selected.
|
// 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();
|
$groupObjects = array();
|
||||||
|
|
||||||
|
@ -3,47 +3,39 @@
|
|||||||
class SubsiteAdminTest extends SapphireTest {
|
class SubsiteAdminTest extends SapphireTest {
|
||||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||||
|
|
||||||
|
function adminLoggedInSession() {
|
||||||
|
return new Session(array(
|
||||||
|
'loggedInAs' => $this->idFromFixture('Member', 'admin')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test generation of the view
|
* Test generation of the view
|
||||||
*/
|
*/
|
||||||
function testBasicView() {
|
function testBasicView() {
|
||||||
// Open the admin area logged in as admin
|
// Open the admin area logged in as admin
|
||||||
$response1 = Director::test('admin/subsites/');
|
$response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession());
|
||||||
|
|
||||||
|
|
||||||
// Confirm that this URL gets you the entire page, with the edit form loaded
|
// Confirm that this URL gets you the entire page, with the edit form loaded
|
||||||
$response2 = Director::test('admin/subsites/show/1');
|
$response2 = Director::test('admin/subsites/show/1', null, $this->adminLoggedInSession());
|
||||||
$this->assertTrue(strpos($response2->getBody(), 'id="Root_Configuration"') !== false);
|
$this->assertTrue(strpos($response2->getBody(), 'id="Root_Configuration"') !== false);
|
||||||
$this->assertTrue(strpos($response2->getBody(), '<head') !== false);
|
$this->assertTrue(strpos($response2->getBody(), '<head') !== false);
|
||||||
|
|
||||||
// Confirm that this URL gets you just the form content, with the edit form loaded
|
// 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));
|
$response3 = Director::test('admin/subsites/show/1', array('ajax' => 1), $this->adminLoggedInSession());
|
||||||
|
|
||||||
$this->assertTrue(strpos($response3->getBody(), 'id="Root_Configuration"') !== false);
|
$this->assertTrue(strpos($response3->getBody(), 'id="Root_Configuration"') !== false);
|
||||||
$this->assertTrue(strpos($response3->getBody(), '<form') === false);
|
$this->assertTrue(strpos($response3->getBody(), '<form') === false);
|
||||||
$this->assertTrue(strpos($response3->getBody(), '<head') === false);
|
$this->assertTrue(strpos($response3->getBody(), '<head') === false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that the template list is properly generated.
|
|
||||||
*/
|
|
||||||
function testTemplateList() {
|
|
||||||
$cont = new SubsiteAdmin();
|
|
||||||
$templates = $cont->getIntranetTemplates();
|
|
||||||
|
|
||||||
$templateIDs = $this->allFixtureIDs('Subsite_Template');
|
|
||||||
$this->assertTrue($templates->onlyContainsIDs($templateIDs));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test searching for an intranet
|
* Test searching for an intranet
|
||||||
*/
|
*/
|
||||||
function testIntranetSearch() {
|
function testIntranetSearch() {
|
||||||
$cont = new SubsiteAdmin();
|
$cont = new SubsiteAdmin();
|
||||||
$cont->pushCurrent();
|
$cont->pushCurrent();
|
||||||
|
$cont->setSession($this->adminLoggedInSession());
|
||||||
$member = $this->objFromFixture('Member','admin');
|
|
||||||
$member->logIn();
|
|
||||||
|
|
||||||
// Check that the logged-in member has the correct permissions
|
// Check that the logged-in member has the correct permissions
|
||||||
$this->assertTrue(Permission::check('ADMIN') ? true : false);
|
$this->assertTrue(Permission::check('ADMIN') ? true : false);
|
||||||
@ -65,6 +57,41 @@ class SubsiteAdminTest extends SapphireTest {
|
|||||||
$cont->popCurrent();
|
$cont->popCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the intranet creation form.
|
||||||
|
*/
|
||||||
|
function testIntranetCreation() {
|
||||||
|
$cont = new SubsiteAdmin();
|
||||||
|
$cont->pushCurrent();
|
||||||
|
$cont->setSession($this->adminLoggedInSession());
|
||||||
|
|
||||||
|
$form = $cont->AddSubsiteForm();
|
||||||
|
$source = $form->dataFieldByName('TemplateID')->getSource();
|
||||||
|
|
||||||
|
$templateIDs = $this->allFixtureIDs('Subsite_Template');
|
||||||
|
foreach($templateIDs as $templateID) {
|
||||||
|
$this->assertArrayHasKey($templateID, $source);
|
||||||
|
}
|
||||||
|
|
||||||
|
$templateObj = $this->objFromFixture('Subsite_Template','main');
|
||||||
|
$this->assertEquals($templateObj->Title, $source[$templateObj->ID], "Template dropdown isn't listing Title values");
|
||||||
|
|
||||||
|
$response = $form->testSubmission('addintranet', array(
|
||||||
|
'Name' => 'Test Intranet',
|
||||||
|
'Subdomain' => 'Test',
|
||||||
|
'TemplateID' => 1,
|
||||||
|
'AdminEmail' => '',
|
||||||
|
'AdminName' => '',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertTrue(true == preg_match('/admin\/subsites\/show\/([0-9]+)/i', $response->getHeader('Location'), $matches), "Intranet creation dowsn't redirect to new view");
|
||||||
|
|
||||||
|
$newIntranet = DataObject::get_by_id("Subsite", $matches[1]);
|
||||||
|
$this->assertEquals('Test Intranet', $newIntranet->Title, "New intranet not created properly.");
|
||||||
|
|
||||||
|
$cont->popCurrent();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user