Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added tests/e2e/assets/e2e-test-theme-2.0.zip
Binary file not shown.
33 changes: 20 additions & 13 deletions tests/e2e/assets/e2e-test-theme.md
Original file line number Diff line number Diff line change
@@ -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': '<?php\n// E2E theme fixture.\n',
'screenshot.jpg': Path('tests/phpunit/data/images/test-image.jpg').read_bytes(),
archives = {
'1.0': 'tests/e2e/assets/e2e-test-theme.zip',
'2.0': 'tests/e2e/assets/e2e-test-theme-2.0.zip',
}
with ZipFile('tests/e2e/assets/e2e-test-theme.zip', 'w') as archive:
for name, content in files.items():
entry = ZipInfo(
'e2e-test-theme/' + name,
date_time=(2020, 1, 1, 0, 0, 0),
)
archive.writestr(entry, content)
for version, path in archives.items():
files = {
'style.css': f'/*\nTheme Name: E2E Test Theme\nVersion: {version}\nUpdate URI: false\n*/\n',
'index.php': '<?php\n// E2E theme fixture.\n',
'screenshot.jpg': Path('tests/phpunit/data/images/test-image.jpg').read_bytes(),
}
with ZipFile(path, 'w') as archive:
for name, content in files.items():
entry = ZipInfo(
'e2e-test-theme/' + name,
date_time=(2020, 1, 1, 0, 0, 0),
)
archive.writestr(entry, content)
```
64 changes: 54 additions & 10 deletions tests/e2e/specs/themes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright';
const themeSlug = 'e2e-test-theme';
const themeName = 'E2E Test Theme';

async function uploadTheme( admin, page, fixture ) {
await admin.visitAdminPage( 'theme-install.php' );
await page
.getByRole( 'button', { name: 'Upload Theme', exact: true } )
.click();
await page
.locator( '#themezip' )
.setInputFiles( `tests/e2e/assets/${ fixture }` );
await page
.getByRole( 'button', { name: 'Install Now', exact: true } )
.click();
}

async function deleteTheme( requestUtils ) {
const themes = await requestUtils.rest( { path: '/wp/v2/themes' } );
if ( ! themes.some( ( theme ) => theme.stylesheet === themeSlug ) ) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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', {
Expand Down
Loading