mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-01 23:37:43 +02:00
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99491 467b73ca-7a2a-4603-9d3b-597d59a354a9
167 lines
5.3 KiB
PHP
167 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* Possible actions:
|
|
* - action_save
|
|
* - action_publish
|
|
* - action_unpublish
|
|
* - action_delete
|
|
* - action_deletefromlive
|
|
* - action_rollback
|
|
* - action_revert
|
|
*
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class SiteTreeActionsTest extends FunctionalTest {
|
|
|
|
static $fixture_file = 'sapphire/tests/SiteTreeActionsTest.yml';
|
|
|
|
static function set_up_once() {
|
|
SiteTreeTest::set_up_once();
|
|
|
|
parent::set_up_once();
|
|
}
|
|
|
|
static function tear_down_once() {
|
|
SiteTreeTest::tear_down_once();
|
|
|
|
parent::tear_down_once();
|
|
}
|
|
|
|
function testActionsReadonly() {
|
|
if(class_exists('SiteTreeCMSWorkflow')) return true;
|
|
|
|
$readonlyEditor = $this->objFromFixture('Member', 'cmsreadonlyeditor');
|
|
$this->session()->inst_set('loggedInAs', $readonlyEditor->ID);
|
|
|
|
$page = new SiteTreeActionsTest_Page();
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
$page->write();
|
|
$page->doPublish();
|
|
|
|
$actionsArr = $page->getCMSActions()->column('Name');
|
|
|
|
$this->assertNotContains('action_save',$actionsArr);
|
|
$this->assertNotContains('action_publish',$actionsArr);
|
|
$this->assertNotContains('action_unpublish',$actionsArr);
|
|
$this->assertNotContains('action_delete',$actionsArr);
|
|
$this->assertNotContains('action_deletefromlive',$actionsArr);
|
|
$this->assertNotContains('action_rollback',$actionsArr);
|
|
$this->assertNotContains('action_revert',$actionsArr);
|
|
}
|
|
|
|
function testActionsNoDeletePublishedRecord() {
|
|
if(class_exists('SiteTreeCMSWorkflow')) return true;
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$page = new SiteTreeActionsTest_Page();
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
$page->write();
|
|
$pageID = $page->ID;
|
|
$page->doPublish();
|
|
$page->deleteFromStage('Stage');
|
|
|
|
// Get the live version of the page
|
|
$page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
|
|
$this->assertType("SiteTree", $page);
|
|
|
|
// Check that someone without the right permission can't delete the page
|
|
$editor = $this->objFromFixture('Member', 'cmsnodeleteeditor');
|
|
$this->session()->inst_set('loggedInAs', $editor->ID);
|
|
|
|
$actionsArr = $page->getCMSActions()->column('Name');
|
|
$this->assertNotContains('action_deletefromlive',$actionsArr);
|
|
|
|
// Check that someone with the right permission can delete the page
|
|
$this->objFromFixture('Member', 'cmseditor')->logIn();
|
|
$actionsArr = $page->getCMSActions()->column('Name');
|
|
$this->assertContains('action_deletefromlive',$actionsArr);
|
|
}
|
|
|
|
function testActionsPublishedRecord() {
|
|
if(class_exists('SiteTreeCMSWorkflow')) return true;
|
|
|
|
$author = $this->objFromFixture('Member', 'cmseditor');
|
|
$this->session()->inst_set('loggedInAs', $author->ID);
|
|
|
|
$page = new Page();
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
$page->write();
|
|
$page->doPublish();
|
|
|
|
$actionsArr = $page->getCMSActions()->column('Name');
|
|
|
|
$this->assertContains('action_save',$actionsArr);
|
|
$this->assertContains('action_publish',$actionsArr);
|
|
$this->assertContains('action_unpublish',$actionsArr);
|
|
$this->assertContains('action_delete',$actionsArr);
|
|
$this->assertNotContains('action_deletefromlive',$actionsArr);
|
|
$this->assertNotContains('action_rollback',$actionsArr);
|
|
$this->assertNotContains('action_revert',$actionsArr);
|
|
}
|
|
|
|
function testActionsDeletedFromStageRecord() {
|
|
if(class_exists('SiteTreeCMSWorkflow')) return true;
|
|
|
|
$author = $this->objFromFixture('Member', 'cmseditor');
|
|
$this->session()->inst_set('loggedInAs', $author->ID);
|
|
|
|
$page = new Page();
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
$page->write();
|
|
$pageID = $page->ID;
|
|
$page->doPublish();
|
|
$page->deleteFromStage('Stage');
|
|
|
|
// Get the live version of the page
|
|
$page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
|
|
$this->assertType('SiteTree', $page);
|
|
|
|
$actionsArr = $page->getCMSActions()->column('Name');
|
|
|
|
$this->assertNotContains('action_save',$actionsArr);
|
|
$this->assertNotContains('action_publish',$actionsArr);
|
|
$this->assertNotContains('action_unpublish',$actionsArr);
|
|
$this->assertNotContains('action_delete',$actionsArr);
|
|
$this->assertContains('action_deletefromlive',$actionsArr);
|
|
$this->assertNotContains('action_rollback',$actionsArr);
|
|
$this->assertContains('action_revert',$actionsArr);
|
|
}
|
|
|
|
function testActionsChangedOnStageRecord() {
|
|
if(class_exists('SiteTreeCMSWorkflow')) return true;
|
|
|
|
$author = $this->objFromFixture('Member', 'cmseditor');
|
|
$this->session()->inst_set('loggedInAs', $author->ID);
|
|
|
|
$page = new Page();
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
$page->write();
|
|
$page->doPublish();
|
|
$page->Content = 'Changed on Stage';
|
|
$page->write();
|
|
$page->flushCache();
|
|
|
|
$actionsArr = $page->getCMSActions()->column('Name');
|
|
|
|
$this->assertContains('action_save',$actionsArr);
|
|
$this->assertContains('action_publish',$actionsArr);
|
|
$this->assertContains('action_unpublish',$actionsArr);
|
|
$this->assertContains('action_delete',$actionsArr);
|
|
$this->assertNotContains('action_deletefromlive',$actionsArr);
|
|
$this->assertContains('action_rollback',$actionsArr);
|
|
$this->assertNotContains('action_revert',$actionsArr);
|
|
}
|
|
}
|
|
|
|
class SiteTreeActionsTest_Page extends Page implements TestOnly {
|
|
function canEdit($member = null) {
|
|
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANEDIT');
|
|
}
|
|
|
|
function canDelete($member = null) {
|
|
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANDELETE');
|
|
}
|
|
}
|
|
?>
|