Search in sources :

Example 31 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class IfPluginTest method testIfPluginUserNotAllowed.

/**
 * Checks that user access is forbidden.
 *
 * @throws WikiException test Assert.failing.
 */
@Test
public void testIfPluginUserNotAllowed() throws WikiException {
    String src = "[{IfPlugin user='!Janne Jalkanen'\n" + "\n" + "Content NOT visible for Janne Jalkanen}]";
    String expected = "\n";
    testEngine.saveText("Test", src);
    WikiPage page = testEngine.getPage("Test", WikiPageProvider.LATEST_VERSION);
    WikiContext context = getJanneBasedWikiContextFor(page);
    String res = testEngine.getHTML(context, page);
    Assert.assertEquals(expected, res);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 32 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class PageViewPluginTest method testShowCountsExclude.

@Test
public void testShowCountsExclude() throws Exception {
    testEngine.saveText("TestPageExcluded", "this is test page that should be excluded [{PageViewPlugin}]");
    WikiPage page1 = testEngine.getPage("TestPage01");
    WikiContext context1 = new WikiContext(testEngine, page1);
    WikiPage page2 = testEngine.getPage("TestPage02");
    WikiContext context2 = new WikiContext(testEngine, page2);
    // generate counts:
    testEngine.getHTML(context1, page1);
    testEngine.getHTML(context2, page2);
    testEngine.getHTML(context2, page2);
    // mind the double \n in the following string:
    String pageViewPageContent = "[{PageViewPlugin show='list' exclude='TestPageExcl*' '\n\n* {1} ({2} views)\n}]";
    testEngine.saveText("PageViews", pageViewPageContent);
    WikiPage pageviews = testEngine.getPage("PageViews");
    WikiContext contextPV = new WikiContext(testEngine, pageviews);
    String result = testEngine.getHTML(contextPV, pageviews);
    // System.out.println( result );
    Assert.assertTrue(result.contains("Test Page 01"));
    // this page should not have been shown:
    Assert.assertFalse(result.contains("Test Page Excluded"));
    testEngine.deleteTestPage("TestPageExcluded");
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 33 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class PageViewPluginTest method testShowCountEntries.

@Test
public void testShowCountEntries() throws Exception {
    // create pages that should be counted
    testEngine.saveText("TestPage03", "this is test page 03 [{PageViewPlugin}]");
    testEngine.saveText("TestPage04", "this is test page 04 [{PageViewPlugin}]");
    WikiPage page1 = testEngine.getPage("TestPage01");
    WikiContext context1 = new WikiContext(testEngine, page1);
    WikiPage page2 = testEngine.getPage("TestPage02");
    WikiContext context2 = new WikiContext(testEngine, page2);
    WikiPage page3 = testEngine.getPage("TestPage03");
    WikiContext context3 = new WikiContext(testEngine, page3);
    WikiPage page4 = testEngine.getPage("TestPage04");
    WikiContext context4 = new WikiContext(testEngine, page4);
    // generate counts:
    testEngine.getHTML(context1, page1);
    testEngine.getHTML(context2, page2);
    testEngine.getHTML(context2, page2);
    testEngine.getHTML(context3, page3);
    testEngine.getHTML(context4, page4);
    // mind the double \n in the following string:
    String pageViewPageContent = "[{PageViewPlugin show='list' entries=3'\n\n* {1} ({2} views)\n}]";
    testEngine.saveText("PageViews", pageViewPageContent);
    WikiPage pageviews = testEngine.getPage("PageViews");
    WikiContext contextPV = new WikiContext(testEngine, pageviews);
    String result = testEngine.getHTML(contextPV, pageviews);
    // System.out.println( result );
    Assert.assertTrue(result.contains("Test Page 03"));
    Assert.assertFalse(result.contains("Test Page 04"));
    testEngine.deleteTestPage("TestPage03");
    testEngine.deleteTestPage("TestPage04");
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 34 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class ReferringPagesPluginTest method testSingleReferral.

@Test
public void testSingleReferral() throws Exception {
    WikiContext context2 = new WikiContext(engine, new WikiPage(engine, "Foobar"));
    String res = manager.execute(context2, "{INSERT org.apache.wiki.plugin.ReferringPagesPlugin WHERE max=5}");
    Assert.assertEquals(mkLink("TestPage") + "<br />", res);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 35 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class ReferringUndefinedPagesPluginTest method setUp.

@Before
public void setUp() throws Exception {
    CacheManager.getInstance().removeAllCaches();
    testEngine = new TestEngine(props);
    testEngine.saveText("TestPage01", "Some Text for testing 01 which refers [NonExistingPageA] ");
    testEngine.saveText("TestPage02", "Some Text for testing 02 which refers [NonExistingPageB] ");
    testEngine.saveText("TestPage03", "Some Text for testing 03 which refers [NonExistingPageC] ");
    context = new WikiContext(testEngine, testEngine.newHttpRequest(), new WikiPage(testEngine, "TestPage"));
    manager = new DefaultPluginManager(testEngine, props);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Before(org.junit.Before)

Aggregations

WikiContext (org.apache.wiki.WikiContext)90 WikiPage (org.apache.wiki.WikiPage)63 Test (org.junit.Test)40 TestEngine (org.apache.wiki.TestEngine)11 StringReader (java.io.StringReader)9 WikiEngine (org.apache.wiki.WikiEngine)9 ProviderException (org.apache.wiki.api.exceptions.ProviderException)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 StringWriter (java.io.StringWriter)6 Collection (java.util.Collection)6 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 LinkCollector (org.apache.wiki.LinkCollector)5 Attachment (org.apache.wiki.attachment.Attachment)5 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiDocument (org.apache.wiki.parser.WikiDocument)4