diff --git a/tests/e2e/assets/e2e-test-theme-2.0.zip b/tests/e2e/assets/e2e-test-theme-2.0.zip new file mode 100644 index 0000000000000..8738981684861 Binary files /dev/null and b/tests/e2e/assets/e2e-test-theme-2.0.zip differ diff --git a/tests/e2e/assets/e2e-test-theme.md b/tests/e2e/assets/e2e-test-theme.md index 3c8dcc235b57d..204a29d79c1b0 100644 --- a/tests/e2e/assets/e2e-test-theme.md +++ b/tests/e2e/assets/e2e-test-theme.md @@ -1,23 +1,30 @@ -# Theme fixture +# Theme fixtures `e2e-test-theme.zip` contains a minimal classic theme with three files. Its template executes no code. The screenshot reuses the existing PHPUnit image fixture. The update URI prevents WordPress.org update matching. -To reproduce the archive from the repository root with Python 3: +`e2e-test-theme-2.0.zip` contains the same theme with version `2.0`, for replacing an installed theme with an uploaded version. + +To reproduce both archives from the repository root with Python 3: ```python from pathlib import Path from zipfile import ZipFile, ZipInfo -files = { - 'style.css': '/*\nTheme Name: E2E Test Theme\nVersion: 1.0\nUpdate URI: false\n*/\n', - 'index.php': ' theme.stylesheet === themeSlug ) ) { @@ -47,16 +60,7 @@ test.describe( 'Theme management', () => { previousTheme = themes.find( ( theme ) => theme.status === 'active' ).stylesheet; - await admin.visitAdminPage( 'theme-install.php' ); - await page - .getByRole( 'button', { name: 'Upload Theme', exact: true } ) - .click(); - await page - .locator( '#themezip' ) - .setInputFiles( 'tests/e2e/assets/e2e-test-theme.zip' ); - await page - .getByRole( 'button', { name: 'Install Now', exact: true } ) - .click(); + await uploadTheme( admin, page, 'e2e-test-theme.zip' ); await expect( page.getByText( 'Theme installed successfully.', { exact: true } ) ).toBeVisible(); @@ -152,6 +156,46 @@ test.describe( 'Theme management', () => { ).toBe( previousTheme ); } ); + test( 'replaces an installed theme with an uploaded version', async ( { + admin, + page, + requestUtils, + } ) => { + expect( + ( + await requestUtils.rest( { + path: `/wp/v2/themes/${ themeSlug }`, + } ) + ).version + ).toBe( '1.0' ); + await uploadTheme( admin, page, 'e2e-test-theme-2.0.zip' ); + await expect( + page.getByRole( 'heading', { + name: 'This theme is already installed.', + exact: true, + } ) + ).toBeVisible(); + await expect( + page.getByRole( 'row', { name: 'Version 1.0 2.0', exact: true } ) + ).toBeVisible(); + await page + .getByRole( 'link', { + name: 'Replace installed with uploaded', + exact: true, + } ) + .click(); + await expect( + page.getByText( 'Theme updated successfully.', { exact: true } ) + ).toBeVisible(); + expect( + ( + await requestUtils.rest( { + path: `/wp/v2/themes/${ themeSlug }`, + } ) + ).version + ).toBe( '2.0' ); + } ); + test( 'searches for an installed theme', async ( { admin, page } ) => { await admin.visitAdminPage( 'themes.php' ); const search = page.getByRole( 'searchbox', {