silverstripe-cms/tests/LeftAndMainTest.php
Sam Minnee f71804e465 API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.

From: Sam Minnee <sam@silverstripe.com>


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 03:06:42 +00:00

86 lines
2.5 KiB
PHP

<?php
/**
* @package cms
* @subpackage tests
*/
class LeftAndMainTest extends FunctionalTest {
static $fixture_file = 'cms/tests/CMSMainTest.yml';
function setUp() {
parent::setUp();
// @todo fix controller stack problems and re-activate
//$this->autoFollowRedirection = false;
CMSMenu::populate_menu();
}
/**
* Check that all subclasses of leftandmain can be accessed
*/
public function testLeftAndMainSubclasses() {
$adminuser = $this->objFromFixture('Member','admin');
$this->session()->inst_set('loggedInAs', $adminuser->ID);
$menuItems = singleton('CMSMain')->MainMenu();
foreach($menuItems as $menuItem) {
$link = $menuItem->Link;
// don't test external links
if(preg_match('/^https?:\/\//',$link)) continue;
$response = $this->get($link);
$this->assertType('SS_HTTPResponse', $response, "$link should return a response object");
$this->assertEquals(200, $response->getStatusCode(), "$link should return 200 status code");
// Check that a HTML page has been returned
$this->assertRegExp('/<html[^>]*>/i', $response->getBody(), "$link should contain <html> tag");
$this->assertRegExp('/<head[^>]*>/i', $response->getBody(), "$link should contain <head> tag");
$this->assertRegExp('/<body[^>]*>/i', $response->getBody(), "$link should contain <body> tag");
}
$this->session()->inst_set('loggedInAs', null);
}
function testCanView() {
$adminuser = $this->objFromFixture('Member', 'admin');
$assetsonlyuser = $this->objFromFixture('Member', 'assetsonlyuser');
// anonymous user
$this->session()->inst_set('loggedInAs', null);
$menuItems = singleton('LeftAndMain')->MainMenu();
$this->assertEquals(
$menuItems->column('Code'),
array(),
'Without valid login, members cant access any menu entries'
);
// restricted cms user
$this->session()->inst_set('loggedInAs', $assetsonlyuser->ID);
$menuItems = singleton('LeftAndMain')->MainMenu();
$this->assertEquals(
$menuItems->column('Code'),
array('AssetAdmin','Help'),
'Groups with limited access can only access the interfaces they have permissions for'
);
// admin
$this->session()->inst_set('loggedInAs', $adminuser->ID);
$menuItems = singleton('LeftAndMain')->MainMenu();
$this->assertContains(
'CMSMain',
$menuItems->column('Code'),
'Administrators can access CMS'
);
$this->assertContains(
'AssetAdmin',
$menuItems->column('Code'),
'Administrators can access Assets'
);
$this->session()->inst_set('loggedInAs', null);
}
}