2011-03-18 04:23:47 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Possible actions:
|
|
|
|
* - action_save
|
|
|
|
* - action_publish
|
|
|
|
* - action_unpublish
|
2015-05-15 01:51:23 +02:00
|
|
|
* - action_archive
|
2011-03-18 04:23:47 +01:00
|
|
|
* - action_deletefromlive
|
|
|
|
* - action_rollback
|
|
|
|
* - action_revert
|
|
|
|
*
|
2011-03-22 10:47:26 +01:00
|
|
|
* @package cms
|
2011-03-18 04:23:47 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class SiteTreeActionsTest extends FunctionalTest {
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
protected static $fixture_file = 'SiteTreeActionsTest.yml';
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsReadonly() {
|
2011-03-18 04:23:47 +01:00
|
|
|
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();
|
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_delete'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsNoDeletePublishedRecord() {
|
2011-03-18 04:23:47 +01:00
|
|
|
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");
|
2012-05-09 13:06:55 +02:00
|
|
|
$this->assertInstanceOf("SiteTree", $page);
|
2011-03-18 04:23:47 +01:00
|
|
|
|
|
|
|
// Check that someone without the right permission can't delete the page
|
|
|
|
$editor = $this->objFromFixture('Member', 'cmsnodeleteeditor');
|
|
|
|
$this->session()->inst_set('loggedInAs', $editor->ID);
|
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
|
2011-03-18 04:23:47 +01:00
|
|
|
|
|
|
|
// Check that someone with the right permission can delete the page
|
|
|
|
$this->objFromFixture('Member', 'cmseditor')->logIn();
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_deletefromlive'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsPublishedRecord() {
|
2011-03-18 04:23:47 +01:00
|
|
|
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();
|
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
|
2015-05-15 01:51:23 +02:00
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsDeletedFromStageRecord() {
|
2011-03-18 04:23:47 +01:00
|
|
|
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");
|
2012-05-09 13:06:55 +02:00
|
|
|
$this->assertInstanceOf('SiteTree', $page);
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
2015-05-15 01:51:23 +02:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_archive'));
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_deletefromlive'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_revert'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsChangedOnStageRecord() {
|
2011-03-18 04:23:47 +01:00
|
|
|
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();
|
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
|
2015-05-15 01:51:23 +02:00
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsViewingOldVersion() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$p = new Page();
|
|
|
|
$p->Content = 'test page first version';
|
|
|
|
$p->write();
|
|
|
|
$p->Content = 'new content';
|
|
|
|
$p->write();
|
|
|
|
|
|
|
|
// Looking at the old version, the ability to rollback to that version is available
|
|
|
|
$version = DB::query('SELECT "Version" FROM "SiteTree_versions" WHERE "Content" = \'test page first version\'')->value();
|
|
|
|
$old = Versioned::get_version('Page', $p->ID, $version);
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $old->getCMSActions();
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
2015-05-15 01:51:23 +02:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_archive'));
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_email'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeActionsTest_Page extends Page implements TestOnly {
|
2012-09-19 12:07:46 +02:00
|
|
|
public function canEdit($member = null) {
|
2011-03-18 04:23:47 +01:00
|
|
|
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANEDIT');
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function canDelete($member = null) {
|
2011-03-18 04:23:47 +01:00
|
|
|
return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANDELETE');
|
|
|
|
}
|
|
|
|
}
|