Source of file SiteTreeCMSWorkflowTest.php
Size: 11,308 Bytes - Last Modified: 2021-12-23T10:28:49+00:00
/var/www/docs.ssmods.com/process/src/tests/SiteTreeCMSWorkflowTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 | <?php /** * @package cmsworkflow * @subpackage tests */ class SiteTreeCMSWorkflowTest extends FunctionalTest { /** * Created in setUp() to ensure defaults are created *before* inserting new fixtures, * as they rely on certain default groups being present. */ public static $fixture_file = 'cmsworkflow/tests/SiteTreeCMSWorkflowTest.yml'; protected $requireDefaultRecordsFrom = array('SiteTreeCMSTwoStepWorkflow'); protected $requiredExtensions = array( 'SiteTree' => array('SiteTreeCMSTwoStepWorkflow'), 'SiteConfig' => array('SiteConfigTwoStepWorkflow'), 'WorkflowRequest' => array('WorkflowTwoStepRequest'), ); protected $illegalExtensions = array( 'SiteTree' => array('SiteTreeCMSThreeStepWorkflow'), 'WorkflowRequest' => array('WorkflowThreeStepRequest'), 'LeftAndMain' => array('LeftAndMainCMSThreeStepWorkflow'), 'SiteConfig' => array('SiteConfigThreeStepWorkflow'), ); // function setUp() { // parent::setUp(); // // // default records are not created in TestRunner by default // singleton('SiteTreeCMSTwoStepWorkflow')->augmentDefaultRecords(); // $fixtureFile = 'cmsworkflow/tests/SiteTreeCMSWorkflowTest.yml'; // $fixture = new YamlFixture($fixtureFile); // $fixture->saveIntoDatabase(); // // Duplicated to be compatible with 2.3 and 2.4 // $this->fixtures = array($fixture); // $this->fixture = $fixture; // } public function testAlternateCanPublishLimitsToPublisherGroups() { $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; // Check for default record group assignments $defaultpublisherspage = $this->objFromFixture('SiteTree', 'defaultpublisherspage'); $defaultpublishersgroup = DataObject::get_one('Group', "{$bt}Code{$bt} = 'site-content-publishers'"); $defaultpublisher = $this->objFromFixture('Member', 'defaultpublisher'); // Workaround because defaults aren't written in unit tests $defaultpublisher->Groups()->add($defaultpublishersgroup); $gs = $defaultpublisher->Groups(); $this->assertTrue( $defaultpublisherspage->canPublish($defaultpublisher), 'Default publisher groups are assigned to new records' ); // Check for random user publish permissions $randomUser = $this->objFromFixture('Member', 'randomuser'); $this->assertFalse( $defaultpublisherspage->canPublish($randomUser), 'Users which are not in publisher groups cant publish new pages' ); // Check for custom page group assignments $custompublisherspage = $this->objFromFixture('SiteTree', 'custompublisherpage'); $custompublishersgroup = $this->objFromFixture('Group', 'custompublishergroup'); $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $custompublisher->Groups()->add($custompublishersgroup); $this->assertTrue( $custompublisherspage->canPublish($custompublisher), 'Default publisher groups are assigned to new records' ); } public function testAccessTabOnlyDisplaysWithGrantAccessPermissions() { $page = $this->objFromFixture('SiteTree', 'custompublisherpage'); $customauthor = $this->objFromFixture('Member', 'customauthor'); $this->session()->inst_set('loggedInAs', $customauthor->ID); $fields = $page->getCMSFields(); $this->assertTrue( $fields->dataFieldByName('CanPublishType')->isReadonly(), 'Users with publish or SITETREE_GRANT_ACCESS permission can change "publish" group assignments in cms fields' ); $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $this->session()->inst_set('loggedInAs', $custompublisher->ID); $fields = $page->getCMSFields(); $this->assertFalse( $fields->dataFieldByName('CanPublishType')->isReadonly(), 'Users without publish or SITETREE_GRANT_ACCESS permission cannot change "publish" group assignments in cms fields' ); $this->session()->inst_set('loggedInAs', null); } public function testCmsActionsLimited() { // For 2.3 and 2.4 compatibility $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; $custompublisherspage = $this->objFromFixture('SiteTree', 'custompublisherpage'); $custompublishersgroup = $this->objFromFixture('Group', 'custompublishergroup'); $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $workflowadmin = $this->objFromFixture('Member', 'workflowadmin'); $custompublisher->Groups()->add($custompublishersgroup); $customauthorsgroup = $this->objFromFixture('Group', 'customauthorsgroup'); $customauthor = $this->objFromFixture('Member', 'customauthor'); $customauthor->Groups()->add($customauthorsgroup); $unpublishedRecord = new Page(); $unpublishedRecord->CanEditType = 'LoggedInUsers'; $unpublishedRecord->write(); $unpublishedRecord->PublisherGroups()->add($custompublishersgroup); $custompublisher->logIn(); $publishedRecord = new Page(); $publishedRecord->CanEditType = 'LoggedInUsers'; $publishedRecord->write(); $publishedRecord->doPublish(); $publishedRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromLiveRecord = new Page(); $deletedFromLiveRecord->CanEditType = 'LoggedInUsers'; $deletedFromLiveRecord->write(); $deletedFromLiveRecord->doPublish(); $deletedFromLiveRecord->deleteFromStage('Live'); $deletedFromLiveRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromStageRecord = new Page(); $deletedFromStageRecord->CanEditType = 'LoggedInUsers'; $deletedFromStageRecord->write(); $deletedFromStageRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromStageRecord->doPublish(); $deletedFromStageRecordID = $deletedFromStageRecord->ID; $deletedFromStageRecord->deleteFromStage('Stage'); $deletedFromStageRecord = Versioned::get_one_by_stage("SiteTree", "Live", "{$bt}SiteTree{$bt}.{$bt}ID{$bt} = $deletedFromStageRecordID"); $changedOnStageRecord = new Page(); $changedOnStageRecord->CanEditType = 'LoggedInUsers'; $changedOnStageRecord->write(); $changedOnStageRecord->publish('Stage', 'Live'); $changedOnStageRecord->Content = 'Changed on Stage'; $changedOnStageRecord->write(); $changedOnStageRecord->PublisherGroups()->add($custompublishersgroup); // test "publish" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertNotContains( 'action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button' ); $this->assertNotContains( 'action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button' ); $this->assertNotContains( 'action_publish', $deletedFromLiveRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button' ); $this->assertNotContains( 'action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button' ); // test "publish" action for publisher $this->session()->inst_set('loggedInAs', $custompublisher->ID); WorkflowRequest::set_force_publishers_to_use_workflow(false); $this->assertContains( 'action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button' ); $this->assertContains( 'action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button' ); $this->assertContains( 'action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button' ); WorkflowRequest::set_force_publishers_to_use_workflow(true); $this->assertFalse( in_array('action_publish', $unpublishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow' ); $this->assertFalse( in_array('action_publish', $publishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow' ); $this->assertFalse( in_array('action_publish', $changedOnStageRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow' ); // test "request publication" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertContains( 'action_cms_requestpublication', $unpublishedRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page is not published' ); $this->assertNotContains( 'action_cms_requestpublication', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request publication button if page has been published but not altered on stage' ); $this->assertContains( 'action_cms_requestpublication', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page has been changed on stage' ); // test "request removal" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertNotContains( 'action_cms_requestdeletefromlive', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page hasnt been altered' ); $this->assertNotContains( 'action_cms_requestdeletefromlive', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been published but not altered on stage' ); $this->assertNotContains( 'action_cms_requestdeletefromlive', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been changed on stage but not deleted from stage' ); // test "request removal" action for publisher $this->session()->inst_set('loggedInAs', $custompublisher->ID); // reset login $this->session()->inst_set('loggedInAs', null); } } |