From b9c89839da7b3a288037efa3da2b97ed43fa2f80 Mon Sep 17 00:00:00 2001 From: juhi123 Date: Fri, 3 Jan 2025 12:11:32 +0530 Subject: [PATCH 1/3] Add Playwright E2E tests to add, activate and delete a theme --- tests/e2e/specs/theme/theme.test.js | 65 +++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/e2e/specs/theme/theme.test.js diff --git a/tests/e2e/specs/theme/theme.test.js b/tests/e2e/specs/theme/theme.test.js new file mode 100644 index 0000000000000..7f33f4121b95a --- /dev/null +++ b/tests/e2e/specs/theme/theme.test.js @@ -0,0 +1,65 @@ +/** + * WordPress dependencies + */ +import { test, expect } from '@wordpress/e2e-test-utils-playwright'; + +test.describe( 'Manage Themes', () => { + const themeSlug = 'hello-elementor'; + const fallbackThemeSlug = 'twentytwentyone'; + + test.afterAll( async ( { requestUtils } ) => { + // Activate a fallback theme after all tests + await requestUtils.activateTheme( fallbackThemeSlug ); + } ); + + test( 'installs a theme', async ( { page, admin } ) => { + await admin.visitAdminPage( 'theme-install.php' ); // Navigate to theme install page + await page.fill( '#wp-filter-search-input', themeSlug ); // Search for the theme + await page.hover( `.theme[data-slug="${ themeSlug }"]` ); + await page.click( + `.theme[data-slug="${ themeSlug }"] a.button-primary.theme-install` + ); + await page.waitForSelector( + `.theme[data-slug="${ themeSlug }"] a.button-primary.theme-install.updating-message`, + { state: 'detached' } + ); + // Locate the notice element + const successNotice = page.locator( + `.theme[data-slug="${ themeSlug }"] .notice.notice-success.notice-alt p` + ); + + // Assert the text content is as expected + await expect( successNotice ).toHaveText( 'Installed' ); + } ); + + test( 'activates a theme', async ( { page, admin } ) => { + await admin.visitAdminPage( 'themes.php' ); // Navigate to themes page + await page.click( `.theme[data-slug="${ themeSlug }"] .activate` ); + } ); + + test( 'deletes an inactive theme', async ( { + page, + admin, + requestUtils, + } ) => { + // Activate a fallback theme before deleting the current one + await requestUtils.activateTheme( fallbackThemeSlug ); + + await admin.visitAdminPage( 'themes.php' ); // Navigate to themes page + + // Confirm deletion dialog + page.on( 'dialog', async ( dialog ) => { + await dialog.accept(); + } ); + + // Open the theme details for the theme to delete + await page.click( `.theme[data-slug="${ themeSlug }"]` ); + await page.click( '.delete-theme' ); + + // Verify theme is deleted + await expect( + page.locator( `.theme[data-slug="${ themeSlug }"]` ) + ).not.toBeVisible(); + console.log( `Theme "${ themeSlug }" deleted successfully.` ); + } ); +} ); From a496b67751a30d99174d85fc5bbdae92f4c389c6 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Mon, 12 Oct 2026 19:10:52 +0200 Subject: [PATCH 2/3] Build/Test Tools: Cover theme activation and deletion with a local fixture. --- tests/e2e/assets/e2e-test-theme.md | 23 +++++ tests/e2e/assets/e2e-test-theme.zip | Bin 0 -> 2524 bytes tests/e2e/specs/theme/theme.test.js | 65 -------------- tests/e2e/specs/themes.test.js | 134 ++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 65 deletions(-) create mode 100644 tests/e2e/assets/e2e-test-theme.md create mode 100644 tests/e2e/assets/e2e-test-theme.zip delete mode 100644 tests/e2e/specs/theme/theme.test.js create mode 100644 tests/e2e/specs/themes.test.js diff --git a/tests/e2e/assets/e2e-test-theme.md b/tests/e2e/assets/e2e-test-theme.md new file mode 100644 index 0000000000000..3c8dcc235b57d --- /dev/null +++ b/tests/e2e/assets/e2e-test-theme.md @@ -0,0 +1,23 @@ +# Theme fixture + +`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: + +```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': 'w$1wt zkFXdfa|eeN&9#f%xlPll=>s!8*0`?$5CnmBNCg@R*teP&5e|Tt7qCGP^Z*7j0cb>m zkP0AkfSHm3@PI6)Wk1OJy$%Y1vLc8$+4~Kth6md55iaS6d(yS_h+x)zilrAPN;T z0SZE+Q95W0Mh6K5lz_YkI>s0i%cZMyXZeO=t#%RY_h%LA&HtucZ0gq{Td-_POtL=C zj5vFa`NBnut-rK!SiXX~($UH7U#r)wUFYtx!9Re$F)(OT*j8rvHdaI=ha0=lj-8IX~e!m{!o25^k00`I%&~SMA1z-|Auo~~sY<_Om)k&P%&1P1hNnqIX#=UM+V0Cd z3+Z@qt>uHfHwl#?Zqg^^x3faY8E6G-+SQ@>@swQk7e*R@X;ht|F|WI+$`r0i;>FdZ z^Xl$=A;DImvItOJa$VHrS){(B)_ZV2PM}*OQ`Eg?D8ueAeq`<)6;~E9VYv0MLjiu^ z7d6heWP~PL#ei38fMn=JSzqZ2#d_5l5i8oXtjUZ0ZR?T&h3>gNhJZMcI74-jkHH8n zmr!DlkQg;`Yy-oHbsGrp56bcN>GK86<;gyf`h@w6>qWftZY|Ybl4ifAVA;eW;Th+U z`?00=Qs-vs#+Hism9a(?|F)NsZK=`c@q)vqYv!cA@gC+^-X; z(!@h~h8mC({q2=@m*sI0Y)S8I_-MR^@Os->878l>4)SiwRVlHQ<1^C|Uzx_C0vf z<80aDMyHPP%$pj}De!AcGl{N5P}Bf=0|H(=wFIVpcYBQ&UPf996=a{7FCQ z((hpaJMJ!9D@_wqGH8Y_w*C2C9a4O~cX}`O()0Bv`+CjzWck`uWvEQeCgD9M=U$^9 zEaiDj_}s4?CYqTHS8a+dy^&z`vN6hj(10xn`aT2gJe~rlDQL=Nuv>pf{CJ^!qV8TA z2|c#NYNT$nvmDzPP2{n~4EzpZ8Bt7089dR}~tka1K``}7BnMco$w literal 0 HcmV?d00001 diff --git a/tests/e2e/specs/theme/theme.test.js b/tests/e2e/specs/theme/theme.test.js deleted file mode 100644 index 7f33f4121b95a..0000000000000 --- a/tests/e2e/specs/theme/theme.test.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * WordPress dependencies - */ -import { test, expect } from '@wordpress/e2e-test-utils-playwright'; - -test.describe( 'Manage Themes', () => { - const themeSlug = 'hello-elementor'; - const fallbackThemeSlug = 'twentytwentyone'; - - test.afterAll( async ( { requestUtils } ) => { - // Activate a fallback theme after all tests - await requestUtils.activateTheme( fallbackThemeSlug ); - } ); - - test( 'installs a theme', async ( { page, admin } ) => { - await admin.visitAdminPage( 'theme-install.php' ); // Navigate to theme install page - await page.fill( '#wp-filter-search-input', themeSlug ); // Search for the theme - await page.hover( `.theme[data-slug="${ themeSlug }"]` ); - await page.click( - `.theme[data-slug="${ themeSlug }"] a.button-primary.theme-install` - ); - await page.waitForSelector( - `.theme[data-slug="${ themeSlug }"] a.button-primary.theme-install.updating-message`, - { state: 'detached' } - ); - // Locate the notice element - const successNotice = page.locator( - `.theme[data-slug="${ themeSlug }"] .notice.notice-success.notice-alt p` - ); - - // Assert the text content is as expected - await expect( successNotice ).toHaveText( 'Installed' ); - } ); - - test( 'activates a theme', async ( { page, admin } ) => { - await admin.visitAdminPage( 'themes.php' ); // Navigate to themes page - await page.click( `.theme[data-slug="${ themeSlug }"] .activate` ); - } ); - - test( 'deletes an inactive theme', async ( { - page, - admin, - requestUtils, - } ) => { - // Activate a fallback theme before deleting the current one - await requestUtils.activateTheme( fallbackThemeSlug ); - - await admin.visitAdminPage( 'themes.php' ); // Navigate to themes page - - // Confirm deletion dialog - page.on( 'dialog', async ( dialog ) => { - await dialog.accept(); - } ); - - // Open the theme details for the theme to delete - await page.click( `.theme[data-slug="${ themeSlug }"]` ); - await page.click( '.delete-theme' ); - - // Verify theme is deleted - await expect( - page.locator( `.theme[data-slug="${ themeSlug }"]` ) - ).not.toBeVisible(); - console.log( `Theme "${ themeSlug }" deleted successfully.` ); - } ); -} ); diff --git a/tests/e2e/specs/themes.test.js b/tests/e2e/specs/themes.test.js new file mode 100644 index 0000000000000..9b9a73dad98be --- /dev/null +++ b/tests/e2e/specs/themes.test.js @@ -0,0 +1,134 @@ +/** + * WordPress dependencies + */ +import { test, expect } from '@wordpress/e2e-test-utils-playwright'; + +const themeSlug = 'e2e-test-theme'; +const themeName = 'E2E Test Theme'; + +test.describe( 'Theme management', () => { + let previousTheme; + let ownsTheme; + + test.beforeEach( async ( { admin, page, requestUtils } ) => { + // The fixture slug requires an environment not shared with another test run. + ownsTheme = false; + const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); + expect( themes.map( ( theme ) => theme.stylesheet ) ).not.toContain( + themeSlug + ); + previousTheme = themes.find( + ( theme ) => theme.status === 'active' + ).stylesheet; + ownsTheme = true; + 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 expect( + page.getByText( 'Theme installed successfully.', { exact: true } ) + ).toBeVisible(); + } ); + + test.afterEach( async ( { admin, page, requestUtils } ) => { + if ( ! ownsTheme ) { + return; + } + await requestUtils.activateTheme( previousTheme ); + const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); + if ( themes.some( ( theme ) => theme.stylesheet === themeSlug ) ) { + await admin.visitAdminPage( 'themes.php' ); + await page.locator( `.theme[data-slug="${ themeSlug }"]` ).click(); + const deleteUrl = await page + .getByRole( 'link', { + name: `Delete ${ themeName }`, + exact: true, + } ) + .getAttribute( 'href' ); + const response = await requestUtils.request.get( deleteUrl ); + expect( response.ok() ).toBe( true ); + await response.dispose(); + } + const remainingThemes = await requestUtils.rest( { + path: '/wp/v2/themes', + } ); + expect( + remainingThemes.map( ( theme ) => theme.stylesheet ) + ).not.toContain( themeSlug ); + expect( + remainingThemes.find( ( theme ) => theme.status === 'active' ) + .stylesheet + ).toBe( previousTheme ); + } ); + + test( 'activates an installed theme from its card', async ( { + admin, + page, + requestUtils, + } ) => { + await admin.visitAdminPage( 'themes.php' ); + const card = page.locator( `.theme[data-slug="${ themeSlug }"]` ); + await card.hover(); + await card + .getByRole( 'link', { + name: `Activate ${ themeName }`, + exact: true, + } ) + .click(); + await expect( + card.getByRole( 'heading', { + name: `Active: ${ themeName }`, + exact: true, + } ) + ).toBeVisible(); + await page.reload(); + await expect( + card.getByRole( 'heading', { + name: `Active: ${ themeName }`, + exact: true, + } ) + ).toBeVisible(); + const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); + expect( + themes.find( ( theme ) => theme.status === 'active' ).stylesheet + ).toBe( themeSlug ); + } ); + + test( 'deletes an inactive theme from its details', async ( { + admin, + page, + requestUtils, + } ) => { + await admin.visitAdminPage( 'themes.php' ); + const card = page.locator( `.theme[data-slug="${ themeSlug }"]` ); + await card.click(); + await Promise.all( [ + page.waitForEvent( 'dialog' ).then( async ( dialog ) => { + expect( dialog.type() ).toBe( 'confirm' ); + await dialog.accept(); + } ), + page + .getByRole( 'link', { + name: `Delete ${ themeName }`, + exact: true, + } ) + .click(), + ] ); + await expect( card ).toHaveCount( 0 ); + await page.reload(); + await expect( card ).toHaveCount( 0 ); + const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); + expect( themes.map( ( theme ) => theme.stylesheet ) ).not.toContain( + themeSlug + ); + expect( + themes.find( ( theme ) => theme.status === 'active' ).stylesheet + ).toBe( previousTheme ); + } ); +} ); From 5253b5fa49b0bd4b05d94517bf69a24b6ad436bd Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Tue, 20 Oct 2026 09:32:40 -0700 Subject: [PATCH 3/3] Build/Test Tools: Decouple theme cleanup from the details overlay. --- tests/e2e/specs/themes.test.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/e2e/specs/themes.test.js b/tests/e2e/specs/themes.test.js index 9b9a73dad98be..686f0faab3862 100644 --- a/tests/e2e/specs/themes.test.js +++ b/tests/e2e/specs/themes.test.js @@ -36,22 +36,25 @@ test.describe( 'Theme management', () => { ).toBeVisible(); } ); - test.afterEach( async ( { admin, page, requestUtils } ) => { + test.afterEach( async ( { requestUtils } ) => { if ( ! ownsTheme ) { return; } await requestUtils.activateTheme( previousTheme ); const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ); if ( themes.some( ( theme ) => theme.stylesheet === themeSlug ) ) { - await admin.visitAdminPage( 'themes.php' ); - await page.locator( `.theme[data-slug="${ themeSlug }"]` ).click(); - const deleteUrl = await page - .getByRole( 'link', { - name: `Delete ${ themeName }`, - exact: true, - } ) - .getAttribute( 'href' ); - const response = await requestUtils.request.get( deleteUrl ); + const themesResponse = await requestUtils.request.get( + 'wp-admin/themes.php' + ); + const html = await themesResponse.text(); + await themesResponse.dispose(); + const deleteQuery = html.match( + `action=delete&stylesheet=${ themeSlug }&_wpnonce=[a-z0-9]+` + ); + expect( deleteQuery ).not.toBeNull(); + const response = await requestUtils.request.get( + `wp-admin/themes.php?${ deleteQuery[ 0 ].replace( /&/g, '&' ) }` + ); expect( response.ok() ).toBe( true ); await response.dispose(); }