KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > dialog > DialogFckEditTest


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.dialog;
14
15 import junit.framework.TestCase;
16 import static org.easymock.EasyMock.*;
17
18 import javax.jcr.RepositoryException;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20
21 /**
22  * @author gjoseph
23  * @version $Revision: $ ($Author: $)
24  */

25 public class DialogFckEditTest extends TestCase {
26
27     public void testNullsAndBasicCharsAreNotTouchedForJS() {
28         assertEquals("foo bar", new DialogFckEdit().escapeJsValue("foo bar"));
29         assertNull(new DialogFckEdit().escapeJsValue(null));
30     }
31
32     public void testQuotesAreEscapedForJS() {
33         assertEquals("foo\\'bar", new DialogFckEdit().escapeJsValue("foo'bar"));
34         assertEquals("foo\\\"bar", new DialogFckEdit().escapeJsValue("foo\"bar"));
35         assertEquals("fo\\'o\\\"bar", new DialogFckEdit().escapeJsValue("fo'o\"bar"));
36     }
37
38     public void testNewLinesAreEscapedForJS() {
39         assertEquals("foo\\r\\nbar", new DialogFckEdit().escapeJsValue("foo\r\nbar"));
40         assertEquals("foo\\nbar", new DialogFckEdit().escapeJsValue("foo\nbar"));
41         assertEquals("foo\\rbar", new DialogFckEdit().escapeJsValue("foo\rbar"));
42     }
43
44     public void testBackSlashesAreEscapedForJS() {
45         assertEquals("foo\\\\bar", new DialogFckEdit().escapeJsValue("foo\\bar"));
46         assertEquals("Here is a \\\\backslash for Sean", new DialogFckEdit().escapeJsValue("Here is a \\backslash for Sean"));
47     }
48
49     public void testConvertToViewMakesLinksAndImagesPathRelativeToTheContextAndDialogConfig() throws RepositoryException {
50         final HttpServletRequest JavaDoc mockReq = createMock(HttpServletRequest JavaDoc.class);
51         expect(mockReq.getContextPath()).andReturn("/myContextPath/").times(3);
52
53         final DialogFckEdit d = new DialogFckEdit();
54         d.init(mockReq, null, null, null);
55         d.setTopParent(d);
56         d.setConfig("path", "here");
57         replay(mockReq);
58
59         assertEquals("<a HREF=\"/myContextPath/here/bar\">baz</a>", d.convertToView("<a HREF=\"foo/bar\">baz</a>"));
60         assertEquals("<img SRC=\"/myContextPath/here/bar.gif\"/>", d.convertToView("<img SRC=\"foo/bar.gif\"/>"));
61         assertEquals("<img SRC=\"/myContextPath/here/bar.gif\">", d.convertToView("<img SRC=\"foo/bar.gif\">"));
62
63         verify(mockReq);
64     }
65
66     /* TODO : MAGNOLIA-1133
67     public void testConvertToViewMakesLinksAndImagesPathRelativeToTheContext() throws RepositoryException {
68         final HttpServletRequest mockReq = createMock(HttpServletRequest.class);
69         expect(mockReq.getContextPath()).andReturn("/myContextPath").times(3);
70
71         final DialogFckEdit d = new DialogFckEdit();
72         d.init(mockReq, null, null, null);
73         d.setTopParent(d);
74         //d.setConfig("path", "here");
75         replay(mockReq);
76
77         assertEquals("<a HREF=\"/myContextPath/foo/bar\">baz</a>", d.convertToView("<a HREF=\"foo/bar\">baz</a>"));
78         assertEquals("<a HREF=\"/myContextPath/foo/bar/yabadabadoo\">baz</a>", d.convertToView("<a HREF=\"foo/bar/yabadabadoo\">baz</a>"));
79         assertEquals("<img SRC=\"/myContextPath/foo/bar.gif\"/>", d.convertToView("<img SRC=\"foo/bar.gif\"/>"));
80         assertEquals("<img SRC=\"/myContextPath/foo/bar.gif\">", d.convertToView("<img SRC=\"foo/bar.gif\">"));
81
82         verify(mockReq);
83     }
84     */

85
86     public void testConvertToViewDoesNotImpactAbsoluteAndExternalLinksAndImages() throws RepositoryException {
87         final HttpServletRequest JavaDoc mockReq = createMock(HttpServletRequest JavaDoc.class);
88
89         final DialogFckEdit d = new DialogFckEdit();
90         d.init(mockReq, null, null, null);
91         d.setTopParent(d);
92         replay(mockReq);
93
94         assertEquals("<a HREF=\"/foo/bar\">baz</a>", d.convertToView("<a HREF=\"/foo/bar\">baz</a>"));
95         assertEquals("<a HREF=\"http://foo.com/bar\">baz</a>", d.convertToView("<a HREF=\"http://foo.com/bar\">baz</a>"));
96         assertEquals("<a HREF=\"https://foo.com/bar\">baz</a>", d.convertToView("<a HREF=\"https://foo.com/bar\">baz</a>"));
97         assertEquals("<img SRC=\"/foo/bar.gif\"/>", d.convertToView("<img SRC=\"/foo/bar.gif\"/>"));
98         assertEquals("<img SRC=\"http://foo.com/bar/baz.gif\">", d.convertToView("<img SRC=\"http://foo.com/bar/baz.gif\">"));
99         assertEquals("<img SRC=\"https://foo.com/bar/baz.gif\">", d.convertToView("<img SRC=\"https://foo.com/bar/baz.gif\">"));
100
101         verify(mockReq);
102     }
103
104     public void testConvertToViewDoesNotConvertMailtoLinks() throws RepositoryException {
105         final HttpServletRequest JavaDoc mockReq = createMock(HttpServletRequest JavaDoc.class);
106
107         final DialogFckEdit d = new DialogFckEdit();
108         d.init(mockReq, null, null, null);
109         d.setTopParent(d);
110         replay(mockReq);
111
112         assertEquals("<a HREF=\"mailto:lieutenant@columbo.net\">mail me !</a>", d.convertToView("<a HREF=\"mailto:lieutenant@columbo.net\">mail me !</a>"));
113
114         verify(mockReq);
115     }
116 }
117
Popular Tags