Added tests and fixed associated bugs in the subsite admin section

This commit is contained in:
Sam Minnee 2007-08-20 22:37:43 +00:00
parent 13aa9894b8
commit dd4045b2bb
4 changed files with 34 additions and 15 deletions

View File

@ -220,8 +220,8 @@ SQL;
$SQLa_perm = Convert::raw2sql($permissionCodes);
$SQL_perms = join("','", $SQLa_perm);
$memberID = (int)$member->ID;
return DB::query("SELECT COUNT(`Permission`.`ID`) FROM `Permission` LEFT JOIN `Group` ON `Group`.`ID` = `Permission`.`GroupID` LEFT JOIN `Group_Members` USING(`GroupID`) WHERE `Permission`.`Code` IN ('$SQL_perms') AND `SubsiteID` = 0 AND `MemberID` = {$memberID}")->value();
// `SubsiteID` = 0 AND
return DB::query("SELECT COUNT(`Permission`.`ID`) FROM `Permission` LEFT JOIN `Group` ON `Group`.`ID` = `Permission`.`GroupID` LEFT JOIN `Group_Members` USING(`GroupID`) WHERE `Permission`.`Code` IN ('$SQL_perms') AND `MemberID` = {$memberID}")->value();
}
function createInitialRecords() {

View File

@ -14,14 +14,16 @@ class SubsiteAdmin extends GenericDataAdmin {
}
function getLink() {
return 'admin/intranets/';
return 'admin/subsites/';
}
function Link() {
return $this->getLink();
}
function Results($data, $form) {
function Results($data = null) {
if(!$data) $data = $this->requestParams;
$where = '';
if(isset($data['Name']) && $data['Name']) {
$SQL_name = Convert::raw2sql($data['Name']);
@ -38,7 +40,7 @@ class SubsiteAdmin extends GenericDataAdmin {
foreach($intranets as $intranet) {
$numIntranets++;
$evenOdd = ($numIntranets % 2) ? 'odd':'even';
$html .= "<tr class=\"$evenOdd\"><td><a href=\"admin/intranets/show/{$intranet->ID}\">{$intranet->Title}</a></td><td>{$intranet->Subdomain}.{$intranet->Domain}</td></tr>";
$html .= "<tr class=\"$evenOdd\"><td><a class=\"show\" href=\"admin/subsites/show/{$intranet->ID}\">{$intranet->Title}</a></td><td>{$intranet->Subdomain}.{$intranet->Domain}</td></tr>";
}
$html .= "</tbody></table>";
return $html;
@ -108,7 +110,7 @@ class SubsiteAdmin extends GenericDataAdmin {
$member->Groups()->add($groupObjects['Administrators']);
Director::redirect('admin/intranets/show/' . $intranet->ID);
Director::redirect('admin/subsites/show/' . $intranet->ID);
}
}
?>

View File

@ -2,6 +2,27 @@
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);
// 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->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.
@ -31,20 +52,16 @@ class SubsiteAdminTest extends SapphireTest {
$searches = array(
array('Name' => 'Other'),
array('Name' => ''),
);
foreach($searches as $search) {
$response = $form->testAjaxSubmission('getResults', $search);
echo $response->getBody();
$links = $response->getLinks();
foreach($links as $link) {
$this->assertTrue(preg_match('/^admin\/subsites\/show\/[0-9]+$/', $link['href']) == 1, "Search result links bad.");
}
}
/*
$this->assertHasLink($response->getBody(), 'admin/intranets/show/' . $this->idFromFixture('Subsite', 'other'));
$this->assertHasntLink($response->getBody(), 'admin/intranets/show/' . $this->idFromFixture('Subsite', 'other'));
*/
$cont->popCurrent();
}

View File

@ -2,7 +2,7 @@
class SubsiteTest extends SapphireTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
/**
* Create a new subsite from the template and verify that all the template's pages are copied
*/