use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.
the class XWikiWikiModelTest method getDocumentEditURLWhenNoQueryStringSpecified.
@Test
public void getDocumentEditURLWhenNoQueryStringSpecified() throws Exception {
DocumentResourceReference reference = new DocumentResourceReference("TargetSpace.TargetPage");
reference.setAnchor("anchor");
EntityReferenceSerializer<String> compactEntityReferenceSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
// Note: we use a character that needs to be encoded in the current document's page name to make sure the
// generate query string is encoded.
DocumentReference currentDocumentReference = new DocumentReference("Wiki", "Space", "Page\u20AC");
DocumentReference documentReference = new DocumentReference("TargetWiki", "TargetSpace", "TargetPage");
when(this.documentAccessBridge.getCurrentDocumentReference()).thenReturn(currentDocumentReference);
when(compactEntityReferenceSerializer.serialize(currentDocumentReference)).thenReturn("Wiki:Space.Page\u20AC");
when(this.referenceResolver.resolve(reference, EntityType.DOCUMENT)).thenReturn(documentReference);
this.mocker.getComponentUnderTest().getDocumentEditURL(reference);
// Verify that getDocumentURL is called with the query string already encoded since getDocumentURL() doesn't
// encode it.
verify(this.documentAccessBridge).getDocumentURL(documentReference, "create", "parent=Wiki%3ASpace.Page%E2%82%AC", "anchor");
}
use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecuteWhenInnerMacro.
/**
* Check that macro used inside wiki macro are executed as part of the document.
*/
@Test
public void testExecuteWhenInnerMacro() throws Exception {
registerWikiMacro("wikimacro1", "{{toc/}}", Syntax.XWIKI_2_0);
getMockery().checking(new Expectations() {
{
DocumentResourceReference reference = new DocumentResourceReference(null);
reference.setAnchor("Hheading");
allowing(mockWikiModel).getDocumentViewURL(reference);
will(returnValue("url"));
}
});
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
converter.convert(new StringReader("= heading\n\n{{wikimacro1 param1=\"value1\" param2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<h1 id=\"Hheading\" class=\"wikigeneratedid\"><span>heading</span></h1>" + "<ul><li><span class=\"wikilink\"><a href=\"#Hheading\">heading</a></span></li></ul>", printer.toString());
}
use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.
the class DefaultLinkReferenceParserTest method parseWhenInWikiMode.
@Test
public void parseWhenInWikiMode() throws Exception {
// Create a Mock WikiModel implementation so that the link parser works in wiki mode
WikiModel mockWikiModel = this.componentManager.registerMockComponent(WikiModel.class);
ResourceReference reference = this.parser.parse("");
assertEquals("", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = []", reference.toString());
when(mockWikiModel.isDocumentAvailable(new DocumentResourceReference("existingpage"))).thenReturn(true);
reference = this.parser.parse("existingpage");
assertEquals("existingpage", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [existingpage]", reference.toString());
reference = this.parser.parse("unexistingpage");
assertEquals("unexistingpage", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [unexistingpage]", reference.toString());
reference = this.parser.parse("space.unexistingpage");
assertEquals("space.unexistingpage", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [space.unexistingpage]", reference.toString());
reference = this.parser.parse("http://xwiki.org");
assertEquals("http://xwiki.org", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.URL, reference.getType());
assertEquals("Typed = [false] Type = [url] Reference = [http://xwiki.org]", reference.toString());
// Verify mailto: URI is recognized
reference = this.parser.parse("mailto:john@smith.com?subject=test");
assertEquals("john@smith.com?subject=test", reference.getReference());
assertTrue(reference.isTyped());
assertEquals(ResourceType.MAILTO, reference.getType());
assertEquals("Typed = [true] Type = [mailto] Reference = [john@smith.com?subject=test]", reference.toString());
// Verify attach: URI is recognized
reference = this.parser.parse("attach:some:content");
assertEquals("some:content", reference.getReference());
assertTrue(reference.isTyped());
assertEquals(ResourceType.ATTACHMENT, reference.getType());
assertEquals("Typed = [true] Type = [attach] Reference = [some:content]", reference.toString());
// Verify that unknown URIs are ignored
// Note: In this example we point to a document and we consider that myxwiki is the wiki name and
// http://xwiki.org is the page name
reference = this.parser.parse("mywiki:http://xwiki.org");
assertEquals("mywiki:http://xwiki.org", reference.getReference());
assertFalse(reference.isTyped());
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Typed = [false] Type = [doc] Reference = [mywiki:http://xwiki.org]", reference.toString());
// Verify doc links work
reference = this.parser.parse("doc:wiki:space.page");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("wiki:space.page", reference.getReference());
assertEquals("Typed = [true] Type = [doc] Reference = [wiki:space.page]", reference.toString());
assertTrue(reference.isTyped());
// Verify space links work
reference = this.parser.parse("space:wiki:space");
assertEquals(ResourceType.SPACE, reference.getType());
assertEquals("wiki:space", reference.getReference());
assertEquals("Typed = [true] Type = [space] Reference = [wiki:space]", reference.toString());
assertTrue(reference.isTyped());
// Verify InterWiki links work
reference = this.parser.parse("interwiki:alias:content");
assertEquals(ResourceType.INTERWIKI, reference.getType());
assertEquals("content", reference.getReference());
assertTrue(reference.isTyped());
assertEquals("alias", ((InterWikiResourceReference) reference).getInterWikiAlias());
assertEquals("Typed = [true] Type = [interwiki] Reference = [content] " + "Parameters = [[interWikiAlias] = [alias]]", reference.toString());
// Verify that an invalid InterWiki link is considered as Document link
reference = this.parser.parse("interwiki:invalid_since_doesnt_have_colon");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("interwiki:invalid_since_doesnt_have_colon", reference.getReference());
assertFalse(reference.isTyped());
assertEquals("Typed = [false] Type = [doc] Reference = [interwiki:invalid_since_doesnt_have_colon]", reference.toString());
// Verify typed URLs
reference = this.parser.parse("url:http://xwiki.org");
assertEquals(ResourceType.URL, reference.getType());
assertTrue(reference.isTyped());
assertEquals("http://xwiki.org", reference.getReference());
assertEquals("Typed = [true] Type = [url] Reference = [http://xwiki.org]", reference.toString());
// Verify query string and anchors have no meaning in link reference to documents.
reference = this.parser.parse("Hello World?no=queryString#notAnAnchor");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("Hello World?no=queryString#notAnAnchor", reference.getReference());
assertFalse(reference.isTyped());
assertNull(((DocumentResourceReference) reference).getAnchor());
assertNull(((DocumentResourceReference) reference).getQueryString());
assertEquals("Typed = [false] Type = [doc] Reference = [Hello World?no=queryString#notAnAnchor]", reference.toString());
// Verify that the interwiki separator from XWiki Syntax 2.0 has not meaning in link references to documents
reference = this.parser.parse("page@alias");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertFalse(reference.isTyped());
assertEquals("page@alias", reference.getReference());
assertEquals("Typed = [false] Type = [doc] Reference = [page@alias]", reference.toString());
// Verify path link types
reference = this.parser.parse("path:/some/path");
assertEquals(ResourceType.PATH, reference.getType());
assertTrue(reference.isTyped());
assertEquals("/some/path", reference.getReference());
assertEquals("Typed = [true] Type = [path] Reference = [/some/path]", reference.toString());
// Verify UNC link types
reference = this.parser.parse("unc:\\\\myserver\\myshare\\mydoc.txt");
assertEquals(ResourceType.UNC, reference.getType());
assertTrue(reference.isTyped());
assertEquals("\\\\myserver\\myshare\\mydoc.txt", reference.getReference());
assertEquals("Typed = [true] Type = [unc] Reference = [\\\\myserver\\myshare\\mydoc.txt]", reference.toString());
// Verify that reference escapes are left as is by the link parser
reference = this.parser.parse("pa\\.ge");
assertEquals(ResourceType.DOCUMENT, reference.getType());
assertEquals("pa\\.ge", reference.getReference());
}
use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.
the class XWikiLinkLabelGeneratorTest method generateWhenNestedPage.
@Test
public void generateWhenNestedPage() throws Exception {
ResourceReference resourceReference = new DocumentResourceReference("WebHome");
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("space1", "NestedPage"), "WebHome");
EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentModelBridge dmb = mock(DocumentModelBridge.class);
when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb);
when(dmb.getTitle()).thenReturn("My title");
EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
when(localSerializer.serialize(new SpaceReference("wiki", "space1", "NestedPage"))).thenReturn("space1.NestedPage");
assertEquals("%l%la%n%na%N%NA " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (My title) " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (My title)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
use of org.xwiki.rendering.listener.reference.DocumentResourceReference in project xwiki-platform by xwiki.
the class XWikiLinkLabelGeneratorTest method generateWhenDocumentFailsToLoad.
@Test
public void generateWhenDocumentFailsToLoad() throws Exception {
ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
DocumentReference documentReference = new DocumentReference("xwiki", "Main", "HelloWorld");
EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
when(dab.getTranslatedDocumentInstance(documentReference)).thenThrow(new Exception("error"));
EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
when(localSerializer.serialize(new SpaceReference("xwiki", "Main"))).thenReturn("Main");
assertEquals("%l%la%n%na%N%NA " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld) " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
Aggregations