Skip to content

Commit

Permalink
[Misc] Fix repository clone error on NTFS filesystems
Browse files Browse the repository at this point in the history
(cherry picked from commit e3980b9)
  • Loading branch information
pjeanjean authored and surli committed Sep 30, 2024
1 parent 5a2918c commit 69d3bd9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,8 +71,6 @@ class AttachmentIT

private static final String SECOND_ATTACHMENT = "SmallAttachment2.txt";

private static final String ESCAPED_ATTACHMENT = "<strong>EscapedAttachment.txt";

private static final String IMAGE_ATTACHMENT = "image.gif";

private static final String SMALL_SIZE_ATTACHMENT = "SmallSizeAttachment.png";
Expand Down Expand Up @@ -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("<strong>", 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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WebElement> 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);
Expand Down

0 comments on commit 69d3bd9

Please sign in to comment.