This is an automated email from the ASF dual-hosted git repository. mraible pushed a commit to branch feature/playwright-tests in repository https://gitbox.apache.org/repos/asf/roller.git
commit d7a0ac4121315389ed71c0dbd3acd188ad6c9dfd Author: Matt Raible <[email protected]> AuthorDate: Wed Aug 12 06:46:35 2026 -0600 Cover media file upload in the new-user journey test The journey now enables file uploads from the server admin page (they ship disabled, and the first registered user is the admin), uploads a generated PNG, and asserts the success page appears and the stored image is served back with the right content type. This guards the Struts 7 UploadedFilesAware upload path, which broke silently during the migration until Greg Huber caught it on dev@roller. --- .../apache/roller/playwright/NewUserJourneyIT.java | 60 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/it-playwright/src/test/java/org/apache/roller/playwright/NewUserJourneyIT.java b/it-playwright/src/test/java/org/apache/roller/playwright/NewUserJourneyIT.java index 3ad19d44d..c54ae6b30 100644 --- a/it-playwright/src/test/java/org/apache/roller/playwright/NewUserJourneyIT.java +++ b/it-playwright/src/test/java/org/apache/roller/playwright/NewUserJourneyIT.java @@ -17,8 +17,18 @@ */ package org.apache.roller.playwright; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.regex.Pattern; +import javax.imageio.ImageIO; + +import com.microsoft.playwright.APIResponse; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -28,7 +38,9 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * The path a brand new Roller install puts its first visitor through: register - * an account, sign in, create a weblog, then publish and read back an entry. + * an account, sign in, create a weblog, then publish and read back an entry, + * and finally upload a media file (the first user is the admin, so the journey + * also turns file uploads on, which Roller ships disabled). * * <p>This is the journey the old Selenium suite covered. Roller only accepts * registrations on an install with no users yet, so the test skips when the @@ -73,8 +85,19 @@ class NewUserJourneyIT extends BaseIT { private static final String WEBLOG_EMAIL = "#createWeblog_bean_emailAddress"; private static final String WEBLOG_SUBMIT = "#createWeblog_0"; + // server admin configuration form + private static final String GLOBAL_CONFIG_PAGE = "roller-ui/admin/globalConfig.rol"; + private static final String UPLOADS_ENABLED = "input[name='uploads.enabled']"; + private static final String GLOBAL_CONFIG_SAVE = "#saveButton"; + + // media file upload form + private static final String MEDIA_UPLOAD_PAGE = "roller-ui/authoring/mediaFileAdd.rol?weblog=" + BLOG_HANDLE; + private static final String MEDIA_FILE_INPUT = "#fileControl0"; + private static final String MEDIA_UPLOAD_SUBMIT = "#uploadButton"; + private static final String MEDIA_THUMBNAIL = "img.mediaFileImage"; + @Test - @DisplayName("registers an account, creates a weblog, then publishes and reads an entry") + @DisplayName("registers an account, creates a weblog, publishes an entry, and uploads a media file") void firstUserCanRegisterAndPublish() { goTo(LOGIN_PAGE); assumeTrue(page.locator(LOGIN_USERNAME).count() > 0, @@ -85,6 +108,8 @@ class NewUserJourneyIT extends BaseIT { createWeblog(); publishEntry(BLOG_HANDLE, ENTRY_TITLE, ENTRY_TEXT); assertEntryOnBlog(BLOG_HANDLE, ENTRY_TITLE, ENTRY_TEXT); + enableUploads(); + uploadMediaFile(); } private void register() { @@ -139,4 +164,35 @@ class NewUserJourneyIT extends BaseIT { goTo(MENU_PAGE); assertThat(page.getByText(BLOG_NAME).first()).isVisible(); } + + private void enableUploads() { + goTo(GLOBAL_CONFIG_PAGE); + page.locator(UPLOADS_ENABLED).check(); + page.locator(GLOBAL_CONFIG_SAVE).click(); + assertThat(page.locator(UPLOADS_ENABLED)).isChecked(); + } + + private void uploadMediaFile() { + goTo(MEDIA_UPLOAD_PAGE); + page.locator(MEDIA_FILE_INPUT).setInputFiles(pngFile()); + page.locator(MEDIA_UPLOAD_SUBMIT).click(); + assertThat(page).hasTitle(Pattern.compile("Media File Upload Complete")); + + // the uploaded image the success page shows is really served back + String thumbnail = page.locator(MEDIA_THUMBNAIL).first().getAttribute("src"); + String mediaUrl = URI.create(page.url()).resolve(thumbnail.replace("?t=true", "")).toString(); + APIResponse media = page.request().get(mediaUrl); + Assertions.assertEquals(200, media.status()); + Assertions.assertEquals("image/png", media.headers().get("content-type")); + } + + private Path pngFile() { + try { + Path png = Files.createTempFile("roller-upload", ".png"); + ImageIO.write(new BufferedImage(8, 8, BufferedImage.TYPE_INT_RGB), "png", png.toFile()); + return png; + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } }
