01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import fitnesse.wiki.*;
06: import java.util.*;
07:
08: //created by Jason Sypher
09:
10: public class LastModifiedWidgetTest extends AbstractWidget {
11: private WikiPage root;
12:
13: private WikiPage page;
14:
15: private LastModifiedWidget widget;
16:
17: public void setUp() throws Exception {
18: root = InMemoryPage.makeRoot("RooT");
19: page = root.getPageCrawler().addPage(root,
20: PathParser.parse("SomePage"), "some text");
21: widget = new LastModifiedWidget(new WidgetRoot(page),
22: "!lastmodified");
23: }
24:
25: public void testRegularExpression() throws Exception {
26: assertMatchEquals("!lastmodified", "!lastmodified");
27: }
28:
29: public void testResults() throws Exception {
30: setUp();
31: Date date = page.getData().getLastModificationTime();
32: String formattedDate = LastModifiedWidget.formatDate(date);
33: assertHasRegexp(formattedDate, widget.render());
34: }
35:
36: public void testDateFormat() throws Exception {
37: GregorianCalendar date = new GregorianCalendar(2003, 3, 1, 11,
38: 41, 30);
39: String formattedDate = LastModifiedWidget.formatDate(date
40: .getTime());
41: assertEquals("Apr 01, 2003 at 11:41:30 AM", formattedDate);
42: }
43:
44: public void testDefaultUsername() throws Exception {
45: assertSubString("Last modified anonymously", widget.render());
46: }
47:
48: public void testUsername() throws Exception {
49: PageData data = page.getData();
50: data.setAttribute(WikiPage.LAST_MODIFYING_USER, "Aladdin");
51: page.commit(data);
52:
53: assertSubString("Last modified by Aladdin", widget.render());
54: }
55:
56: protected String getRegexp() {
57: return LastModifiedWidget.REGEXP;
58: }
59:
60: }
|