2009-05-04 07:03:44 +02:00
< ? php
2007-08-16 08:38:29 +02:00
class SubsiteAdminTest extends SapphireTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml' ;
2007-08-21 00:37:43 +02:00
2007-08-21 03:38:20 +02:00
function adminLoggedInSession () {
return new Session ( array (
'loggedInAs' => $this -> idFromFixture ( 'Member' , 'admin' )
));
}
2007-08-21 00:37:43 +02:00
2007-08-21 03:38:20 +02:00
/**
* 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
2010-03-01 03:53:22 +01:00
$response2 = Director :: test ( 'admin/subsites/Subsite/1/edit' , null , $this -> adminLoggedInSession ());
2008-03-19 05:26:00 +01:00
$this -> assertTrue ( strpos ( $response2 -> getBody (), 'id="Form_EditForm_ID"' ) !== false , " Testing Form_EditForm_ID exists " );
$this -> assertTrue ( strpos ( $response2 -> getBody (), '<head' ) !== false , " Testing <head> exists " );
2007-08-21 03:38:20 +02:00
}
2007-08-16 08:38:29 +02:00
2007-08-17 07:50:23 +02:00
/**
* Test searching for an intranet
*/
2008-03-19 05:26:00 +01:00
function XXtestIntranetSearch () {
2007-08-17 07:50:23 +02:00
$cont = new SubsiteAdmin ();
$cont -> pushCurrent ();
2007-08-21 03:38:20 +02:00
$cont -> setSession ( $this -> adminLoggedInSession ());
2007-08-17 07:50:23 +02:00
// Check that the logged-in member has the correct permissions
$this -> assertTrue ( Permission :: check ( 'ADMIN' ) ? true : false );
$form = $cont -> SearchForm ();
$searches = array (
array ( 'Name' => 'Other' ),
);
foreach ( $searches as $search ) {
$response = $form -> testAjaxSubmission ( 'getResults' , $search );
2007-08-21 00:37:43 +02:00
$links = $response -> getLinks ();
foreach ( $links as $link ) {
$this -> assertTrue ( preg_match ( '/^admin\/subsites\/show\/[0-9]+$/' , $link [ 'href' ]) == 1 , " Search result links bad. " );
}
2007-08-17 07:50:23 +02:00
}
$cont -> popCurrent ();
}
2007-08-21 03:38:20 +02:00
/**
* Test the intranet creation form .
*/
2008-03-19 05:26:00 +01:00
function XXtestIntranetCreation () {
2007-08-21 03:38:20 +02:00
$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' ,
2010-03-01 03:48:45 +01:00
'Domain' => 'test.example.com' ,
2007-08-21 03:38:20 +02:00
'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 ();
}
2009-02-24 23:09:15 +01:00
/**
* Test that the main - site user with ADMIN permissions can access all subsites , regardless
* of whether he is in a subsite - specific group or not .
*/
function testMainsiteAdminCanAccessAllSubsites () {
$member = $this -> objFromFixture ( 'Member' , 'admin' );
2009-05-04 07:03:44 +02:00
Session :: set ( " loggedInAs " , $member -> ID );
2009-02-24 23:09:15 +01:00
$cmsMain = new CMSMain ();
foreach ( $cmsMain -> Subsites () as $subsite ) {
$ids [ $subsite -> ID ] = true ;
2010-01-14 07:29:12 +01:00
}
2009-02-24 23:09:15 +01:00
$this -> assertArrayHasKey ( 0 , $ids , " Main site accessible " );
2010-01-14 07:29:12 +01:00
$this -> assertArrayHasKey ( $this -> idFromFixture ( 'Subsite_Template' , 'main' ), $ids , " Site with no groups inaccesible " );
$this -> assertArrayHasKey ( $this -> idFromFixture ( 'Subsite_Template' , 'subsite1' ), $ids , " Subsite1 Template inaccessible " );
$this -> assertArrayHasKey ( $this -> idFromFixture ( 'Subsite_Template' , 'subsite2' ), $ids , " Subsite2 Template inaccessible " );
2009-02-24 23:09:15 +01:00
}
2007-08-17 07:50:23 +02:00
2007-08-16 08:38:29 +02:00
}
?>