More testing and debugging

This commit is contained in:
Sam Minnee 2007-08-21 01:38:20 +00:00
parent dd4045b2bb
commit 5aff60efb5
2 changed files with 68 additions and 37 deletions

View File

@ -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();

View File

@ -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(), '<head') !== false);
function adminLoggedInSession() {
return new Session(array(
'loggedInAs' => $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(), '<head') !== false);
$this->assertTrue(strpos($response3->getBody(), 'id="Root_Configuration"') !== false);
$this->assertTrue(strpos($response3->getBody(), '<form') === 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));
}
// 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), $this->adminLoggedInSession());
$this->assertTrue(strpos($response3->getBody(), 'id="Root_Configuration"') !== false);
$this->assertTrue(strpos($response3->getBody(), '<form') === false);
$this->assertTrue(strpos($response3->getBody(), '<head') === false);
}
/**
* Test searching for an intranet
@ -41,9 +35,7 @@ class SubsiteAdminTest extends SapphireTest {
function testIntranetSearch() {
$cont = new SubsiteAdmin();
$cont->pushCurrent();
$member = $this->objFromFixture('Member','admin');
$member->logIn();
$cont->setSession($this->adminLoggedInSession());
// Check that the logged-in member has the correct permissions
$this->assertTrue(Permission::check('ADMIN') ? true : false);
@ -64,6 +56,41 @@ class SubsiteAdminTest extends SapphireTest {
$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();
}
}