Search in sources :

Example 76 with WikiPage

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

the class IfPluginTest method testIfPluginIPNotAllowed.

/**
 * Checks that IP address is granted.
 *
 * @throws WikiException test Assert.failing.
 */
@Test
public void testIfPluginIPNotAllowed() throws WikiException {
    String src = "[{IfPlugin ip='!127.0.0.1'\n" + "\n" + "Content NOT visible for 127.0.0.1}]";
    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 77 with WikiPage

use of org.apache.wiki.WikiPage 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 78 with WikiPage

use of org.apache.wiki.WikiPage 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 79 with WikiPage

use of org.apache.wiki.WikiPage 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 80 with WikiPage

use of org.apache.wiki.WikiPage 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)

Aggregations

WikiPage (org.apache.wiki.WikiPage)186 Test (org.junit.Test)77 WikiContext (org.apache.wiki.WikiContext)63 WikiEngine (org.apache.wiki.WikiEngine)29 Attachment (org.apache.wiki.attachment.Attachment)26 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)17 File (java.io.File)16 Collection (java.util.Collection)16 TestEngine (org.apache.wiki.TestEngine)15 Iterator (java.util.Iterator)13 StringReader (java.io.StringReader)9 Hashtable (java.util.Hashtable)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 Vector (java.util.Vector)8 StringWriter (java.io.StringWriter)7 InternalWikiException (org.apache.wiki.InternalWikiException)7 PagePermission (org.apache.wiki.auth.permissions.PagePermission)7