1 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 ; 20 21 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 mockReq = createMock(HttpServletRequest .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 85 86 public void testConvertToViewDoesNotImpactAbsoluteAndExternalLinksAndImages() throws RepositoryException { 87 final HttpServletRequest mockReq = createMock(HttpServletRequest .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 mockReq = createMock(HttpServletRequest .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 |