📄 translatorreadertest.java
字号:
throws Exception { String src = "This should be a [link|http://www.regex.fi/]"; assertEquals( "This should be a <a class=\"external\" href=\"http://www.regex.fi/\">link</a>", translate(src) ); } public void testHyperlinksExtNofollow() throws Exception { String src = "This should be a [link|http://www.regex.fi/]"; assertEquals( "This should be a <a class=\"external\" rel=\"nofollow\" href=\"http://www.regex.fi/\">link</a>", translate_nofollow(src) ); } // // Testing various odds and ends about hyperlink matching. // public void testHyperlinksPluralMatch() throws Exception { String src = "This should be a [HyperLinks]"; newPage("HyperLink"); assertEquals( "This should be a <a class=\"wikipage\" href=\"Wiki.jsp?page=HyperLink\">HyperLinks</a>", translate(src) ); } public void testHyperlinksPluralMatch2() throws Exception { String src = "This should be a [HyperLinks]"; assertEquals( "This should be a <a class=\"editpage\" title=\"Create 'HyperLinks'\" href=\"Edit.jsp?page=HyperLinks\">HyperLinks</a>", translate(src) ); } public void testHyperlinksPluralMatch3() throws Exception { String src = "This should be a [HyperLink]"; newPage("HyperLinks"); assertEquals( "This should be a <a class=\"wikipage\" href=\"Wiki.jsp?page=HyperLinks\">HyperLink</a>", translate(src) ); } public void testHyperlinkJS1() throws Exception { String src = "This should be a [link|http://www.haxored.com/\" onMouseOver=\"alert('Hahhaa');\"]"; assertEquals( "This should be a <a class=\"external\" href=\"http://www.haxored.com/" onMouseOver="alert('Hahhaa');"\">link</a>", translate(src) ); } public void testHyperlinksInterWiki1() throws Exception { String src = "This should be a [link|JSPWiki:HyperLink]"; assertEquals( "This should be a <a class=\"interwiki\" href=\"http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=HyperLink\">link</a>", translate(src) ); } public void testAttachmentLink() throws Exception { newPage("Test"); Attachment att = new Attachment( "Test", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "This should be an [attachment link|Test/TestAtt.txt]"; assertEquals( "This should be an <a class=\"attachment\" href=\"attach/Test/TestAtt.txt\">attachment link</a>"+ "<a href=\"PageInfo.jsp?page=Test/TestAtt.txt\"><img src=\"images/attachment_small.png\" border=\"0\" alt=\"(info)\"/></a>", translate(src)); } public void testAttachmentLink2() throws Exception { props.setProperty( "jspwiki.encoding", "ISO-8859-1" ); //TODO TestEngine testEngine2 = new TestEngine( props ); testEngine2.saveText( "Test", "foo "); created.addElement( "Test" ); Attachment att = new Attachment( "Test", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine2.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "This should be an [attachment link|Test/TestAtt.txt]"; assertEquals( "This should be an <a class=\"attachment\" href=\"attach/Test/TestAtt.txt\">attachment link</a>"+ "<a href=\"PageInfo.jsp?page=Test/TestAtt.txt\"><img src=\"images/attachment_small.png\" border=\"0\" alt=\"(info)\"/></a>", translate(testEngine2,src)); } /** * Are attachments parsed correctly also when using gappy text? */ public void testAttachmentLink3() throws Exception { TestEngine testEngine2 = new TestEngine( props ); testEngine2.saveText( "TestPage", "foo "); created.addElement( "TestPage" ); Attachment att = new Attachment( "TestPage", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine2.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "[Test page/TestAtt.txt]"; assertEquals( "<a class=\"attachment\" href=\"attach/TestPage/TestAtt.txt\">Test page/TestAtt.txt</a>"+ "<a href=\"PageInfo.jsp?page=TestPage/TestAtt.txt\"><img src=\"images/attachment_small.png\" border=\"0\" alt=\"(info)\"/></a>", translate(testEngine2,src)); } public void testAttachmentLink4() throws Exception { TestEngine testEngine2 = new TestEngine( props ); testEngine2.saveText( "TestPage", "foo "); created.addElement( "TestPage" ); Attachment att = new Attachment( "TestPage", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine2.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "["+testEngine2.beautifyTitle("TestPage/TestAtt.txt")+"]"; assertEquals( "<a class=\"attachment\" href=\"attach/TestPage/TestAtt.txt\">TestPage/TestAtt.txt</a>"+ "<a href=\"PageInfo.jsp?page=TestPage/TestAtt.txt\"><img src=\"images/attachment_small.png\" border=\"0\" alt=\"(info)\"/></a>", translate(testEngine2,src)); } public void testNoHyperlink() throws Exception { newPage("HyperLink"); String src = "This should not be a [[HyperLink]"; assertEquals( "This should not be a [HyperLink]", translate(src) ); } public void testNoHyperlink2() throws Exception { String src = "This should not be a [[[[HyperLink]"; assertEquals( "This should not be a [[[HyperLink]", translate(src) ); } public void testNoHyperlink3() throws Exception { String src = "[[HyperLink], and this [[Neither]."; assertEquals( "[HyperLink], and this [Neither].", translate(src) ); } public void testNoPlugin() throws Exception { String src = "There is [[{NoPlugin}] here."; assertEquals( "There is [{NoPlugin}] here.", translate(src) ); } public void testErroneousHyperlink() throws Exception { String src = "What if this is the last char ["; assertEquals( "What if this is the last char ", translate(src) ); } public void testErroneousHyperlink2() throws Exception { String src = "What if this is the last char [["; assertEquals( "What if this is the last char [", translate(src) ); } public void testExtraPagename1() throws Exception { String src = "Link [test_page]"; newPage("Test_page"); assertEquals("Link <a class=\"wikipage\" href=\"Wiki.jsp?page=Test_page\">test_page</a>", translate(src) ); } public void testExtraPagename2() throws Exception { String src = "Link [test.page]"; newPage("Test.page"); assertEquals("Link <a class=\"wikipage\" href=\"Wiki.jsp?page=Test.page\">test.page</a>", translate(src) ); } public void testExtraPagename3() throws Exception { String src = "Link [.testpage_]"; newPage(".testpage_"); assertEquals("Link <a class=\"wikipage\" href=\"Wiki.jsp?page=.testpage_\">.testpage_</a>", translate(src) ); } public void testInlineImages() throws Exception { String src = "Link [test|http://www.ecyrd.com/test.png]"; assertEquals("Link <img class=\"inline\" src=\"http://www.ecyrd.com/test.png\" alt=\"test\" />", translate(src) ); } public void testInlineImages2() throws Exception { String src = "Link [test|http://www.ecyrd.com/test.ppm]"; assertEquals("Link <a class=\"external\" href=\"http://www.ecyrd.com/test.ppm\">test</a>", translate(src) ); } public void testInlineImages3() throws Exception { String src = "Link [test|http://images.com/testi]"; assertEquals("Link <img class=\"inline\" src=\"http://images.com/testi\" alt=\"test\" />", translate(src) ); } public void testInlineImages4() throws Exception { String src = "Link [test|http://foobar.jpg]"; assertEquals("Link <img class=\"inline\" src=\"http://foobar.jpg\" alt=\"test\" />", translate(src) ); } // No link text should be just embedded link. public void testInlineImagesLink2() throws Exception { String src = "Link [http://foobar.jpg]"; assertEquals("Link <img class=\"inline\" src=\"http://foobar.jpg\" alt=\"http://foobar.jpg\" />", translate(src) ); } public void testInlineImagesLink() throws Exception { String src = "Link [http://link.to/|http://foobar.jpg]"; assertEquals("Link <a href=\"http://link.to/\"><img class=\"inline\" src=\"http://foobar.jpg\" alt=\"http://link.to/\"/></a>", translate(src) ); } public void testInlineImagesLink3() throws Exception { String src = "Link [SandBox|http://foobar.jpg]"; newPage("SandBox"); assertEquals("Link <a class=\"wikipage\" href=\"Wiki.jsp?page=SandBox\"><img class=\"inline\" src=\"http://foobar.jpg\" alt=\"SandBox\" /></a>", translate(src) ); } public void testScandicPagename1() throws Exception { String src = "Link [\u00C5\u00E4Test]"; newPage("\u00C5\u00E4Test"); // FIXME: Should be capital assertEquals("Link <a class=\"wikipage\" href=\"Wiki.jsp?page=%C5%E4Test\">\u00c5\u00e4Test</a>", translate(src)); } public void testParagraph() throws Exception { String src = "1\n\n2\n\n3"; assertEquals( "1\n<p>2\n</p>\n<p>3</p>\n", translate(src) ); } public void testParagraph2() throws Exception { String src = "[WikiEtiquette]\r\n\r\n[Find page]"; newPage( "WikiEtiquette" ); assertEquals( "<a class=\"wikipage\" href=\"Wiki.jsp?page=WikiEtiquette\">WikiEtiquette</a>\n"+ "<p><a class=\"wikipage\" href=\"Wiki.jsp?page=FindPage\">Find page</a></p>\n", translate(src) ); } public void testParagraph3() throws Exception { String src = "\r\n\r\n!Testi\r\n\r\nFoo."; assertEquals( "<p></p>\n<h4 id='section-testpage-Testi'>Testi</h4>\n<p>Foo.</p>\n", translate(src) ); } public void testParagraph4() throws Exception { String src = "\r\n[Recent Changes]\\\\\r\n[WikiEtiquette]\r\n\r\n[Find pages|FindPage]\\\\\r\n[Unused pages|UnusedPages]"; newPage("WikiEtiquette"); newPage("RecentChanges"); newPage("FindPage"); newPage("UnusedPages"); assertEquals( "<p><a class=\"wikipage\" href=\"Wiki.jsp?page=RecentChanges\">Recent Changes</a><br />\n"+ "<a class=\"wikipage\" href=\"Wiki.jsp?page=WikiEtiquette\">WikiEtiquette</a>\n</p>\n"+ "<p><a class=\"wikipage\" href=\"Wiki.jsp?page=FindPage\">Find pages</a><br />\n"+ "<a class=\"wikipage\" href=\"Wiki.jsp?page=UnusedPages\">Unused pages</a></p>\n", translate(src) ); } public void testLinebreak() throws Exception { String src = "1\\\\2"; assertEquals( "1<br />2", translate(src) ); } public void testLinebreakEscape() throws Exception { String src = "1~\\\\2"; assertEquals( "1\\\\2", translate(src) ); } public void testLinebreakClear() throws Exception { String src = "1\\\\\\2"; assertEquals( "1<br clear=\"all\" />2", translate(src) ); } public void testTT() throws Exception { String src = "1{{2345}}6"; assertEquals( "1<tt>2345</tt>6", translate(src) ); } public void testTTAcrossLines() throws Exception { String src = "1{{\n2345\n}}6"; assertEquals( "1<tt>\n2345\n</tt>6", translate(src) ); } public void testTTLinks() throws Exception { String src = "1{{\n2345\n[a link]\n}}6"; newPage("ALink"); assertEquals( "1<tt>\n2345\n<a class=\"wikipage\" href=\"Wiki.jsp?page=ALink\">a link</a>\n</tt>6", translate(src) ); } public void testPre() throws Exception { String src = "1{{{2345}}}6"; assertEquals( "1<span style=\"font-family:monospace; whitespace:pre;\">2345</span>6", translate(src) ); } public void testPreEscape() throws Exception { String src = "1~{{{2345}}}6"; assertEquals( "1{{{2345}}}6", translate(src) ); } public void testPre2() throws Exception { String src = "1 {{{ {{{ 2345 }}} }}} 6"; assertEquals( "1 <span style=\"font-family:monospace; whitespace:pre;\"> {{{ 2345 </span> }}} 6", translate(src) ); } public void testHTMLInPre() throws Exception { String src = "1\n{{{ <b> }}}"; assertEquals( "1\n<pre> <b> </pre>\n", translate(src) ); } public void testCamelCaseInPre() throws Exception { String src = "1\n{{{ CamelCase }}}"; assertEquals( "1\n<pre> CamelCase </pre>\n", translate(src) ); } public void testList1() throws Exception { String src = "A list:\n* One\n* Two\n* Three\n"; assertEquals( "A list:\n<ul>\n<li> One\n</li>\n<li> Two\n</li>\n<li> Three\n</li>\n</ul>\n", translate(src) ); } /** Plain multi line testing: <pre> * One continuing * Two * Three </pre> */ public void testMultilineList1() throws Exception { String src = "A list:\n* One\n continuing.\n* Two\n* Three\n"; assertEquals( "A list:\n<ul>\n<li> One\n continuing.\n</li>\n<li> Two\n</li>\n<li> Three\n</li>\n</ul>\n", translate(src) ); } public void testMultilineList2() throws Exception { String src = "A list:\n* One\n continuing.\n* Two\n* Three\nShould be normal."; assertEquals( "A list:\n<ul>\n<li> One\n continuing.\n</li>\n<li> Two\n</li>\n<li> Three\n</li>\n</ul>\nShould be normal.", translate(src) ); } public void testHTML() throws Exception { String src = "<b>Test</b>"; assertEquals( "<b>Test</b>", translate(src) ); } public void testHTML2() throws Exception { String src = "<p>"; assertEquals( "<p>", translate(src) ); } public void testHTMLWhenAllowed() throws Exception { String src = "<p>"; props.setProperty( "jspwiki.translatorReader.allowHTML", "true" ); testEngine = new TestEngine( props );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -