|
| 1 | +import path from 'path'; |
1 | 2 | import { test, expect } from '@wordpress/e2e-test-utils-playwright'; |
2 | 3 | const AxeScanner = require( '../utils/accessibility-axe-scanner' ); |
3 | 4 | const { pages } = require( '../utils/accessibility-pages-matrix' ); |
@@ -110,33 +111,21 @@ test.describe( 'Admin Pages Accessibility', () => { |
110 | 111 |
|
111 | 112 | test.beforeAll( async ( { requestUtils } ) => { |
112 | 113 | // Upload sample image to media library for testing. |
113 | | - const fs = require( 'fs' ); |
114 | | - const path = require( 'path' ); |
115 | | - |
116 | | - const imagePath = path.join( __dirname, '../assets/sample.png' ); |
117 | | - const imageBuffer = fs.readFileSync( imagePath ); |
118 | | - |
119 | | - const response = await requestUtils.rest( { |
120 | | - method: 'POST', |
121 | | - path: 'wp/v2/media', |
122 | | - data: imageBuffer, |
123 | | - headers: { |
124 | | - 'Content-Disposition': 'attachment; filename="sample.png"', |
125 | | - 'Content-Type': 'image/png', |
126 | | - }, |
127 | | - } ); |
| 114 | + const imagePath = path.resolve( __dirname, '../assets/sample.png' ) |
| 115 | + const uploadedMedia = await requestUtils.uploadMedia( |
| 116 | + imagePath |
| 117 | + ); |
128 | 118 |
|
129 | 119 | // Store the ID for cleanup later. |
130 | | - mediaAttachmentId = response.id; |
| 120 | + mediaAttachmentId = uploadedMedia.id; |
131 | 121 | } ); |
132 | 122 |
|
133 | 123 | test.afterAll( async ( { requestUtils } ) => { |
134 | 124 | // Delete the uploaded image to restore initial state |
135 | 125 | if ( mediaAttachmentId ) { |
136 | | - await requestUtils.rest( { |
137 | | - method: 'DELETE', |
138 | | - path: `wp/v2/media/${ mediaAttachmentId }?force=true`, |
139 | | - } ); |
| 126 | + await requestUtils.deleteMedia( |
| 127 | + mediaAttachmentId |
| 128 | + ); |
140 | 129 | } |
141 | 130 | } ); |
142 | 131 |
|
|
0 commit comments