Skip to content

Commit

Permalink
XWIKI-12987: Relative links are made absolute or even broken after mo…
Browse files Browse the repository at this point in the history
…ving a page

  * Fix remaining coverage problems
  • Loading branch information
surli committed Nov 6, 2024
1 parent d2cb1e0 commit 7bb0a61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import javax.inject.Named;
import javax.inject.Provider;
Expand All @@ -34,9 +35,11 @@
import org.xwiki.job.AbstractJobStatus;
import org.xwiki.job.api.AbstractCheckRightsRequest;
import org.xwiki.job.event.status.JobProgressManager;
import org.xwiki.link.LinkStore;
import org.xwiki.model.EntityType;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.DocumentReferenceResolver;
import org.xwiki.model.reference.EntityReference;
import org.xwiki.model.reference.EntityReferenceProvider;
import org.xwiki.model.reference.EntityReferenceResolver;
import org.xwiki.model.reference.EntityReferenceSerializer;
Expand Down Expand Up @@ -119,6 +122,12 @@ class DefaultModelBridgeTest
@Named("document")
private UserReferenceResolver<DocumentReference> userReferenceResolver;

@MockComponent
private Provider<LinkStore> linkStoreProvider;

@MockComponent
private DocumentReferenceResolver<EntityReference> documentReferenceResolver;

@InjectComponentManager
private MockitoComponentManager componentManager;

Expand All @@ -140,6 +149,9 @@ class DefaultModelBridgeTest
@Mock
private XWikiRightService xWikiRightService;

@Mock
private LinkStore linkStore;

@BeforeEach
void configure(MockitoComponentManager componentManager) throws Exception
{
Expand All @@ -158,6 +170,7 @@ void configure(MockitoComponentManager componentManager) throws Exception
.thenReturn(new DocumentReference("what", "ever", "WebHome"));
when(entityReferenceProvider.getDefaultReference(EntityType.SPACE))
.thenReturn(new SpaceReference("whatever", "Main"));
when(this.linkStoreProvider.get()).thenReturn(this.linkStore);
}

private void assertLog(Level level, String message, Object... arguments)
Expand Down Expand Up @@ -892,4 +905,23 @@ void rename() throws Exception

verify(this.xwiki).renameDocument(source, target, true, List.of(), List.of(), this.xcontext);
}

@Test
void getBackLinkedDocuments() throws Exception
{
EntityReference source = mock(EntityReference.class);
EntityReference ref1 = mock(EntityReference.class, "ref1");
EntityReference ref2 = mock(EntityReference.class, "ref2");
EntityReference ref3 = mock(EntityReference.class, "ref3");
when(this.linkStore.resolveBackLinkedEntities(source)).thenReturn(Set.of(ref1, ref2, ref3));

DocumentReference docRef1 = mock(DocumentReference.class, "docRef1");
DocumentReference docRef2 = mock(DocumentReference.class, "docRef2");
DocumentReference docRef3 = mock(DocumentReference.class, "docRef3");
when(this.documentReferenceResolver.resolve(ref1, this.xcontext)).thenReturn(docRef1);
when(this.documentReferenceResolver.resolve(ref2, this.xcontext)).thenReturn(docRef2);
when(this.documentReferenceResolver.resolve(ref3, this.xcontext)).thenReturn(docRef3);

assertEquals(Set.of(docRef1, docRef2, docRef3), this.modelBridge.getBackLinkedDocuments(source));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void replaceDocumentReferenceWhenIncludingDocumentRenamedUsingPageParameterAndNo
new EntityReference("sourcewiki", EntityType.WIKI))).thenReturn("sourcespace/foo");

Optional<MacroBlock> result = this.includeMacroRefactoring.replaceReference(block, null,
sourceReference, targetReference, false, Map.of());
sourceReference, targetReference, false);
assertFalse(result.isEmpty());
assertEquals("sourcewiki:sourcespace.foo", result.get().getParameter("page"));
}
Expand Down

0 comments on commit 7bb0a61

Please sign in to comment.