2011-03-18 04:23:47 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
namespace SilverStripe\CMS\Tests\Model;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2016-10-25 02:22:31 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\DB;
|
2016-10-25 02:22:31 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\Security\Security;
|
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-08-23 04:36:06 +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
|
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
class SiteTreeActionsTest extends FunctionalTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'SiteTreeActionsTest.yml';
|
|
|
|
|
|
|
|
public function testActionsReadonly()
|
|
|
|
{
|
|
|
|
// Publish record
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$page = new SiteTreeActionsTest_Page();
|
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
|
|
|
$page->publishRecursive();
|
|
|
|
|
|
|
|
// Log in as another user
|
|
|
|
$readonlyEditor = $this->objFromFixture(Member::class, 'cmsreadonlyeditor');
|
2017-05-21 05:15:00 +02:00
|
|
|
Security::setCurrentUser($readonlyEditor);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// Reload latest version
|
2018-05-04 03:04:18 +02:00
|
|
|
$page = SiteTree::get()->byID($page->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_archive'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testActionsNoDeletePublishedRecord()
|
|
|
|
{
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
|
|
|
|
$page = new SiteTreeActionsTest_Page();
|
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
|
|
|
$pageID = $page->ID;
|
|
|
|
$page->publishRecursive();
|
|
|
|
$page->deleteFromStage(Versioned::DRAFT);
|
|
|
|
|
|
|
|
// Get the live version of the page
|
|
|
|
$page = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $pageID");
|
|
|
|
$this->assertInstanceOf(SiteTree::class, $page);
|
|
|
|
|
|
|
|
// Check that someone without the right permission can't delete the page
|
|
|
|
$editor = $this->objFromFixture(Member::class, 'cmsnodeleteeditor');
|
2017-05-21 05:15:00 +02:00
|
|
|
Security::setCurrentUser($editor);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_archive'));
|
|
|
|
|
|
|
|
// Check that someone with the right permission can delete the page
|
|
|
|
/** @var Member $member */
|
|
|
|
$member = $this->objFromFixture(Member::class, 'cmseditor');
|
2017-05-21 05:15:00 +02:00
|
|
|
Security::setCurrentUser($member);
|
2017-01-25 21:59:25 +01:00
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testActionsPublishedRecord()
|
|
|
|
{
|
|
|
|
$author = $this->objFromFixture(Member::class, 'cmseditor');
|
2017-05-21 05:15:00 +02:00
|
|
|
Security::setCurrentUser($author);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-05-04 03:04:18 +02:00
|
|
|
/** @var SiteTree $page */
|
|
|
|
$page = new SiteTree();
|
2017-01-25 21:59:25 +01:00
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
|
|
|
$page->publishRecursive();
|
|
|
|
|
|
|
|
// Reload latest version
|
2018-05-04 03:04:18 +02:00
|
|
|
$page = SiteTree::get()->byID($page->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testActionsDeletedFromStageRecord()
|
|
|
|
{
|
|
|
|
$author = $this->objFromFixture(Member::class, 'cmseditor');
|
2017-05-21 05:15:00 +02:00
|
|
|
Security::setCurrentUser($author);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-05-04 03:04:18 +02:00
|
|
|
$page = new SiteTree();
|
2017-01-25 21:59:25 +01:00
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
|
|
|
$this->assertTrue($page->canPublish());
|
|
|
|
$pageID = $page->ID;
|
|
|
|
$page->publishRecursive();
|
|
|
|
$page->deleteFromStage('Stage');
|
|
|
|
|
|
|
|
// Get the live version of the page
|
|
|
|
$page = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $pageID");
|
|
|
|
$this->assertInstanceOf(SiteTree::class, $page);
|
|
|
|
|
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_unpublish'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_revert'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testActionsChangedOnStageRecord()
|
|
|
|
{
|
|
|
|
$author = $this->objFromFixture(Member::class, 'cmseditor');
|
2017-05-21 05:15:00 +02:00
|
|
|
Security::setCurrentUser($author);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-05-04 03:04:18 +02:00
|
|
|
$page = new SiteTree();
|
2017-01-25 21:59:25 +01:00
|
|
|
$page->CanEditType = 'LoggedInUsers';
|
|
|
|
$page->write();
|
|
|
|
$this->assertTrue($page->canPublish());
|
|
|
|
$page->publishRecursive();
|
|
|
|
$page->Content = 'Changed on Stage';
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
|
|
|
|
// Reload latest version
|
2018-05-04 03:04:18 +02:00
|
|
|
$page = SiteTree::get()->byID($page->ID);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$actions = $page->getCMSActions();
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_save'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_publish'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_archive'));
|
|
|
|
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
|
|
|
|
$this->assertNull($actions->dataFieldByName('action_revert'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testActionsViewingOldVersion()
|
|
|
|
{
|
2018-05-04 03:04:18 +02:00
|
|
|
$p = new SiteTree();
|
2017-01-25 21:59:25 +01:00
|
|
|
$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
|
2018-05-04 03:04:18 +02:00
|
|
|
$version = DB::query(
|
|
|
|
'SELECT "Version" FROM "SiteTree_Versions" WHERE "Content" = \'test page first version\''
|
|
|
|
)->value();
|
|
|
|
$old = Versioned::get_version(SiteTree::class, $p->ID, $version);
|
2017-01-25 21:59:25 +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
|
|
|
}
|