use of org.apache.wiki.WikiPage in project jspwiki by apache.
the class JSPWikiMarkupParserTest method testCollectingLinksAttachment.
@Test
public void testCollectingLinksAttachment() throws Exception {
try {
testEngine.saveText(PAGE_NAME, "content");
Attachment att = new Attachment(testEngine, PAGE_NAME, "TestAtt.txt");
att.setAuthor("FirstPost");
testEngine.getAttachmentManager().storeAttachment(att, testEngine.makeAttachmentFile());
LinkCollector coll = new LinkCollector();
LinkCollector coll_others = new LinkCollector();
String src = "[TestAtt.txt]";
WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
MarkupParser p = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
p.addLocalLinkHook(coll_others);
p.addExternalLinkHook(coll_others);
p.addAttachmentLinkHook(coll);
p.parse();
Collection<String> links = coll.getLinks();
Assert.assertEquals("no links found", 1, links.size());
Assert.assertEquals("wrong link", PAGE_NAME + "/TestAtt.txt", links.iterator().next());
Assert.assertEquals("wrong links found", 0, coll_others.getLinks().size());
} finally {
String files = testEngine.getWikiProperties().getProperty(BasicAttachmentProvider.PROP_STORAGEDIR);
File storagedir = new File(files, PAGE_NAME + BasicAttachmentProvider.DIR_EXTENSION);
if (storagedir.exists() && storagedir.isDirectory())
TestEngine.deleteAll(storagedir);
}
}
use of org.apache.wiki.WikiPage in project jspwiki by apache.
the class JSPWikiMarkupParserTest method testSet1.
/**
* Used by the ACL tests.
* @param array
* @param key
* @return
*/
/*
private boolean inArray( Object[] array, Object key )
{
for( int i = 0; i < array.length; i++ )
{
if ( array[i].equals( key ) )
{
return true;
}
}
return false;
}
*/
/**
* Used by the ACL tests.
* @param array
* @param key
* @return
*/
/*
private boolean inGroup( Object[] array, Principal key )
{
for( int i = 0; i < array.length; i++ )
{
if (array[i] instanceof Group)
{
if (((Group)array[i]).isMember(key))
{
return true;
}
}
}
return false;
}
*/
/**
* ACL tests.
*/
/*
@Test
public void testSimpleACL1()
throws Exception
{
String src = "Foobar.[{ALLOW view JanneJalkanen}]";
WikiPage p = new WikiPage( PAGE_NAME );
String res = translate( p, src );
Assert.assertEquals("Page text", "Foobar.", res);
Acl acl = p.getAcl();
Principal prof = new WikiPrincipal("JanneJalkanen");
Assert.assertTrue( "has read", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
Assert.assertFalse( "no edit", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
}
@Test
public void testSimpleACL2()
throws Exception
{
String src = "Foobar.[{ALLOW view JanneJalkanen}]\n"+
"[{ALLOW edit JanneJalkanen, SuloVilen}]";
WikiPage p = new WikiPage( PAGE_NAME );
String res = translate( p, src );
Assert.assertEquals("Page text", "Foobar.\n", res);
Acl acl = p.getAcl();
// ACL says Janne can read and edit
Principal prof = new WikiPrincipal("JanneJalkanen");
Assert.assertTrue( "read for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
Assert.assertTrue( "edit for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
// ACL doesn't say Erik can read or edit
prof = new WikiPrincipal("ErikBunn");
Assert.assertFalse( "no read for BB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
Assert.assertFalse( "no edit for EB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
// ACL says Sulo can edit, but doens't say he can read (though the AuthMgr will tell us it's implied)
prof = new WikiPrincipal("SuloVilen");
Assert.assertFalse( "read for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
Assert.assertTrue( "edit for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
}
*/
/*
private boolean containsGroup( List l, String name )
{
for( Iterator i = l.iterator(); i.hasNext(); )
{
String group = (String) i.next();
if( group.equals( name ) )
return true;
}
return false;
}
*/
/**
* Metadata tests
*/
@Test
public void testSet1() throws Exception {
String src = "Foobar.[{SET name=foo}]";
WikiPage p = new WikiPage(testEngine, PAGE_NAME);
String res = translate(p, src);
Assert.assertEquals("Page text", "Foobar.", res);
Assert.assertEquals("foo", p.getAttribute("name"));
}
use of org.apache.wiki.WikiPage in project jspwiki by apache.
the class JSPWikiMarkupParserTest method translate_nofollow.
private String translate_nofollow(String src) throws IOException, NoRequiredPropertyException, ServletException, WikiException {
props = TestEngine.getTestProperties();
props.setProperty("jspwiki.translatorReader.useRelNofollow", "true");
TestEngine testEngine2 = new TestEngine(props);
WikiContext context = new WikiContext(testEngine2, new WikiPage(testEngine2, PAGE_NAME));
JSPWikiMarkupParser r = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
XHTMLRenderer conv = new XHTMLRenderer(context, r.parse());
return conv.getString();
}
use of org.apache.wiki.WikiPage in project jspwiki by apache.
the class JSPWikiMarkupParserTest method testCollectingLinks2.
@Test
public void testCollectingLinks2() throws Exception {
LinkCollector coll = new LinkCollector();
String src = "[" + PAGE_NAME + "/Test.txt]";
WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
MarkupParser p = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
p.addLocalLinkHook(coll);
p.addExternalLinkHook(coll);
p.addAttachmentLinkHook(coll);
p.parse();
Collection<String> links = coll.getLinks();
Assert.assertEquals("no links found", 1, links.size());
Assert.assertEquals("wrong link", PAGE_NAME + "/Test.txt", links.iterator().next());
}
use of org.apache.wiki.WikiPage in project jspwiki by apache.
the class JSPWikiMarkupParserTest method testCollectingLinks.
/**
* Test collection of links.
*/
@Test
public void testCollectingLinks() throws Exception {
LinkCollector coll = new LinkCollector();
String src = "[Test]";
WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
MarkupParser p = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
p.addLocalLinkHook(coll);
p.addExternalLinkHook(coll);
p.addAttachmentLinkHook(coll);
p.parse();
Collection<String> links = coll.getLinks();
Assert.assertEquals("no links found", 1, links.size());
Assert.assertEquals("wrong link", "Test", links.iterator().next());
}
Aggregations