use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class IfPluginTest method testIfPluginUserAllowed.
/**
* Checks that user access is granted.
*
* @throws WikiException test Assertions.failing.
*/
@Test
public void testIfPluginUserAllowed() throws WikiException {
final String src = "[{IfPlugin user='Janne Jalkanen'\n\nContent visible for Janne Jalkanen}]";
final String expected = "<p>Content visible for Janne Jalkanen</p>\n";
testEngine.saveText("Test", src);
final Page page = testEngine.getManager(PageManager.class).getPage("Test", PageProvider.LATEST_VERSION);
final Context context = getJanneBasedWikiContextFor(page);
final String res = testEngine.getManager(RenderingManager.class).getHTML(context, page);
Assertions.assertEquals(expected, res);
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class IfPluginTest method testIfPluginIPAllowed.
/**
* Checks that IP address is granted.
*
* @throws WikiException test Assertions.failing.
*/
@Test
public void testIfPluginIPAllowed() throws WikiException {
final String src = "[{IfPlugin ip='127.0.0.1'\n\nContent visible for 127.0.0.1}]";
final String expected = "<p>Content visible for 127.0.0.1</p>\n";
testEngine.saveText("Test", src);
final Page page = testEngine.getManager(PageManager.class).getPage("Test", PageProvider.LATEST_VERSION);
final Context context = getJanneBasedWikiContextFor(page);
final String res = testEngine.getManager(RenderingManager.class).getHTML(context, page);
Assertions.assertEquals(expected, res);
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class VersioningFileProviderTest method testChangeNoteOldVersion.
@Test
public void testChangeNoteOldVersion() throws Exception {
final Page p = Wiki.contents().page(engine, NAME1);
final Context context = Wiki.context().create(engine, p);
context.getPage().setAttribute(Page.CHANGENOTE, "Test change");
engine.getManager(PageManager.class).saveText(context, "test");
context.getPage().setAttribute(Page.CHANGENOTE, "Change 2");
engine.getManager(PageManager.class).saveText(context, "test2");
final Page p2 = engine.getManager(PageManager.class).getPage(NAME1, 1);
Assertions.assertEquals("Test change", p2.getAttribute(Page.CHANGENOTE));
final Page p3 = engine.getManager(PageManager.class).getPage(NAME1, 2);
Assertions.assertEquals("Change 2", p3.getAttribute(Page.CHANGENOTE));
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class VersioningFileProviderTest method testChangeNoteOldVersion2.
@Test
public void testChangeNoteOldVersion2() throws Exception {
final Page p = Wiki.contents().page(engine, NAME1);
final Context context = Wiki.context().create(engine, p);
context.getPage().setAttribute(Page.CHANGENOTE, "Test change");
engine.getManager(PageManager.class).saveText(context, "test");
for (int i = 0; i < 5; i++) {
final Page p2 = engine.getManager(PageManager.class).getPage(NAME1).clone();
p2.removeAttribute(Page.CHANGENOTE);
context.setPage(p2);
engine.getManager(PageManager.class).saveText(context, "test" + i);
}
final Page p3 = engine.getManager(PageManager.class).getPage(NAME1, -1);
Assertions.assertNull(p3.getAttribute(Page.CHANGENOTE));
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class PageViewPluginTest method testShowCountsSorted.
@Test
public void testShowCountsSorted() throws Exception {
final Page page1 = testEngine.getManager(PageManager.class).getPage("TestPage01");
final Context context1 = Wiki.context().create(testEngine, page1);
final Page page2 = testEngine.getManager(PageManager.class).getPage("TestPage02");
final Context context2 = Wiki.context().create(testEngine, page2);
// generate counts:
testEngine.getManager(RenderingManager.class).getHTML(context1, page1);
testEngine.getManager(RenderingManager.class).getHTML(context2, page2);
testEngine.getManager(RenderingManager.class).getHTML(context2, page2);
// mind the double \n in the following string:
final String pageViewPageContent = "[{PageViewPlugin show='list' sort=count '\n\n* {1} ({2} views)\n}]";
testEngine.saveText("PageViews", pageViewPageContent);
final Page pageviews = testEngine.getManager(PageManager.class).getPage("PageViews");
final Context contextPV = Wiki.context().create(testEngine, pageviews);
final String result = testEngine.getManager(RenderingManager.class).getHTML(contextPV, pageviews);
// System.out.println( result );
final int start1 = result.indexOf("Test Page 01");
final int start2 = result.indexOf("Test Page 02");
// page2 should be showed before page1
Assertions.assertTrue(start2 < start1);
}
Aggregations