diff --git a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-docker/src/test/it/org/xwiki/flamingo/test/docker/AttachmentIT.java b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-docker/src/test/it/org/xwiki/flamingo/test/docker/AttachmentIT.java index 234d66f28663..8453917d865a 100644 --- a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-docker/src/test/it/org/xwiki/flamingo/test/docker/AttachmentIT.java +++ b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-docker/src/test/it/org/xwiki/flamingo/test/docker/AttachmentIT.java @@ -20,6 +20,9 @@ package org.xwiki.flamingo.test.docker; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -68,8 +71,6 @@ class AttachmentIT private static final String SECOND_ATTACHMENT = "SmallAttachment2.txt"; - private static final String ESCAPED_ATTACHMENT = "EscapedAttachment.txt"; - private static final String IMAGE_ATTACHMENT = "image.gif"; private static final String SMALL_SIZE_ATTACHMENT = "SmallSizeAttachment.png"; @@ -448,19 +449,24 @@ void deleteAttachmentWithSpecialChar(TestUtils setup, TestReference testReferenc @Test @Order(9) - void checkEscapingInAttachmentName(TestUtils setup, TestReference testReference, - TestConfiguration testConfiguration) + void checkEscapingInAttachmentName(TestUtils setup, TestReference testReference) throws IOException { setup.loginAsSuperAdmin(); + + // We shouldn't store files with special characters in the repository, since some filesystems don't support it. + // Instead, we create the file during the test. + Path unescapedFile = Files.createTempFile("", null); + String unescapedFileName = unescapedFile.getFileName().toString(); + setup.createPage(testReference, "Empty content"); AttachmentsPane attachmentsPane = new AttachmentsViewPage().openAttachmentsDocExtraPane(); - attachmentsPane.setFileToUpload(getFileToUpload(testConfiguration, ESCAPED_ATTACHMENT).getAbsolutePath()); - attachmentsPane.waitForUploadToFinish(ESCAPED_ATTACHMENT); + attachmentsPane.setFileToUpload(unescapedFile.toString(), true); + attachmentsPane.waitForUploadToFinish(unescapedFileName); attachmentsPane.clickHideProgress(); - assertTrue(attachmentsPane.attachmentExistsByFileName(ESCAPED_ATTACHMENT)); - attachmentsPane.deleteAttachmentByFileByName(ESCAPED_ATTACHMENT); + assertTrue(attachmentsPane.attachmentExistsByFileName(unescapedFileName)); + attachmentsPane.deleteAttachmentByFileByName(unescapedFileName); } private String getAttachmentsMacroContent(DocumentReference docRef) diff --git a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-docker/src/test/resources/AttachmentIT/EscapedAttachment.txt b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-docker/src/test/resources/AttachmentIT/EscapedAttachment.txt deleted file mode 100644 index 3cfe87304cd3..000000000000 --- a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-docker/src/test/resources/AttachmentIT/EscapedAttachment.txt +++ /dev/null @@ -1 +0,0 @@ -This is an attachment whose name should be escaped. \ No newline at end of file diff --git a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-pageobjects/src/main/java/org/xwiki/flamingo/skin/test/po/AttachmentsPane.java b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-pageobjects/src/main/java/org/xwiki/flamingo/skin/test/po/AttachmentsPane.java index fff0f4b6369d..ac77c43c86e3 100644 --- a/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-pageobjects/src/main/java/org/xwiki/flamingo/skin/test/po/AttachmentsPane.java +++ b/xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-test/xwiki-platform-flamingo-skin-test-pageobjects/src/main/java/org/xwiki/flamingo/skin/test/po/AttachmentsPane.java @@ -28,6 +28,8 @@ import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.LocalFileDetector; +import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.support.FindBy; import org.xwiki.livedata.test.po.LiveDataElement; import org.xwiki.livedata.test.po.TableLayoutElement; @@ -116,9 +118,26 @@ public void waitForAttachmentsLiveData() * @param filePath the path to the file to upload in URL form (the file *must* exist in the target directory). */ public void setFileToUpload(final String filePath) + { + setFileToUpload(filePath, false); + } + + /** + * Fills the URL with the specified file path. + * + * @param filePath the path to the file to upload in URL form (the file *must* exist in the target directory). + * @param local if true, the file will be searched on the local filesystem. + * @since 15.10.13 + * @since 16.4.4 + * @since 16.9.0RC1 + */ + public void setFileToUpload(final String filePath, final boolean local) { final List inputs = this.pane.findElements(By.className("uploadFileInput")); WebElement input = inputs.get(inputs.size() - 1); + if (local) { + ((RemoteWebElement) input).setFileDetector(new LocalFileDetector()); + } // Clean the field before setting the value in case of successive uploads. input.clear(); input.sendKeys(filePath);