mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Removed reliance of sapphire/admin unit tests on SiteTree and CMSMain
This commit is contained in:
parent
9d742f02f2
commit
95dcc74c10
@ -13,13 +13,13 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
|
||||
$this->assertTrue((empty($menuItems)), 'Menu can be cleared');
|
||||
|
||||
// Add a controller to the menu and check it is as expected
|
||||
CMSMenu::add_controller('CMSMain');
|
||||
CMSMenu::add_controller('CMSMenuTest_LeftAndMainController');
|
||||
$menuItems = CMSMenu::get_menu_items();
|
||||
$menuItem = $menuItems['CMSMain'];
|
||||
$menuItem = $menuItems['CMSMenuTest_LeftAndMainController'];
|
||||
$this->assertType('CMSMenuItem', $menuItem, 'Controller menu item is of class CMSMenuItem');
|
||||
$this->assertEquals($menuItem->url, singleton('CMSMain')->Link(), 'Controller menu item has the correct link');
|
||||
$this->assertEquals($menuItem->controller, 'CMSMain', 'Controller menu item has the correct controller class');
|
||||
$this->assertEquals($menuItem->priority, singleton('CMSMain')->stat('menu_priority'), 'Controller menu item has the correct priority');
|
||||
$this->assertEquals($menuItem->url, singleton('CMSMenuTest_LeftAndMainController')->Link(), 'Controller menu item has the correct link');
|
||||
$this->assertEquals($menuItem->controller, 'CMSMenuTest_LeftAndMainController', 'Controller menu item has the correct controller class');
|
||||
$this->assertEquals($menuItem->priority, singleton('CMSMenuTest_LeftAndMainController')->stat('menu_priority'), 'Controller menu item has the correct priority');
|
||||
CMSMenu::clear_menu();
|
||||
|
||||
// Add a link to the menu
|
||||
@ -38,10 +38,10 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
|
||||
public function testCmsClassDetection() {
|
||||
|
||||
// Get CMS classes and check that:
|
||||
// 1.) CMSMain is included
|
||||
// 1.) SecurityAdmin is included
|
||||
// 2.) LeftAndMain & ModelAdmin are excluded
|
||||
$cmsClasses = CMSMenu::get_cms_classes();
|
||||
$this->assertContains('CMSMain', $cmsClasses, 'CMSMain included in valid CMS Classes');
|
||||
$this->assertContains('SecurityAdmin', $cmsClasses, 'SecurityAdmin included in valid CMS Classes');
|
||||
$this->assertNotContains('LeftAndMain', $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
|
||||
$this->assertNotContains('ModelAdmin', $cmsClasses, 'LeftAndMain not included in valid CMS Classes');
|
||||
|
||||
@ -49,16 +49,16 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
|
||||
|
||||
public function testAdvancedMenuHandling() {
|
||||
|
||||
// Populate from CMS Classes, check for existance of CMSMain
|
||||
// Populate from CMS Classes, check for existance of SecurityAdmin
|
||||
CMSMenu::clear_menu();
|
||||
CMSMenu::populate_menu();
|
||||
$menuItem = CMSMenu::get_menu_item('CMSMain');
|
||||
$this->assertType('CMSMenuItem', $menuItem, 'CMSMain menu item exists');
|
||||
$this->assertEquals($menuItem->url, singleton('CMSMain')->Link(), 'Menu item has the correct link');
|
||||
$this->assertEquals($menuItem->controller, 'CMSMain', 'Menu item has the correct controller class');
|
||||
$menuItem = CMSMenu::get_menu_item('SecurityAdmin');
|
||||
$this->assertType('CMSMenuItem', $menuItem, 'SecurityAdmin menu item exists');
|
||||
$this->assertEquals($menuItem->url, singleton('SecurityAdmin')->Link(), 'Menu item has the correct link');
|
||||
$this->assertEquals($menuItem->controller, 'SecurityAdmin', 'Menu item has the correct controller class');
|
||||
$this->assertEquals(
|
||||
$menuItem->priority,
|
||||
singleton('CMSMain')->stat('menu_priority'),
|
||||
singleton('SecurityAdmin')->stat('menu_priority'),
|
||||
'Menu item has the correct priority'
|
||||
);
|
||||
|
||||
@ -77,3 +77,9 @@ class CMSMenuTest extends SapphireTest implements TestOnly {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CMSMenuTest_LeftAndMainController extends LeftAndMain implements TestOnly {
|
||||
static $url_segment = 'CMSMenuTest_LeftAndMainController';
|
||||
static $menu_title = 'CMSMenuTest_LeftAndMainController';
|
||||
static $menu_priority = 50;
|
||||
}
|
@ -4,7 +4,10 @@
|
||||
* @subpackage tests
|
||||
*/
|
||||
class LeftAndMainTest extends FunctionalTest {
|
||||
static $fixture_file = 'cms/tests/CMSMainTest.yml';
|
||||
|
||||
static $fixture_file = 'sapphire/admin/tests/LeftAndMainTest.yml';
|
||||
|
||||
protected $extraDataObjects = array('LeftAndMainTest_Object');
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
@ -14,10 +17,14 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
CMSMenu::populate_menu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This test would typically rely on SiteTree and CMSMain, but is mocked by
|
||||
* LeftAndMain_Controller and LeftAndMain_Object here to remove this dependency.
|
||||
*/
|
||||
public function testSaveTreeNodeSorting() {
|
||||
$this->loginWithPermission('ADMIN');
|
||||
|
||||
$rootPages = DataObject::get('SiteTree', '"ParentID" = 0'); // implicitly sorted
|
||||
$rootPages = DataObject::get('LeftAndMainTest_Object', '"ParentID" = 0'); // implicitly sorted
|
||||
$siblingIDs = $rootPages->column('ID');
|
||||
$page1 = $rootPages->offsetGet(0);
|
||||
$page2 = $rootPages->offsetGet(1);
|
||||
@ -32,11 +39,11 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
'ParentID' => 0
|
||||
);
|
||||
|
||||
$response = $this->post('admin/savetreenode', $data);
|
||||
$response = $this->post('LeftAndMainTest_Controller/savetreenode', $data);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$page1 = DataObject::get_by_id('SiteTree', $page1->ID, false);
|
||||
$page2 = DataObject::get_by_id('SiteTree', $page2->ID, false);
|
||||
$page3 = DataObject::get_by_id('SiteTree', $page3->ID, false);
|
||||
$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);
|
||||
|
||||
$this->assertEquals(2, $page1->Sort, 'Page1 is sorted after Page2');
|
||||
$this->assertEquals(1, $page2->Sort, 'Page2 is sorted before Page1');
|
||||
@ -46,11 +53,11 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
public function testSaveTreeNodeParentID() {
|
||||
$this->loginWithPermission('ADMIN');
|
||||
|
||||
$page1 = $this->objFromFixture('Page', 'page1');
|
||||
$page2 = $this->objFromFixture('Page', 'page2');
|
||||
$page3 = $this->objFromFixture('Page', 'page3');
|
||||
$page31 = $this->objFromFixture('Page', 'page31');
|
||||
$page32 = $this->objFromFixture('Page', 'page32');
|
||||
$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');
|
||||
|
||||
// Move page2 into page3, between page3.1 and page 3.2
|
||||
$siblingIDs = array(
|
||||
@ -63,11 +70,11 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
'ID' => $page2->ID,
|
||||
'ParentID' => $page3->ID
|
||||
);
|
||||
$response = $this->post('admin/savetreenode', $data);
|
||||
$response = $this->post('LeftAndMainTest_Controller/savetreenode', $data);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$page2 = DataObject::get_by_id('SiteTree', $page2->ID, false);
|
||||
$page31 = DataObject::get_by_id('SiteTree', $page31->ID, false);
|
||||
$page32 = DataObject::get_by_id('SiteTree', $page32->ID, false);
|
||||
$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);
|
||||
|
||||
$this->assertEquals($page3->ID, $page2->ParentID, 'Moved page gets new parent');
|
||||
$this->assertEquals(1, $page31->Sort, 'Children pages before insertaion are unaffected');
|
||||
@ -101,7 +108,7 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
$adminuser = $this->objFromFixture('Member','admin');
|
||||
$this->session()->inst_set('loggedInAs', $adminuser->ID);
|
||||
|
||||
$menuItems = singleton('CMSMain')->MainMenu();
|
||||
$menuItems = singleton('LeftAndMain')->MainMenu();
|
||||
foreach($menuItems as $menuItem) {
|
||||
$link = $menuItem->Link;
|
||||
|
||||
@ -124,7 +131,7 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
|
||||
function testCanView() {
|
||||
$adminuser = $this->objFromFixture('Member', 'admin');
|
||||
$assetsonlyuser = $this->objFromFixture('Member', 'assetsonlyuser');
|
||||
$securityonlyuser = $this->objFromFixture('Member', 'securityonlyuser');
|
||||
$allcmssectionsuser = $this->objFromFixture('Member', 'allcmssectionsuser');
|
||||
|
||||
// anonymous user
|
||||
@ -137,21 +144,21 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
);
|
||||
|
||||
// restricted cms user
|
||||
$this->session()->inst_set('loggedInAs', $assetsonlyuser->ID);
|
||||
$this->session()->inst_set('loggedInAs', $securityonlyuser->ID);
|
||||
$menuItems = singleton('LeftAndMain')->MainMenu();
|
||||
$this->assertEquals(
|
||||
$menuItems->column('Code'),
|
||||
array('AssetAdmin','Help'),
|
||||
array('SecurityAdmin','Help'),
|
||||
'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();
|
||||
$requiredSections = array('CMSMain','AssetAdmin','SecurityAdmin','Help');
|
||||
$this->assertEquals(
|
||||
array_diff($requiredSections, $menuItems->column('Code')),
|
||||
array(),
|
||||
$this->assertContains('SecurityAdmin', $menuItems->column('Code'),
|
||||
'Group with CMS_ACCESS_LeftAndMain permission can access all sections'
|
||||
);
|
||||
$this->assertContains('Help', $menuItems->column('Code'),
|
||||
'Group with CMS_ACCESS_LeftAndMain permission can access all sections'
|
||||
);
|
||||
|
||||
@ -159,14 +166,9 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
$this->session()->inst_set('loggedInAs', $adminuser->ID);
|
||||
$menuItems = singleton('LeftAndMain')->MainMenu();
|
||||
$this->assertContains(
|
||||
'CMSMain',
|
||||
'SecurityAdmin',
|
||||
$menuItems->column('Code'),
|
||||
'Administrators can access CMS'
|
||||
);
|
||||
$this->assertContains(
|
||||
'AssetAdmin',
|
||||
$menuItems->column('Code'),
|
||||
'Administrators can access Assets'
|
||||
'Administrators can access Security Admin'
|
||||
);
|
||||
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
@ -174,3 +176,22 @@ class LeftAndMainTest extends FunctionalTest {
|
||||
|
||||
}
|
||||
|
||||
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'
|
||||
);
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
Page:
|
||||
LeftAndMainTest_Object:
|
||||
page1:
|
||||
Title: Page 1
|
||||
page2:
|
||||
@ -7,10 +7,10 @@ Page:
|
||||
Title: Page 3
|
||||
page31:
|
||||
Title: Page 3.1
|
||||
Parent: =>Page.page3
|
||||
Parent: =>LeftAndMainTest_Object.page3
|
||||
page32:
|
||||
Title: Page 3.2
|
||||
Parent: =>Page.page3
|
||||
Parent: =>LeftAndMainTest_Object.page3
|
||||
page4:
|
||||
Title: Page 4
|
||||
page5:
|
||||
@ -65,8 +65,8 @@ Group:
|
||||
Title: Administrators
|
||||
empty:
|
||||
Title: Empty Group
|
||||
assetsonly:
|
||||
Title: assetsonly
|
||||
securityonly:
|
||||
Title: securityonly
|
||||
allcmssections:
|
||||
Title: allcmssections
|
||||
rooteditusers:
|
||||
@ -76,9 +76,9 @@ Member:
|
||||
Email: admin@example.com
|
||||
Password: ZXXlkwecxz2390232233
|
||||
Groups: =>Group.admin
|
||||
assetsonlyuser:
|
||||
Email: assetsonlyuser@test.com
|
||||
Groups: =>Group.assetsonly
|
||||
securityonlyuser:
|
||||
Email: securityonlyuser@test.com
|
||||
Groups: =>Group.securityonly
|
||||
allcmssectionsuser:
|
||||
Email: allcmssectionsuser@test.com
|
||||
Groups: =>Group.allcmssections
|
||||
@ -89,25 +89,12 @@ Permission:
|
||||
admin:
|
||||
Code: ADMIN
|
||||
GroupID: =>Group.admin
|
||||
assetsonly:
|
||||
Code: CMS_ACCESS_AssetAdmin
|
||||
GroupID: =>Group.assetsonly
|
||||
securityonly:
|
||||
Code: CMS_ACCESS_SecurityAdmin
|
||||
GroupID: =>Group.securityonly
|
||||
allcmssections:
|
||||
Code: CMS_ACCESS_LeftAndMain
|
||||
GroupID: =>Group.allcmssections
|
||||
allcmssections2:
|
||||
Code: CMS_ACCESS_LeftAndMain
|
||||
GroupID: =>Group.rooteditusers
|
||||
SiteConfig:
|
||||
siteconfig1:
|
||||
EditorGroups: =>Group.rooteditusers
|
||||
CanCreateTopLevelType: 'OnlyTheseUsers'
|
||||
SiteConfig_CreateTopLevelGroups:
|
||||
createtoplevelgroups1:
|
||||
SiteConfigID: =>SiteConfig.siteconfig1
|
||||
GroupID: =>Group.rooteditusers
|
||||
RedirectorPage:
|
||||
page5:
|
||||
Title: Page 5
|
||||
RedirectionType: External
|
||||
ExternalURL: http://www.google.com
|
||||
|
@ -4,8 +4,11 @@
|
||||
* @subpackage tests
|
||||
*/
|
||||
class SecurityAdminTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'sapphire/admin/tests/LeftAndMainTest.yml';
|
||||
|
||||
protected $extraDataObjects = array('LeftAndMainTest_Object');
|
||||
|
||||
function testGroupExport() {
|
||||
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
||||
|
||||
@ -70,7 +73,7 @@ class SecurityAdminTest extends FunctionalTest {
|
||||
$response = $this->get('admin/security/show/' . $group->ID);
|
||||
|
||||
$this->assertContains(
|
||||
'CMS_ACCESS_CMSMain',
|
||||
'CMS_ACCESS_SecurityAdmin',
|
||||
$response->getBody()
|
||||
);
|
||||
$this->assertNotContains(
|
||||
|
@ -56,17 +56,20 @@ class ClassInfoTest extends SapphireTest {
|
||||
* @covers ClassInfo::ancestry()
|
||||
*/
|
||||
public function testAncestry() {
|
||||
$ancestry = ClassInfo::ancestry('SiteTree');
|
||||
$ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass');
|
||||
$expect = ArrayLib::valuekey(array(
|
||||
'Object',
|
||||
'ViewableData',
|
||||
'DataObject',
|
||||
'SiteTree'
|
||||
'ClassInfoTest_BaseClass',
|
||||
'ClassInfoTest_ChildClass',
|
||||
));
|
||||
$this->assertEquals($expect, $ancestry);
|
||||
|
||||
$ancestry = ClassInfo::ancestry('SiteTree', true);
|
||||
$this->assertEquals(array('SiteTree' => 'SiteTree'), $ancestry);
|
||||
$ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass', true);
|
||||
$this->assertEquals(array('ClassInfoTest_BaseClass' => 'ClassInfoTest_BaseClass'), $ancestry,
|
||||
'$tablesOnly option excludes memory-only inheritance classes'
|
||||
);
|
||||
|
||||
$this->setExpectedException('Exception');
|
||||
ClassInfo::ancestry(42);
|
||||
|
@ -39,8 +39,8 @@ class TableFieldTest extends SapphireTest {
|
||||
$tableField->setValue(array(
|
||||
'new' => array(
|
||||
'Code' => array(
|
||||
'CMS_ACCESS_CMSMain',
|
||||
'CMS_ACCESS_AssetAdmin',
|
||||
'CustomPerm1',
|
||||
'CustomPerm2',
|
||||
),
|
||||
'Arg' => array(
|
||||
'1',
|
||||
@ -53,8 +53,8 @@ class TableFieldTest extends SapphireTest {
|
||||
// Let's check that the 2 permissions entries have been saved
|
||||
$permissions = $group->Permissions()->toDropdownMap('Arg', 'Code');
|
||||
$this->assertEquals(array(
|
||||
1 => 'CMS_ACCESS_CMSMain',
|
||||
2 => 'CMS_ACCESS_AssetAdmin',
|
||||
1 => 'CustomPerm1',
|
||||
2 => 'CustomPerm2',
|
||||
), $permissions);
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ class TableFieldTest extends SapphireTest {
|
||||
}
|
||||
$value['new'] = array(
|
||||
'Code' => array(
|
||||
'CMS_ACCESS_NewsletterAdmin',
|
||||
'CustomPerm3',
|
||||
),
|
||||
'Arg' => array(
|
||||
'3',
|
||||
@ -77,9 +77,9 @@ class TableFieldTest extends SapphireTest {
|
||||
// Let's check that the 2 existing permissions entries, and the 1 new one, have been saved
|
||||
$permissions = $group->Permissions()->toDropdownMap('Arg', 'Code');
|
||||
$this->assertEquals(array(
|
||||
1 => 'CMS_ACCESS_CMSMain',
|
||||
2 => 'CMS_ACCESS_AssetAdmin',
|
||||
3 => 'CMS_ACCESS_NewsletterAdmin',
|
||||
1 => 'CustomPerm1',
|
||||
2 => 'CustomPerm2',
|
||||
3 => 'CustomPerm3',
|
||||
), $permissions);
|
||||
|
||||
}
|
||||
|
@ -20,14 +20,14 @@ class PermissionTest extends SapphireTest {
|
||||
|
||||
function testPermissionAreInheritedFromOneRole() {
|
||||
$member = $this->objFromFixture('Member', 'author');
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_CMSMain"));
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_MyAdmin"));
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
||||
$this->assertFalse(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"));
|
||||
}
|
||||
|
||||
function testPermissionAreInheritedFromMultipleRoles() {
|
||||
$member = $this->objFromFixture('Member', 'access');
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_CMSMain"));
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_MyAdmin"));
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"));
|
||||
$this->assertTrue(Permission::checkMember($member, "EDIT_PERMISSIONS"));
|
||||
@ -41,7 +41,7 @@ class PermissionTest extends SapphireTest {
|
||||
$this->assertTrue(Permission::checkMember($member, "SITETREE_EDIT_ALL"));
|
||||
|
||||
// Check that roles from parent groups are there
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_CMSMain"));
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_MyAdmin"));
|
||||
$this->assertTrue(Permission::checkMember($member, "CMS_ACCESS_AssetAdmin"));
|
||||
|
||||
// Check that permissions from parent groups are there
|
||||
|
@ -7,7 +7,7 @@ PermissionRole:
|
||||
PermissionRoleCode:
|
||||
author1:
|
||||
Role: =>PermissionRole.author
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
Code: CMS_ACCESS_MyAdmin
|
||||
author2:
|
||||
Role: =>PermissionRole.author
|
||||
Code: CMS_ACCESS_AssetAdmin
|
||||
|
Loading…
Reference in New Issue
Block a user