001: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: // Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.responders.editing;
004:
005: import fitnesse.*;
006: import fitnesse.testutil.AbstractRegex;
007: import fitnesse.wiki.*;
008: import fitnesse.http.*;
009:
010: public class PropertiesResponderTest extends AbstractRegex {
011: private WikiPage root;
012:
013: private PageCrawler crawler;
014:
015: private MockRequest request;
016:
017: private Responder responder;
018:
019: private SimpleResponse response;
020:
021: private String content;
022:
023: public void setUp() throws Exception {
024: root = InMemoryPage.makeRoot("RooT");
025: crawler = root.getPageCrawler();
026: }
027:
028: public void testResponse() throws Exception {
029: WikiPage page = crawler.addPage(root, PathParser
030: .parse("PageOne"));
031: PageData data = page.getData();
032: data.setContent("some content");
033: WikiPageProperties properties = data.getProperties();
034: properties.set(WikiPage.ACTION_TEST, "true");
035: properties.set(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE,
036: "http://www.fitnesse.org");
037: page.commit(data);
038:
039: MockRequest request = new MockRequest();
040: request.setResource("PageOne");
041:
042: Responder responder = new PropertiesResponder();
043: SimpleResponse response = (SimpleResponse) responder
044: .makeResponse(new FitNesseContext(root), request);
045: assertEquals("max-age=0", response.getHeader("Cache-Control"));
046:
047: String content = response.getContent();
048: assertSubString("PageOne", content);
049: assertSubString("value=\"http://www.fitnesse.org\"", content);
050: assertDoesntHaveRegexp("textarea name=\"extensionXml\"",
051: content);
052: assertHasRegexp("<input.*value=\"Save Properties\".*>", content);
053:
054: assertHasRegexp("<input.*value=\"saveProperties\"", content);
055:
056: assertSubString(
057: "<input type=\"checkbox\" name=\"Test\" checked=\"true\"/>",
058: content);
059: assertSubString("<input type=\"checkbox\" name=\"Search\"",
060: content);
061: assertSubString(
062: "<input type=\"checkbox\" name=\"Edit\" checked=\"true\"/>",
063: content);
064: assertSubString("<input type=\"checkbox\" name=\"Suite\"/>",
065: content);
066: assertSubString("<input type=\"checkbox\" name=\"Versions\"",
067: content);
068: assertSubString("<input type=\"checkbox\" name=\"Refactor\"",
069: content);
070: assertSubString("<input type=\"checkbox\" name=\"WhereUsed\"",
071: content);
072: assertSubString(
073: "<input type=\"checkbox\" name=\"RecentChanges\"",
074: content);
075:
076: assertSubString("<input type=\"checkbox\" name=\""
077: + WikiPage.SECURE_READ + "\"/>", content);
078: assertSubString("<input type=\"checkbox\" name=\""
079: + WikiPage.SECURE_WRITE + "\"/>", content);
080: assertSubString("<input type=\"checkbox\" name=\""
081: + WikiPage.SECURE_TEST + "\"/>", content);
082: }
083:
084: public void testGetVirtualWikiValue() throws Exception {
085: WikiPage page = crawler.addPage(root, PathParser
086: .parse("PageOne"));
087: PageData data = page.getData();
088:
089: assertEquals("", PropertiesResponder.getVirtualWikiValue(data));
090:
091: data.setAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE,
092: "http://www.objectmentor.com");
093: assertEquals("http://www.objectmentor.com", PropertiesResponder
094: .getVirtualWikiValue(data));
095: }
096:
097: public void testUsernameDisplayed() throws Exception {
098: WikiPage page = getContentFromSimplePropertiesPage();
099:
100: assertSubString("Last modified anonymously", content);
101:
102: PageData data = page.getData();
103: data.setAttribute(WikiPage.LAST_MODIFYING_USER, "Bill");
104: page.commit(data);
105:
106: request.setResource("SomePage");
107: response = (SimpleResponse) responder.makeResponse(
108: new FitNesseContext(root), request);
109: content = response.getContent();
110:
111: assertSubString("Last modified by Bill", content);
112: }
113:
114: private WikiPage getContentFromSimplePropertiesPage()
115: throws Exception {
116: WikiPage page = root.addChildPage("SomePage");
117:
118: return getPropertiesContentFromPage(page);
119: }
120:
121: private WikiPage getPropertiesContentFromPage(WikiPage page)
122: throws Exception {
123: request = new MockRequest();
124: request.setResource(page.getName());
125: responder = new PropertiesResponder();
126: response = (SimpleResponse) responder.makeResponse(
127: new FitNesseContext(root), request);
128: content = response.getContent();
129: return page;
130: }
131:
132: public void testWikiImportForm() throws Exception {
133: getContentFromSimplePropertiesPage();
134:
135: checkUpdateForm();
136: assertSubString("Wiki Import.", content);
137: assertSubString("value=\"Import\"", content);
138: assertSubString("type=\"text\"", content);
139: assertSubString("name=\"remoteUrl\"", content);
140: }
141:
142: private void checkUpdateForm() {
143: assertSubString("<form", content);
144: assertSubString("action=\"SomePage#end\"", content);
145: assertSubString("<input", content);
146: assertSubString("type=\"hidden\"", content);
147: assertSubString("name=\"responder\"", content);
148: assertSubString("value=\"import\"", content);
149: }
150:
151: public void testWikiImportUpdate() throws Exception {
152: testWikiImportUpdateWith("WikiImportRoot");
153: assertSubString(" imports its subpages from ", content);
154: assertSubString("value=\"Update Subpages\"", content);
155: }
156:
157: public void testWikiImportUpdateNonroot() throws Exception {
158: testWikiImportUpdateWith("WikiImportSource");
159: assertSubString(" imports its content and subpages from ",
160: content);
161: assertSubString("value=\"Update Content and Subpages\"",
162: content);
163: }
164:
165: private void testWikiImportUpdateWith(String propertyName)
166: throws Exception {
167: WikiPage page = root.addChildPage("SomePage");
168: PageData data = page.getData();
169: data.setAttribute(propertyName, "http://my.host.com/PageRoot");
170: page.commit(data);
171:
172: getPropertiesContentFromPage(page);
173: checkUpdateForm();
174: assertSubString("Wiki Import Update.", content);
175: assertSubString(
176: "<a href=\"http://my.host.com/PageRoot\">http://my.host.com/PageRoot</a>",
177: content);
178:
179: assertNotSubString("value=\"Import\"", content);
180: }
181:
182: public void testSymbolicLinkForm() throws Exception {
183: getContentFromSimplePropertiesPage();
184:
185: assertSubString("Symbolic Links", content);
186: assertSubString(
187: "<input type=\"hidden\" name=\"responder\" value=\"symlink\"/>",
188: content);
189: assertSubString("<input type=\"text\" name=\"linkName\"/>",
190: content);
191: assertSubString("<input type=\"text\" name=\"linkPath\"",
192: content);
193: assertSubString(
194: "<input type=\"submit\" name=\"submit\" value=\"Create Symbolic Link\"/>",
195: content);
196: }
197:
198: public void testSybolicLinkList() throws Exception {
199: WikiPage page = root.addChildPage("SomePage");
200: PageData data = page.getData();
201: WikiPageProperties props = data.getProperties();
202: props.addSymbolicLink("LinkOne", PathParser
203: .parse("PatH.ToAnother.PagE"));
204: props.addSymbolicLink("LinkTwo", PathParser
205: .parse("PatH.ToYetAnother.PagE"));
206: page.commit(data);
207:
208: getPropertiesContentFromPage(page);
209:
210: assertSubString("LinkOne", content);
211: assertSubString(
212: "<a href=\"SomePage?responder=symlink&removal=LinkOne\">remove</a>",
213: content);
214: assertSubString("LinkTwo", content);
215: assertSubString(
216: "<a href=\"SomePage?responder=symlink&removal=LinkTwo\">remove</a>",
217: content);
218: }
219:
220: public void testActionPropertiesHtml() throws Exception {
221: WikiPage page = root.addChildPage("SomePage");
222: PageData data = page.getData();
223: String html = new PropertiesResponder()
224: .makeTestActionCheckboxesHtml(data).html();
225: assertSubString(
226: "<div style=\"float: left; width: 150px;\">Actions:",
227: html);
228: assertSubString("Actions:", html);
229: assertSubString(
230: "<input type=\"checkbox\" name=\"Test\"/> - Test", html);
231: assertSubString(
232: "<input type=\"checkbox\" name=\"Suite\"/> - Suite",
233: html);
234: assertSubString(
235: "<input type=\"checkbox\" name=\"Edit\" checked=\"true\"/> - Edit",
236: html);
237: assertSubString(
238: "<input type=\"checkbox\" name=\"Versions\"/> - Versions",
239: html);
240: assertSubString(
241: "<input type=\"checkbox\" name=\"Refactor\" checked=\"true\"/> - Refactor",
242: html);
243: assertSubString(
244: "<input type=\"checkbox\" name=\"WhereUsed\"/> - WhereUsed",
245: html);
246: }
247:
248: public void testMakeNavigationPropertiesHtml() throws Exception {
249: WikiPage page = root.addChildPage("SomePage");
250: PageData data = page.getData();
251: String html = new PropertiesResponder()
252: .makeNavigationCheckboxesHtml(data).html();
253: assertSubString(
254: "<div style=\"float: left; width: 150px;\">Navigation:",
255: html);
256: assertSubString(
257: "<input type=\"checkbox\" name=\"Files\"/> - Files",
258: html);
259: assertSubString(
260: "<input type=\"checkbox\" name=\"RecentChanges\"/> - RecentChanges",
261: html);
262: assertSubString(
263: "<input type=\"checkbox\" name=\"Search\"/> - Search",
264: html);
265: }
266:
267: public void testMakeSecurityPropertiesHtml() throws Exception {
268: WikiPage page = root.addChildPage("SomePage");
269: PageData data = page.getData();
270: String html = new PropertiesResponder()
271: .makeSecurityCheckboxesHtml(data).html();
272: assertSubString(
273: "<div style=\"float: left; width: 150px;\">Security:",
274: html);
275: assertSubString(
276: "<input type=\"checkbox\" name=\"secure-read\"/> - secure-read",
277: html);
278: assertSubString(
279: "<input type=\"checkbox\" name=\"secure-write\"/> - secure-write",
280: html);
281: assertSubString(
282: "<input type=\"checkbox\" name=\"secure-test\"/> - secure-test",
283: html);
284: }
285: }
|