1 4 package com.openedit.modules.workflow; 5 6 import java.util.List ; 7 8 import com.openedit.BaseTestCase; 9 import com.openedit.WebPageRequest; 10 import com.openedit.modules.html.EditorSession; 11 import com.openedit.modules.html.HtmlEditorModule; 12 import com.openedit.page.Page; 13 import com.openedit.users.User; 14 15 public class WorkFlowTest extends BaseTestCase 16 { 17 public void testEditDraft() throws Exception  18 { 19 WebPageRequest req = getFixture().createPageRequest("/index.html"); 20 User user = getFixture().getUserManager().getUser("usesdraft"); 21 req.setUser(user); 22 HtmlEditorModule mod = (HtmlEditorModule)getModule("HtmlEditor"); 23 24 req.setRequestParameter("editPath", "/index.html"); 25 mod.loadView(req); 26 27 EditorSession ses = (EditorSession)req.getPageValue("editorSession"); 28 29 assertEquals( "/index.draft.html",ses.getEditPath()); 30 req.setRequestParameter("editPath", ses.getEditPath()); 31 req.setRequestParameter("saveas", ses.getEditPath()); 32 req.setRequestParameter("content", "New Draft Content"); 33 mod.save(req); 34 35 Page page = getPage("/index.draft.html"); 37 assertTrue("draft missing", page.exists() ); 38 39 41 44 } 47 public void testListDrafts() throws Exception  48 { 49 WebPageRequest req = getFixture().createPageRequest(); 50 51 WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow"); 52 List drafts = mod.listDrafts(req); 53 54 55 assertTrue("Missing list " + drafts.size(), drafts.size() > 0); 56 57 } 58 59 public void testApprove() throws Exception  60 { 61 WebPageRequest req = getFixture().createPageRequest("/index.draft.html"); 62 63 WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow"); 64 req.setRequestParameter("editPath", "/index.draft.html"); 65 req.setRequestParameter("origURL", "/index.html"); 66 mod.approve(req); 67 68 assertTrue("Did not redirect", req.hasRedirected() ); 69 } 70 71 public void testChangeDraftMode() throws Exception  72 { 73 WebPageRequest req = getFixture().createPageRequest(); 74 75 WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow"); 76 assertFalse("Was in draft mode", req.getUser().hasProperty("oe.edit.draftmode")); 77 mod.flipDraftMode(req); 78 assertTrue("Was Not in draft mode", req.getUser().hasProperty("oe.edit.draftmode")); 79 80 } 81 82 public void testChangeStatus() throws Exception  83 { 84 88 Page live = getFixture().getPageManager().getPage("/index.html"); 89 Page draft = getFixture().getPageManager().getPage("/index.draft.html"); 90 getFixture().getPageManager().copyPage(live, draft); 91 92 93 User level1user = getFixture().getUserManager().getUser("level1user"); 94 WebPageRequest req = getFixture().createPageRequest(); 95 req.setUser(level1user); 96 req.setRequestParameter("editPath", "/index.draft.html"); 97 req.setRequestParameter("origURL", "/index.html"); 98 WorkFlowModule mod = (WorkFlowModule)getModule("WorkFlow"); 99 mod.approve(req); 100 101 assertTrue( draft.exists() ); 102 boolean nope = mod.getWorkFlow().canApprove(level1user, draft); 103 assertFalse( nope); 104 105 boolean yup = mod.getWorkFlow().canApprove(getFixture().getUserManager().getUser("admin"), draft); 106 assertTrue(yup); 107 110 111 } 115 } 116 | Popular Tags |