silverstripe-framework/tests/SiteTreeActionsTest.php
Sean Harvey a96e5a7dd5 BUGFIX #6291 Remove rollback action from CMSMain allowed_actions and rely on form action_rollback instead which is safer (from r115440)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@115919 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:27:38 +13:00

132 lines
4.5 KiB
PHP

<?php
/**
* Possible actions:
* - action_save
* - action_publish
* - action_unpublish
* - action_delete
* - action_deletefromlive
* - action_rollback
* - action_revert
*
* @package sapphire
* @subpackage tests
*/
if(class_exists('SiteTreeCMSWorkflow')) {
class SiteTreeActionsTest extends FunctionalTest {
function testDummy() {}
}
} else {
class SiteTreeActionsTest extends FunctionalTest {
static $fixture_file = 'sapphire/tests/SiteTreeActionsTest.yml';
function testActionsNewPage() {
$className = 'Page';
$page = new $className();
$page->Title = 'New ' . $className;
$page->URLSegment = "new-" . strtolower($className);
$page->ClassName = $className;
$page->ParentID = 0;
$page->ID = 'new-Page-1';
$author = $this->objFromFixture('Member', 'cmseditor');
$this->session()->inst_set('loggedInAs', $author->ID);
$actionsArr = $page->getCMSActions()->column('Name');
$this->assertContains('action_save',$actionsArr);
$this->assertContains('action_publish',$actionsArr);
$this->assertNotContains('action_unpublish',$actionsArr);
$this->assertContains('action_delete',$actionsArr);
$this->assertNotContains('action_deletefromlive',$actionsArr);
$this->assertNotContains('action_rollback',$actionsArr);
$this->assertNotContains('action_revert',$actionsArr);
}
function testActionsPublishedRecord() {
$page = new Page();
$page->write();
$page->publish('Stage', 'Live');
$author = $this->objFromFixture('Member', 'cmseditor');
$this->session()->inst_set('loggedInAs', $author->ID);
$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() {
$page = new Page();
$page->write();
$pageID = $page->ID;
$page->publish('Stage', 'Live');
$page->deleteFromStage('Stage');
// Get the live version of the page
$page = Versioned::get_one_by_stage("SiteTree", "Live", "`SiteTree`.ID = $pageID");
$author = $this->objFromFixture('Member', 'cmseditor');
$this->session()->inst_set('loggedInAs', $author->ID);
$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() {
$page = new Page();
$page->write();
$page->publish('Stage', 'Live');
$page->Content = 'Changed on Stage';
$page->write();
$page->flushCache();
$author = $this->objFromFixture('Member', 'cmseditor');
$this->session()->inst_set('loggedInAs', $author->ID);
$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);
}
}
function testActionsViewingOldVersion() {
$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);
$actions = $old->getCMSActions()->column('Name');
$this->assertNotContains('action_save', $actions);
$this->assertNotContains('action_publish', $actions);
$this->assertNotContains('action_unpublish', $actions);
$this->assertNotContains('action_delete', $actions);
$this->assertContains('action_email', $actions);
$this->assertContains('action_rollback', $actions);
}
}