2011-03-23 10:51:00 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class LeftAndMainTest extends FunctionalTest {
|
2011-03-29 06:54:08 +02:00
|
|
|
|
|
|
|
static $fixture_file = 'sapphire/admin/tests/LeftAndMainTest.yml';
|
|
|
|
|
|
|
|
protected $extraDataObjects = array('LeftAndMainTest_Object');
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// @todo fix controller stack problems and re-activate
|
|
|
|
//$this->autoFollowRedirection = false;
|
|
|
|
CMSMenu::populate_menu();
|
|
|
|
}
|
|
|
|
|
2011-03-29 06:54:08 +02:00
|
|
|
/**
|
|
|
|
* Note: This test would typically rely on SiteTree and CMSMain, but is mocked by
|
|
|
|
* LeftAndMain_Controller and LeftAndMain_Object here to remove this dependency.
|
|
|
|
*/
|
2011-03-23 10:51:00 +01:00
|
|
|
public function testSaveTreeNodeSorting() {
|
|
|
|
$this->loginWithPermission('ADMIN');
|
2011-03-29 06:54:08 +02:00
|
|
|
|
|
|
|
$rootPages = DataObject::get('LeftAndMainTest_Object', '"ParentID" = 0'); // implicitly sorted
|
2011-03-23 10:51:00 +01:00
|
|
|
$siblingIDs = $rootPages->column('ID');
|
|
|
|
$page1 = $rootPages->offsetGet(0);
|
|
|
|
$page2 = $rootPages->offsetGet(1);
|
|
|
|
$page3 = $rootPages->offsetGet(2);
|
|
|
|
|
|
|
|
// Move page2 before page1
|
|
|
|
$siblingIDs[0] = $page2->ID;
|
|
|
|
$siblingIDs[1] = $page1->ID;
|
|
|
|
$data = array(
|
|
|
|
'SiblingIDs' => $siblingIDs,
|
|
|
|
'ID' => $page2->ID,
|
|
|
|
'ParentID' => 0
|
|
|
|
);
|
|
|
|
|
2011-03-29 06:54:08 +02:00
|
|
|
$response = $this->post('LeftAndMainTest_Controller/savetreenode', $data);
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
2011-03-29 06:54:08 +02:00
|
|
|
$page1 = DataObject::get_by_id('LeftAndMainTest_Object', $page1->ID, false);
|
|
|
|
$page2 = DataObject::get_by_id('LeftAndMainTest_Object', $page2->ID, false);
|
|
|
|
$page3 = DataObject::get_by_id('LeftAndMainTest_Object', $page3->ID, false);
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
$this->assertEquals(2, $page1->Sort, 'Page1 is sorted after Page2');
|
|
|
|
$this->assertEquals(1, $page2->Sort, 'Page2 is sorted before Page1');
|
|
|
|
$this->assertEquals(3, $page3->Sort, 'Sort order for other pages is unaffected');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveTreeNodeParentID() {
|
|
|
|
$this->loginWithPermission('ADMIN');
|
|
|
|
|
2011-03-29 06:54:08 +02:00
|
|
|
$page1 = $this->objFromFixture('LeftAndMainTest_Object', 'page1');
|
|
|
|
$page2 = $this->objFromFixture('LeftAndMainTest_Object', 'page2');
|
|
|
|
$page3 = $this->objFromFixture('LeftAndMainTest_Object', 'page3');
|
|
|
|
$page31 = $this->objFromFixture('LeftAndMainTest_Object', 'page31');
|
|
|
|
$page32 = $this->objFromFixture('LeftAndMainTest_Object', 'page32');
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
// Move page2 into page3, between page3.1 and page 3.2
|
|
|
|
$siblingIDs = array(
|
|
|
|
$page31->ID,
|
|
|
|
$page2->ID,
|
|
|
|
$page32->ID
|
|
|
|
);
|
|
|
|
$data = array(
|
|
|
|
'SiblingIDs' => $siblingIDs,
|
|
|
|
'ID' => $page2->ID,
|
|
|
|
'ParentID' => $page3->ID
|
|
|
|
);
|
2011-03-29 06:54:08 +02:00
|
|
|
$response = $this->post('LeftAndMainTest_Controller/savetreenode', $data);
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
2011-03-29 06:54:08 +02:00
|
|
|
$page2 = DataObject::get_by_id('LeftAndMainTest_Object', $page2->ID, false);
|
|
|
|
$page31 = DataObject::get_by_id('LeftAndMainTest_Object', $page31->ID, false);
|
|
|
|
$page32 = DataObject::get_by_id('LeftAndMainTest_Object', $page32->ID, false);
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
$this->assertEquals($page3->ID, $page2->ParentID, 'Moved page gets new parent');
|
|
|
|
$this->assertEquals(1, $page31->Sort, 'Children pages before insertaion are unaffected');
|
|
|
|
$this->assertEquals(2, $page2->Sort, 'Moved page is correctly sorted');
|
|
|
|
$this->assertEquals(3, $page32->Sort, 'Children pages after insertion are resorted');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that CMS versions can be interpreted appropriately
|
|
|
|
*/
|
|
|
|
public function testCMSVersion() {
|
|
|
|
$l = new LeftAndMain();
|
|
|
|
$this->assertEquals("2.4", $l->versionFromVersionFile(
|
2011-03-29 10:34:26 +02:00
|
|
|
'$URL: http://svn.silverstripe.com/open/modules/sapphire/branches/2.4/silverstripe_version $'));
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->assertEquals("2.2.0", $l->versionFromVersionFile(
|
2011-03-29 10:34:26 +02:00
|
|
|
'$URL: http://svn.silverstripe.com/open/modules/sapphire/tags/2.2.0/silverstripe_version $'));
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->assertEquals("trunk", $l->versionFromVersionFile(
|
2011-03-29 10:34:26 +02:00
|
|
|
'$URL: http://svn.silverstripe.com/open/modules/sapphire/trunk/silverstripe_version $'));
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->assertEquals("2.4.0-alpha1", $l->versionFromVersionFile(
|
2011-03-29 10:34:26 +02:00
|
|
|
'$URL: http://svn.silverstripe.com/open/modules/sapphire/tags/alpha/2.4.0-alpha1/silverstripe_version $'));
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->assertEquals("2.4.0-beta1", $l->versionFromVersionFile(
|
2011-03-29 10:34:26 +02:00
|
|
|
'$URL: http://svn.silverstripe.com/open/modules/sapphire/tags/beta/2.4.0-beta1/silverstripe_version $'));
|
2011-03-23 10:51:00 +01:00
|
|
|
$this->assertEquals("2.4.0-rc1", $l->versionFromVersionFile(
|
2011-03-29 10:34:26 +02:00
|
|
|
'$URL: http://svn.silverstripe.com/open/modules/sapphire/tags/rc/2.4.0-rc1/silverstripe_version $'));
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that all subclasses of leftandmain can be accessed
|
|
|
|
*/
|
|
|
|
public function testLeftAndMainSubclasses() {
|
|
|
|
$adminuser = $this->objFromFixture('Member','admin');
|
|
|
|
$this->session()->inst_set('loggedInAs', $adminuser->ID);
|
|
|
|
|
2011-03-29 06:54:08 +02:00
|
|
|
$menuItems = singleton('LeftAndMain')->MainMenu();
|
2011-03-23 10:51:00 +01:00
|
|
|
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');
|
2011-03-29 06:54:08 +02:00
|
|
|
$securityonlyuser = $this->objFromFixture('Member', 'securityonlyuser');
|
2011-03-23 10:51:00 +01:00
|
|
|
$allcmssectionsuser = $this->objFromFixture('Member', 'allcmssectionsuser');
|
|
|
|
|
|
|
|
// 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
|
2011-03-29 06:54:08 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', $securityonlyuser->ID);
|
2011-03-23 10:51:00 +01:00
|
|
|
$menuItems = singleton('LeftAndMain')->MainMenu();
|
|
|
|
$this->assertEquals(
|
|
|
|
$menuItems->column('Code'),
|
2011-03-29 06:54:08 +02:00
|
|
|
array('SecurityAdmin','Help'),
|
2011-03-23 10:51:00 +01:00
|
|
|
'Groups with limited access can only access the interfaces they have permissions for'
|
|
|
|
);
|
|
|
|
|
|
|
|
// all cms sections user
|
|
|
|
$this->session()->inst_set('loggedInAs', $allcmssectionsuser->ID);
|
|
|
|
$menuItems = singleton('LeftAndMain')->MainMenu();
|
2011-03-29 06:54:08 +02:00
|
|
|
$this->assertContains('SecurityAdmin', $menuItems->column('Code'),
|
|
|
|
'Group with CMS_ACCESS_LeftAndMain permission can access all sections'
|
|
|
|
);
|
|
|
|
$this->assertContains('Help', $menuItems->column('Code'),
|
2011-03-23 10:51:00 +01:00
|
|
|
'Group with CMS_ACCESS_LeftAndMain permission can access all sections'
|
|
|
|
);
|
|
|
|
|
|
|
|
// admin
|
|
|
|
$this->session()->inst_set('loggedInAs', $adminuser->ID);
|
|
|
|
$menuItems = singleton('LeftAndMain')->MainMenu();
|
|
|
|
$this->assertContains(
|
2011-03-29 06:54:08 +02:00
|
|
|
'SecurityAdmin',
|
2011-03-23 10:51:00 +01:00
|
|
|
$menuItems->column('Code'),
|
2011-03-29 06:54:08 +02:00
|
|
|
'Administrators can access Security Admin'
|
2011-03-23 10:51:00 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->session()->inst_set('loggedInAs', null);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-29 06:54:08 +02:00
|
|
|
class LeftAndMainTest_Controller extends LeftAndMain implements TestOnly {
|
|
|
|
protected $template = 'BlankPage';
|
|
|
|
|
|
|
|
static $tree_class = 'LeftAndMainTest_Object';
|
|
|
|
}
|
|
|
|
|
|
|
|
class LeftAndMainTest_Object extends DataObject implements TestOnly {
|
|
|
|
|
|
|
|
static $db = array(
|
|
|
|
'Title' => 'Varchar',
|
|
|
|
'URLSegment' => 'Varchar',
|
|
|
|
'Sort' => 'Int',
|
|
|
|
);
|
|
|
|
|
|
|
|
static $extensions = array(
|
|
|
|
'Hierarchy'
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|