@Test public void getEntityURLWithDefaultAction() throws Exception { DocumentReference documentReference = new DocumentReference("tennis", Arrays.asList("Path", "To"), "Success"); AttachmentReference attachmentReference = new AttachmentReference("image.png", documentReference); XWikiURLFactory urlFactory = mock(XWikiURLFactory.class); context.setURLFactory(urlFactory); EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local"); when(localSerializer.serialize(documentReference.getLastSpaceReference())) .thenReturn("Path.To"); // Document Entity DocumentReferenceResolver<EntityReference> documentResolver = this.mocker.registerMockComponent( DocumentReferenceResolver.TYPE_REFERENCE, "currentgetdocument"); when(documentResolver.resolve(documentReference)).thenReturn(documentReference); this.xwiki.getURL(documentReference, this.context); verify(urlFactory).createURL("Path.To", "Success", "view", null, null, "tennis", this.context); // Attachment Entity AttachmentReferenceResolver<EntityReference> attachmentResolver = this.mocker.registerMockComponent(AttachmentReferenceResolver.TYPE_REFERENCE, "current"); when(attachmentResolver.resolve(attachmentReference)).thenReturn(attachmentReference); this.xwiki.getURL(attachmentReference, this.context); verify(urlFactory) .createAttachmentURL( "image.png", "Path.To", "Success", "download", null, "tennis", this.context); }
@Test public void getURLWithDotsAndBackslashInSpaceName() throws Exception { XWikiURLFactory urlFactory = mock(XWikiURLFactory.class); context.setURLFactory(urlFactory); DocumentReference reference = new DocumentReference("wiki", Arrays.asList("space.withdot.and\\and:"), "page"); EntityReferenceSerializer<String> serializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local"); when(serializer.serialize(reference.getLastSpaceReference())).thenReturn("somescapedspace"); this.xwiki.getURL(reference, "view", null, null, context); verify(urlFactory).createURL("somescapedspace", "page", "view", null, null, "wiki", context); }
@Test public void getURLWithLocale() throws Exception { XWikiURLFactory urlFactory = mock(XWikiURLFactory.class); context.setURLFactory(urlFactory); DocumentReference reference = new DocumentReference("wiki", "Space", "Page", Locale.FRENCH); EntityReferenceSerializer<String> serializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local"); when(serializer.serialize(reference.getLastSpaceReference())).thenReturn("Space"); this.xwiki.getURL(reference, "view", null, null, context); verify(urlFactory).createURL("Space", "Page", "view", "language=fr", null, "wiki", context); this.xwiki.getURL(reference, "view", "language=ro", null, context); verify(urlFactory) .createURL("Space", "Page", "view", "language=ro&language=fr", null, "wiki", context); }