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

  * Few improvments following review
  • Loading branch information
surli committed Nov 4, 2024
1 parent ff94733 commit 1194cb2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ void renamePageUsedInMacroContentAndParameters(TestUtils setup, TestReference te

setup.rest().delete(testReference);

setup.createPage(sourcePageReference1, "Some content to be linked. number 1");
setup.createPage(sourcePageReference2, "Some content to be linked in macro. number 2");
setup.createPage(sourcePageReference3, "Some content to be linked in nested macro. number 3");
setup.createPage(sourcePageReference4, "A page with image to be linked. number 4");
setup.rest().savePage(sourcePageReference1, "Some content to be linked. number 1", "sourcePage1");
setup.rest().savePage(sourcePageReference2, "Some content to be linked in macro. number 2", "sourcePage2");
setup.rest().savePage(sourcePageReference3, "Some content to be linked in nested macro. number 3",
"sourcePage3");
setup.rest().savePage(sourcePageReference4, "A page with image to be linked. number 4", "sourcePage4");
AttachmentsPane attachmentsPane = new AttachmentsViewPage().openAttachmentsDocExtraPane();
File image = new File(testConfiguration.getBrowser().getTestResourcesPath(), "AttachmentIT/image.gif");
attachmentsPane.setFileToUpload(image.getAbsolutePath());
attachmentsPane.waitForUploadToFinish("image.gif");
setup.createPage(sourcePageReference5, "A page to be included. number 5");
setup.rest().savePage(sourcePageReference5, "A page to be included. number 5", "sourcePage5");

String testPageContent = "Check out this page: [[type the link label>>doc:%1$s]]\n" + "\n" + "{{warning}}\n"
+ "Withing a macro: Check out this page: [[type the link label>>doc:%2$s]]\n" + "\n" + "{{error}}\n"
Expand All @@ -387,8 +388,9 @@ void renamePageUsedInMacroContentAndParameters(TestUtils setup, TestReference te
+ "Withing a macro: Check out this page: [[type the link label>>doc:%1$s]]\n"
+ "{{/warning}}\n\n"
+ "Final line.";
setup.createPage(testReference,
String.format(testPageContent, sourcePage1, sourcePage2, sourcePage3, sourcePage4, sourcePage5));
setup.rest().savePage(testReference,
String.format(testPageContent, sourcePage1, sourcePage2, sourcePage3, sourcePage4, sourcePage5),
"testPage");

// Wait for the solr indexing to be completed before doing any rename
new SolrTestUtils(setup, testConfiguration.getServletEngine()).waitEmptyQueue();
Expand Down Expand Up @@ -671,14 +673,12 @@ void renameWithIndexingWaiting(String strategy, TestUtils setup, TestReference t
void renameWithRelativeLinks(TestUtils testUtils, TestReference testReference, TestConfiguration testConfiguration)
throws Exception
{
testUtils.createPage(testReference, "[[Alice]]\n[[Bob]]\n[[Eve]]", "Test relative links");
testUtils.rest().savePage(testReference, "[[Alice]]\n[[Bob]]\n[[Eve]]", "Test relative links");
SpaceReference rootSpaceReference = testReference.getLastSpaceReference();
SpaceReference aliceSpace = new SpaceReference("Alice", rootSpaceReference);
testUtils.createPage(new DocumentReference("WebHome", aliceSpace), "Alice page",
"Alice");
testUtils.rest().savePage(new DocumentReference("WebHome", aliceSpace), "Alice page", "Alice");
SpaceReference bobSpace = new SpaceReference("Bob", rootSpaceReference);
testUtils.createPage(new DocumentReference("WebHome", bobSpace), "[[Alice]]",
"Alice");
testUtils.rest().savePage(new DocumentReference("WebHome", bobSpace), "[[Alice]]", "Bob");

// Wait for an empty queue here to ensure that the deleted page has been removed from the index and links
// won't be updated just because the page is still in the index.
Expand Down Expand Up @@ -707,10 +707,10 @@ void renameWithRelativeLinks(TestUtils testUtils, TestReference testReference, T
statusPage = rename.clickRenameButton().waitUntilFinished();
assertEquals("Done.", statusPage.getInfoMessage());

SpaceReference Alice2Space = new SpaceReference("Alice2", newRootSpace);
DocumentReference Alice2Reference = new DocumentReference("WebHome", Alice2Space);
SpaceReference alice2Space = new SpaceReference("Alice2", newRootSpace);
DocumentReference alice2Reference = new DocumentReference("WebHome", alice2Space);
wikiEditPage = WikiEditPage.gotoPage(new DocumentReference("WebHome", newRootSpace));
String serializedAlice2Reference = testUtils.serializeLocalReference(Alice2Reference);
String serializedAlice2Reference = testUtils.serializeLocalReference(alice2Reference);
assertEquals(String.format("[[%s]]%n[[Bob]]%n[[Eve]]", serializedAlice2Reference), wikiEditPage.getContent());

// FIXME: ideally this one should be refactored too, however it's not a regression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ protected void runInternal() throws Exception

try {
this.progressManager.startStep(this);
BeginFoldEvent beginEvent = getBeginEvent();
BeginFoldEvent beginEvent = createBeginEvent();
this.observationManager.notify(beginEvent, this, this.getRequest());
if (((CancelableEvent) beginEvent).isCanceled()) {
if (beginEvent instanceof CancelableEvent && ((CancelableEvent) beginEvent).isCanceled()) {
return;
}
this.progressManager.endStep(this);
Expand All @@ -74,7 +74,7 @@ protected void runInternal() throws Exception
this.progressManager.endStep(this);

this.progressManager.startStep(this);
EndFoldEvent endEvent = getEndEvent();
EndFoldEvent endEvent = createEndEvent();
this.observationManager.notify(endEvent, this, this.getRequest());
this.progressManager.endStep(this);
} finally {
Expand Down Expand Up @@ -337,7 +337,6 @@ protected EntityReference getCommonParent()
* @return {@code true} if the operation worked well.
*/
protected abstract boolean atomicOperation(DocumentReference source, DocumentReference target);
protected abstract <B extends BeginFoldEvent & CancelableEvent> B getBeginEvent();

protected abstract EndFoldEvent getEndEvent();
protected abstract BeginFoldEvent createBeginEvent();
protected abstract EndFoldEvent createEndEvent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.observation.event.BeginFoldEvent;
import org.xwiki.observation.event.CancelableEvent;
import org.xwiki.observation.event.EndFoldEvent;
import org.xwiki.refactoring.event.DocumentCopiedEvent;
import org.xwiki.refactoring.event.DocumentCopyingEvent;
Expand Down Expand Up @@ -68,13 +67,13 @@ protected boolean atomicOperation(DocumentReference source, DocumentReference ta
}

@Override
protected <T extends BeginFoldEvent & CancelableEvent> T getBeginEvent()
protected BeginFoldEvent createBeginEvent()
{
return (T) new EntitiesCopyingEvent();
return new EntitiesCopyingEvent();
}

@Override
protected EndFoldEvent getEndEvent()
protected EndFoldEvent createEndEvent()
{
return new EntitiesCopiedEvent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.EntityReference;
import org.xwiki.observation.event.BeginFoldEvent;
import org.xwiki.observation.event.CancelableEvent;
import org.xwiki.observation.event.EndFoldEvent;
import org.xwiki.refactoring.event.DocumentRenamedEvent;
import org.xwiki.refactoring.event.DocumentRenamingEvent;
Expand All @@ -54,13 +53,13 @@ public String getType()
}

@Override
protected <T extends BeginFoldEvent & CancelableEvent> T getBeginEvent()
protected BeginFoldEvent createBeginEvent()
{
return (T) new EntitiesRenamingEvent();
return new EntitiesRenamingEvent();
}

@Override
protected EndFoldEvent getEndEvent()
protected EndFoldEvent createEndEvent()
{
return new EntitiesRenamedEvent();
}
Expand Down

0 comments on commit 1194cb2

Please sign in to comment.