function testWorkflowPublicationApprovalTransition() { WorkflowRequest::$enable_all_alerts = true; $page = $this->objFromFixture('SiteTree', 'custompublisherpage'); $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $customauthor = $this->objFromFixture('Member', 'customauthor'); // awaiting approval $this->session()->inst_set('loggedInAs', $customauthor->ID); $request1 = $page->openOrNewWorkflowRequest('WorkflowPublicationRequest'); $this->assertNotNull($request1); $this->assertEquals($request1->AuthorID, $customauthor->ID, "Logged-in member is set as the author of the request"); $this->assertEquals($request1->Status, 'AwaitingApproval', "Request is set to AwaitingApproval after requestPublication() is called"); $this->assertContains('cms_cancel', array_flip($request1->WorkflowActions()), "Author can cancel own request"); $this->assertNotContains('cms_deny', array_flip($request1->WorkflowActions()), "Author cant deny own request"); $this->session()->inst_set('loggedInAs', $custompublisher->ID); $this->assertContains('cms_cancel', array_flip($request1->WorkflowActions()), "Publisher can cancel requests"); $request1->requestedit('Please make some changes'); $request1->comment('Here are the changes I would like you to do:'); $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertContains('cms_requestpublication', array_flip($request1->WorkflowActions()), "Author can resubmit after request edit"); $request1->request('Resubmit after edits'); $this->session()->inst_set('loggedInAs', $custompublisher->ID); WorkflowRequest::$allow_deny = true; $this->assertContains('cms_deny', array_flip($request1->WorkflowActions()), "Publisher can deny requests when WorkflowRequest::allow_deny is true"); WorkflowRequest::$allow_deny = false; $this->assertNotContains('cms_deny', array_flip($request1->WorkflowActions()), "Publisher can't deny requests when WorkflowRequest::allow_deny is false"); WorkflowRequest::$allow_deny = true; $request1->approve('Looks good'); $this->assertEquals($request1->Status, 'Completed', "Request is set to Completed after page is approved"); $this->assertEquals($request1->PublisherID, $custompublisher->ID, "Currently logged-in user is set as the Publisher for this request"); $this->session()->inst_set('loggedInAs', null); // Make sure the requests can be picked up by the get by author and get by publisher functions $this->assertContains($request1->Page()->ID, WorkflowTwoStepRequest::get_by_publisher('WorkflowPublicationRequest', $custompublisher, array('Completed'))->column('ID')); $this->assertContains($request1->Page()->ID, WorkflowTwoStepRequest::get_by_author('WorkflowPublicationRequest', $customauthor, array('Completed'))->column('ID')); WorkflowRequest::$enable_all_alerts = false; }
function testWorkflowActions() { $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $customapprover = $this->objFromFixture('Member', 'customapprover'); $customauthor = $this->objFromFixture('Member', 'customauthor'); $this->logInAs($customauthor); $page = $this->objFromFixture('SiteTree', 'custompublisherpage'); $request = $page->openOrNewWorkflowRequest('WorkflowPublicationRequest'); WorkflowRequest::$allow_deny = true; // awaiting approval // author $this->logInAs($customauthor); $actions = array_flip($request->WorkflowActions()); $this->assertContains('cms_cancel', $actions); $this->assertContains('cms_comment', $actions); $this->assertNotContains('cms_approve', $actions); $this->assertNotContains('cms_deny', $actions); // approver $this->logInAs($customapprover); $actions = array_flip($request->WorkflowActions()); $this->assertContains('cms_cancel', $actions); $this->assertContains('cms_comment', $actions); $this->assertContains('cms_requestedit', $actions); $this->assertContains('cms_approve', $actions); $this->assertContains('cms_deny', $actions); // publisher $this->logInAs($custompublisher); $actions = array_flip($request->WorkflowActions()); $this->assertContains('cms_cancel', $actions); $this->assertContains('cms_comment', $actions); $this->assertNotContains('cms_requestedit', $actions); $this->assertNotContains('cms_approve', $actions); $this->assertNotContains('cms_deny', $actions); // next status $this->logInAs($customapprover); $request->approve("app"); // approved // author $this->logInAs($customauthor); $actions = array_flip($request->WorkflowActions()); $this->assertContains('cms_cancel', $actions); $this->assertContains('cms_comment', $actions); $this->assertNotContains('cms_approve', $actions); $this->assertNotContains('cms_publish', $actions); $this->assertNotContains('cms_deny', $actions); // approver $this->logInAs($customapprover); $actions = array_flip($request->WorkflowActions()); $this->assertContains('cms_cancel', $actions); $this->assertContains('cms_comment', $actions); $this->assertNotContains('cms_requestedit', $actions); $this->assertNotContains('cms_approve', $actions); $this->assertNotContains('cms_publish', $actions); $this->assertNotContains('cms_deny', $actions); // publisher $this->logInAs($custompublisher); $actions = array_flip($request->WorkflowActions()); $this->assertContains('cms_cancel', $actions); $this->assertContains('cms_comment', $actions); $this->assertContains('cms_requestedit', $actions); $this->assertNotContains('cms_approve', $actions); $this->assertContains('cms_publish', $actions); $this->assertContains('cms_deny', $actions); $request->requestedit("reqed"); // awaiting edit $actions = array_flip($request->WorkflowActions()); $this->assertContains('cms_cancel', $actions); $this->assertContains('cms_comment', $actions); $this->assertContains('cms_requestpublication', $actions); $request->cancel("cancel"); }