2011-03-18 04:23:47 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\Versioning\Versioned;
|
|
|
|
use SilverStripe\ORM\DB;
|
2016-10-25 02:22:31 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2016-06-23 01:51:20 +02:00
|
|
|
use SilverStripe\Security\Permission;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* 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_rollback
|
|
|
|
* - action_revert
|
2016-01-06 00:42:07 +01:00
|
|
|
*
|
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';
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsReadonly() {
|
2016-10-25 02:22:31 +02:00
|
|
|
if(class_exists('SiteTreeCMSWorkflow')) {
|
|
|
|
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
// Publish record
|
|
|
|
$this->logInWithPermission('ADMIN');
|
2011-03-18 04:23:47 +01:00
|
|
|
$page = new SiteTreeActionsTest_Page();
|
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
// Log in as another user
|
|
|
|
$readonlyEditor = $this->objFromFixture(Member::class, 'cmsreadonlyeditor');
|
|
|
|
$this->session()->inst_set('loggedInAs', $readonlyEditor->ID);
|
|
|
|
|
|
|
|
// Reload latest version
|
|
|
|
$page = Page::get()->byID($page->ID);
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2016-03-08 21:50:55 +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'));
|
2016-10-25 02:22:31 +02:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_archive'));
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsNoDeletePublishedRecord() {
|
2016-10-25 02:22:31 +02:00
|
|
|
if(class_exists('SiteTreeCMSWorkflow')) {
|
|
|
|
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
|
|
|
|
}
|
2011-03-18 04:23:47 +01:00
|
|
|
|
|
|
|
$this->logInWithPermission('ADMIN');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$page = new SiteTreeActionsTest_Page();
|
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
|
|
|
$pageID = $page->ID;
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2016-10-25 02:22:31 +02:00
|
|
|
$page->deleteFromStage(Versioned::DRAFT);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Get the live version of the page
|
2016-10-25 02:22:31 +02:00
|
|
|
$page = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $pageID");
|
|
|
|
$this->assertInstanceOf(SiteTree::class, $page);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Check that someone without the right permission can't delete the page
|
2016-10-25 02:22:31 +02:00
|
|
|
$editor = $this->objFromFixture(Member::class, 'cmsnodeleteeditor');
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->session()->inst_set('loggedInAs', $editor->ID);
|
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2016-10-25 02:22:31 +02:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_archive'));
|
2011-03-18 04:23:47 +01:00
|
|
|
|
|
|
|
// Check that someone with the right permission can delete the page
|
2016-10-25 02:22:31 +02:00
|
|
|
/** @var Member $member */
|
|
|
|
$member = $this->objFromFixture(Member::class, 'cmseditor');
|
|
|
|
$member->logIn();
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2016-10-25 02:22:31 +02:00
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsPublishedRecord() {
|
2016-10-25 02:22:31 +02:00
|
|
|
if(class_exists('SiteTreeCMSWorkflow')) {
|
|
|
|
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
|
|
|
|
}
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, 'cmseditor');
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->session()->inst_set('loggedInAs', $author->ID);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
/** @var Page $page */
|
2011-03-18 04:23:47 +01:00
|
|
|
$page = new Page();
|
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
// Reload latest version
|
|
|
|
$page = Page::get()->byID($page->ID);
|
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2016-03-08 21:50:55 +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_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsDeletedFromStageRecord() {
|
2016-10-25 02:22:31 +02:00
|
|
|
if(class_exists('SiteTreeCMSWorkflow')) {
|
|
|
|
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
|
|
|
|
}
|
2011-03-18 04:23:47 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, 'cmseditor');
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->session()->inst_set('loggedInAs', $author->ID);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$page = new Page();
|
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
2016-10-25 02:22:31 +02:00
|
|
|
$this->assertTrue($page->canPublish());
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageID = $page->ID;
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$page->deleteFromStage('Stage');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Get the live version of the page
|
2016-10-25 02:22:31 +02:00
|
|
|
$page = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $pageID");
|
|
|
|
$this->assertInstanceOf(SiteTree::class, $page);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-02-16 22:59:47 +01:00
|
|
|
$actions = $page->getCMSActions();
|
2016-03-08 21:50:55 +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'));
|
2016-10-25 02:22:31 +02:00
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_revert'));
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testActionsChangedOnStageRecord() {
|
2016-10-25 02:22:31 +02:00
|
|
|
if(class_exists('SiteTreeCMSWorkflow')) {
|
|
|
|
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, 'cmseditor');
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->session()->inst_set('loggedInAs', $author->ID);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$page = new Page();
|
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
2016-10-25 02:22:31 +02:00
|
|
|
$this->assertTrue($page->canPublish());
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$page->Content = 'Changed on Stage';
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
// Reload latest version
|
|
|
|
$page = Page::get()->byID($page->ID);
|
|
|
|
|
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->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() {
|
2016-10-25 02:22:31 +02:00
|
|
|
if(class_exists('SiteTreeCMSWorkflow')) {
|
|
|
|
$this->markTestSkipped('Skip if SiteTreeCMSWorkflow installed');
|
|
|
|
}
|
|
|
|
|
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
|
2016-10-25 03:03:45 +02:00
|
|
|
$version = DB::query('SELECT "Version" FROM "SiteTree_Versions" WHERE "Content" = \'test page first version\'')->value();
|
2011-03-18 04:23:47 +01:00
|
|
|
$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'));
|
|
|
|
$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');
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|