2013-10-16 05:24:01 +02:00
|
|
|
<?php
|
|
|
|
|
2010-07-26 05:56:03 +02:00
|
|
|
class LeftAndMainSubsitesTest extends FunctionalTest {
|
|
|
|
|
|
|
|
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
2013-01-03 14:46:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Avoid subsites filtering on fixture fetching.
|
|
|
|
*/
|
|
|
|
function objFromFixture($class, $id) {
|
|
|
|
Subsite::disable_subsite_filter(true);
|
|
|
|
$obj = parent::objFromFixture($class, $id);
|
2013-10-16 05:24:01 +02:00
|
|
|
Subsite::disable_subsite_filter(false);
|
2013-01-03 14:46:56 +01:00
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
2013-10-16 05:24:01 +02:00
|
|
|
|
|
|
|
function testSectionSites() {
|
|
|
|
$member = $this->objFromFixture('Member', 'subsite1member');
|
|
|
|
|
|
|
|
$cmsmain = singleton('CMSMain');
|
|
|
|
$subsites = $cmsmain->sectionSites(true, "Main site", $member);
|
|
|
|
$this->assertDOSEquals(array(
|
|
|
|
array('Title' =>'Subsite1 Template')
|
|
|
|
), $subsites, 'Lists member-accessible sites for the accessible controller.');
|
|
|
|
|
|
|
|
$assetadmin = singleton('AssetAdmin');
|
|
|
|
$subsites = $assetadmin->sectionSites(true, "Main site", $member);
|
|
|
|
$this->assertDOSEquals(array(), $subsites, 'Does not list any sites for forbidden controller.');
|
|
|
|
|
|
|
|
$member = $this->objFromFixture('Member', 'editor');
|
|
|
|
|
|
|
|
$cmsmain = singleton('CMSMain');
|
|
|
|
$subsites = $cmsmain->sectionSites(true, "Main site", $member);
|
|
|
|
$this->assertDOSContains(array(
|
|
|
|
array('Title' =>'Main site')
|
|
|
|
), $subsites, 'Includes the main site for members who can access all sites.');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAccessChecksDontChangeCurrentSubsite() {
|
2010-07-26 05:56:03 +02:00
|
|
|
$admin = $this->objFromFixture("Member","admin");
|
|
|
|
$this->loginAs($admin);
|
|
|
|
$ids = array();
|
|
|
|
|
|
|
|
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
|
|
|
|
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
|
|
|
|
$subsite3 = $this->objFromFixture('Subsite', 'domaintest3');
|
|
|
|
|
|
|
|
$ids[] = $subsite1->ID;
|
|
|
|
$ids[] = $subsite2->ID;
|
|
|
|
$ids[] = $subsite3->ID;
|
|
|
|
$ids[] = 0;
|
|
|
|
|
2013-10-16 05:24:01 +02:00
|
|
|
// Enable session-based subsite tracking.
|
|
|
|
Subsite::$use_session_subsiteid = true;
|
|
|
|
|
2010-07-26 05:56:03 +02:00
|
|
|
foreach($ids as $id) {
|
2013-10-16 05:24:01 +02:00
|
|
|
Subsite::changeSubsite($id);
|
|
|
|
$this->assertEquals($id, Subsite::currentSubsiteID());
|
|
|
|
|
2010-07-26 05:56:03 +02:00
|
|
|
$left = new LeftAndMain();
|
|
|
|
$this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '$id'");
|
2013-10-16 05:24:01 +02:00
|
|
|
$this->assertEquals($id, Subsite::currentSubsiteID(),
|
|
|
|
"The current subsite has not been changed in the process of checking permissions for admin user.");
|
2010-07-26 05:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|