function testNotificationEmails()
 {
     WorkflowRequest::$enable_all_alerts = true;
     $page = $this->objFromFixture('SiteTree', 'custompublisherpage');
     $custompublisher = $this->objFromFixture('Member', 'custompublisher');
     $customauthor = $this->objFromFixture('Member', 'customauthor');
     // awaiting approval emails
     $this->session()->inst_set('loggedInAs', $customauthor->ID);
     $wf = $page->openOrNewWorkflowRequest('WorkflowPublicationRequest');
     $this->assertNotNull($wf);
     $wf->request("Can you publish this please?");
     $this->assertEmailSent($custompublisher->Email, $customauthor->Email);
     // published emails
     $this->session()->inst_set('loggedInAs', $custompublisher->ID);
     // doesn't work because onAfterWrite() is not called
     //$page->publish('Stage','Live');
     // Save and publish is an alias for approve
     $wf->saveAndPublish('Looks good');
     $this->assertEmailSent($customauthor->Email, $custompublisher->Email);
     $this->session()->inst_set('loggedInAs', null);
     WorkflowRequest::$enable_all_alerts = false;
 }
 function testWorkflowPublicationApprovalTransition()
 {
     WorkflowRequest::$enable_all_alerts = true;
     $page = $this->objFromFixture('SiteTree', 'custompublisherpage');
     $custompublisher = $this->objFromFixture('Member', 'custompublisher');
     $customapprover = $this->objFromFixture('Member', 'customapprover');
     $customauthor = $this->objFromFixture('Member', 'customauthor');
     // nothing -> awaiting approval
     $customauthor->logIn();
     $request = $page->openOrNewWorkflowRequest('WorkflowPublicationRequest');
     $request->request("ARGGGGG!");
     $this->assertNotNull($request);
     $this->assertEquals($request->AuthorID, $customauthor->ID, "Logged-in member is set as the author of the request");
     $this->assertEquals($request->Status, 'AwaitingApproval', "Request is set to AwaitingApproval after requestPublication() is called");
     // awaiting approval -> approved
     $customapprover->logIn();
     $request->approve('Looks good');
     $this->assertEquals($request->Status, 'Approved', "Request is set to Approved after page is approved");
     $this->assertEquals($request->ApproverID, $customapprover->ID, "Currently logged-in user is set as the Approver for this request");
     // place comment
     $customauthor->logIn();
     $request->comment("YARRRRRR!");
     // approved -> completed
     $custompublisher->logIn();
     $request->publish('Avast, ye scoundrels!', $custompublisher, false);
     $this->assertEquals($request->Status, 'Completed', "Request is set to Completed after page is published");
     $this->assertEquals($request->PublisherID, $custompublisher->ID, "Currently logged-in user is set as the Publisher for this request");
     // Test save and publish
     $this->objFromFixture('Member', 'admin')->logIn();
     $this->assertTrue(is_string($page->openOrNewWorkflowRequest('WorkflowPublicationRequest')->saveAndPublish("S&P")));
     // Test the get_by_* functions. These are cursory tests, covering functionality
     // but none of the multitude of edge cases
     $this->assertContains($page->ID, WorkflowThreeStepRequest::get_by_author('WorkflowPublicationRequest', $customauthor)->column('ID'));
     $this->assertContains($page->ID, WorkflowThreeStepRequest::get_by_approver('WorkflowPublicationRequest', $customapprover)->column('ID'));
     $this->assertContains($page->ID, WorkflowThreeStepRequest::get_by_publisher('WorkflowPublicationRequest', $custompublisher)->column('ID'));
 }